wm: dnsparser

ref: ba2943ae190fdc67a3f9ce5e1668eda51e3f64b1
dir: /common.c/

View raw version
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdint.h>

void
err(int fatal, char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	
	fprintf(stderr, fatal ? "FATAL: " : "WARN: ");
	vfprintf(stderr, fmt, args);
	fprintf(stderr, "\n");
	
	va_end(args);

	if(fatal)
	{
		fflush(stdout);
		fclose(stdout);
		abort();
	}
}

uint16_t
get2(const u_char *octet)
{
	return octet[0] << 8 | octet[1];
}

uint32_t
get4(const u_char *octet)
{
	return get2(octet) << 8 * 2 | get2(octet + 2);
}