Blob Blame Raw

#include <cstdio>
#include <ctime>

#include <chrono>

#include "common.h"



void Address::print() const
	{ logf("%hhu.%hhu.%hhu.%hhu:%hu", ip[0], ip[1], ip[2], ip[3], port); }


Time monotonicTime() {
	return std::chrono::duration_cast<std::chrono::microseconds>(
		std::chrono::steady_clock::now().time_since_epoch() ).count();
}


Time globalTime()
	{ return time(NULL)*1000000ull; }


const char* bitsToString(const void *data, int size) {
	static char buffer[8*PACKET_SIZE + 1] = {};
	if (size > PACKET_SIZE) size = PACKET_SIZE;
	char *c = buffer;
	for(const unsigned char *p = (const unsigned char*)data, *e = p + size; p < e; ++p)
		for(int i = 0; i < 8; ++i, ++c)
			*c = (*p & (1 << i)) ? '#': '.';
	*c = 0;
	return buffer;
}