36 #define UNUSED __attribute__ ((unused))
43#define DUPPRINT(fp, fmt, ...) \
45 printf(fmt, __VA_ARGS__); \
47 fprintf(fp, fmt, __VA_ARGS__); \
51#define DUPPRINT(fp, fmt...) \
62 printf("%s:%d "#STR": %s \n", __FUNCTION__, __LINE__, strerror(errno)); \
65#define log_debug_scr(STR) \
67 printf("%s:%d %s \n", __FUNCTION__, __LINE__, STR); \
70#define log_debug(STR) \
72 printf("%s:%d "#STR" \n", __FUNCTION__, __LINE__); \
75#define CHECK_RET_EXIT(func) \
79 exit (EXIT_FAILURE); \
83#define CHECK_NULL_EXIT(func) \
87 exit (EXIT_FAILURE); \
92#define CHECK_RET(func) \
99#define CHECK_RET_GOTO_ERROR(func) \
109#define OSDEP(x) (void)(x)
112#define S6_ADDR32(sa6) (sa6)->s6_addr32
114#define S6_ADDR32(sa6) ((uint32_t *)((sa6)->s6_addr))
117#define IPV6_ADDR_COPY(dest, src) \
119 (S6_ADDR32(dest))[0]=(S6_ADDR32(src))[0]; \
120 (S6_ADDR32(dest))[1]=(S6_ADDR32(src))[1]; \
121 (S6_ADDR32(dest))[2]=(S6_ADDR32(src))[2]; \
122 (S6_ADDR32(dest))[3]=(S6_ADDR32(src))[3]; \
131 if (s->
epoch == ~0u) {
139 "Epoch - client delta = %u, server delta = %u",
142 return (c_delta + 2 < s_delta - (s_delta >> 4))
143 || (s_delta + 2 < c_delta - (c_delta >> 4));
146inline static void timeval_align(
struct timeval *x)
148 x->tv_sec+=
x->tv_usec / 1000000;
149 x->tv_usec=
x->tv_usec % 1000000;
151 x->tv_usec=1000000 +
x->tv_usec;
156inline static int timeval_comp(
struct timeval *x,
struct timeval *y)
160 if (
x->tv_sec <
y->tv_sec) {
162 }
else if (
x->tv_sec >
y->tv_sec) {
164 }
else if (
x->tv_usec <
y->tv_usec) {
166 }
else if (
x->tv_usec >
y->tv_usec) {
173inline static int timeval_subtract(
struct timeval *result,
struct timeval *x,
176 int ret=timeval_comp(x, y);
185 if (
x->tv_usec <
y->tv_usec) {
186 int nsec=(
y->tv_usec -
x->tv_usec) / 1000000 + 1;
187 y->tv_usec-=1000000 * nsec;
193 result->tv_sec=
x->tv_sec -
y->tv_sec;
194 result->tv_usec=
x->tv_usec -
y->tv_usec;
195 timeval_align(result);
203static inline void createNonce(
struct pcp_nonce *nonce_field)
206 for (i = 2; i >= 0; --i)
208 nonce_field->
n[i]=htonl (rand());
210 nonce_field->
n[i]=htonl(random());
215static inline char *pcp_strndup(
const char *s,
size_t size) {
217 char const* end=(
char const*)memchr(s, 0, size);
225 ret=(
char*)malloc(size);
228 memcpy(ret, s, size);
233#define strndup pcp_strndup
uint32_t size(sys::state const &state)
#define PCP_LOG(level, fmt,...)