diff options
Diffstat (limited to 'midimcast.c')
-rw-r--r-- | midimcast.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/midimcast.c b/midimcast.c new file mode 100644 index 0000000..6ad047f --- /dev/null +++ b/midimcast.c @@ -0,0 +1,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; +} |