34 #include <arpa/inet.h>
41 #ifdef HAVE_SYS_TIME_H
52 uint16_t tmp = htons(u16);
53 memcpy(bytes, &tmp, 2);
59 uint32_t tmp = htonl(u32);
60 memcpy(bytes, &tmp, 4);
66 uint64_t tmp =
htonll(u64);
67 memcpy(bytes, &tmp, 8);
74 gettimeofday(tv, &tz);
81 if((ptr = malloc(size)) != NULL)
89 const struct timeval *a,
const struct timeval *b)
91 struct timeval y = *b;
94 if (a->tv_usec < b->tv_usec) {
95 int nsec = (b->tv_usec - a->tv_usec) / 1000000 + 1;
96 y.tv_usec -= 1000000 * nsec;
99 if (a->tv_usec - b->tv_usec > 1000000) {
100 int nsec = (a->tv_usec - b->tv_usec) / 1000000;
101 y.tv_usec += 1000000 * nsec;
107 result->tv_sec = a->tv_sec - y.tv_sec;
108 result->tv_usec = a->tv_usec - y.tv_usec;
111 return a->tv_sec < y.tv_sec;
117 if((newln = strchr(line,
'\n')) != NULL)
void bytes_htonl(uint8_t *bytes, uint32_t u32)
Convert a host ordered long to a network ordered byte array.
Header file for common utility functions.
void * malloc_zero(const size_t size)
Allocate memory and set it to zero.
#define htonll(x)
Byte-swap a 64-bit integer.
void bytes_htons(uint8_t *bytes, uint16_t u16)
Convert a host ordered short to a network ordered byte array.
void chomp(char *line)
Remove a newline from the given string.
void bytes_htonll(uint8_t *bytes, uint64_t u64)
Convert a host ordered long-long (64 bit) to a network ordered byte array.
void gettimeofday_wrap(struct timeval *tv)
Convenience function to get the current time of day.
int timeval_subtract(struct timeval *result, const struct timeval *x, const struct timeval *y)
Find the delta between two timevals.