aboutsummaryrefslogtreecommitdiff
path: root/midimcast.c
blob: 6ad047f99d849f61b7119e05d56409f8cd666995 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>

#include "midimcast.h"

void env_read_common(const char **const mcast_group, uint16_t *const mcast_port)
{
	midimcast_debug = getenv("DEBUG") != NULL;

	*mcast_group = getenv("MCAST_GROUP");
	if (!*mcast_group)
		*mcast_group = "224.212.21.175";
	debug("Using multicast group %s", *mcast_group);

	const char *const mcast_port_str = getenv("MCAST_PORT");
	if (mcast_port_str) {
		const long mcast_port_untrunc = strtol(mcast_port_str, NULL, 0);
		if (mcast_port_untrunc < 0 || mcast_port_untrunc > UINT16_MAX)
			err("Port %ld does not exist", mcast_port_untrunc);
		*mcast_port = mcast_port_untrunc;
	} else {
		*mcast_port = 8000;
	}
	debug("Using multicast port %" PRIu16, *mcast_port);
}

uint64_t now() {
	struct timespec ts;
	err_std(clock_gettime, CLOCK_REALTIME, &ts);
	return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}