-
Notifications
You must be signed in to change notification settings - Fork 35
/
utils.h
46 lines (33 loc) · 1.04 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef UTILS_H
#define UTILS_H
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
// sigh.. why is this not defined in some standard place
#ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
#endif
#ifndef MAX
#define MAX(x,y) ((x)>(y)?(x):(y))
#endif
#ifndef BUFLEN
#define BUFLEN 4096
#endif
#define malloc_and_check(x) _realloc_and_check(NULL,(x),__FILE__,__LINE__);
#define realloc_and_check(ptr,x) _realloc_and_check((ptr),(x),__FILE__,__LINE__);
void * _realloc_and_check(void * ptr,size_t bytes, char * file, int lineno);
void perror_and_exit(char * str, int exit_code);
void add_time(struct timeval *now, time_t secs, suseconds_t usecs);
void set_timeval(struct timeval *target, struct timeval *val);
extern inline int time_diff(struct timeval *now, struct timeval *then);
void* xmalloc(size_t len);
void fail(const char *msg);
/**
* Endiannes change for 64 bit numbers.
*/
uint64_t ntohll(uint64_t val);
uint16_t ip_sum_calc(uint16_t len_ip_header, uint16_t buff[]);
#endif