Blame common.cpp

873e9f
c47604
#include <cstdio></cstdio>
16cbea
#include <ctime></ctime>
16cbea
16cbea
#include <chrono></chrono>
c47604
873e9f
#include "common.h"
873e9f
873e9f
873e9f
873e9f
void Address::print() const
ab5ba6
	{ logf("%hhu.%hhu.%hhu.%hhu:%hu", ip[0], ip[1], ip[2], ip[3], port); }
873e9f
937c1c
16cbea
Time monotonicTime() {
16cbea
	return std::chrono::duration_cast<std::chrono::microseconds>(</std::chrono::microseconds>
16cbea
		std::chrono::steady_clock::now().time_since_epoch() ).count();
16cbea
}
16cbea
16cbea
16cbea
Time globalTime()
16cbea
	{ return time(NULL)*1000000ull; }
460064
460064
460064
const char* bitsToString(const void *data, int size) {
460064
	static char buffer[8*PACKET_SIZE + 1] = {};
460064
	if (size > PACKET_SIZE) size = PACKET_SIZE;
460064
	char *c = buffer;
460064
	for(const unsigned char *p = (const unsigned char*)data, *e = p + size; p < e; ++p)
460064
		for(int i = 0; i < 8; ++i, ++c)
460064
			*c = (*p & (1 << i)) ? '#': '.';
460064
	*c = 0;
460064
	return buffer;
460064
}
460064