Skip to Content
[CAIDA - Cooperative Association for Internet Data Analysis logo]
The Cooperative Association for Internet Data Analysis
utils.h
Go to the documentation of this file.
1 /*
2  * corsaro
3  *
4  * Alistair King, CAIDA, UC San Diego
5  * corsaro-info@caida.org
6  *
7  * ntholl and htonll macros from
8  * http://www.codeproject.com/KB/cpp/endianness.aspx
9  *
10  * Other functions from scamper as noted in utils.c
11  *
12  * Copyright (C) 2012 The Regents of the University of California.
13  *
14  * This file is part of corsaro.
15  *
16  * corsaro is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * corsaro is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with corsaro. If not, see <http://www.gnu.org/licenses/>.
28  *
29  */
30 
31 #ifndef __UTILS_H
32 #define __UTILS_H
33 
43 #define XSTR(a) #a
44 
46 #define STR(a) XSTR(a)
47 
48 /* ntholl and htonll macros from
49  http://www.codeproject.com/KB/cpp/endianness.aspx */
51 #define ntohll(x) (((uint64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
52  (uint32_t)ntohl(((int)(x >> 32))))
53 
55 #define htonll(x) ntohll(x)
56 
62 void bytes_htons(uint8_t *bytes, uint16_t u16);
63 
69 void bytes_htonl(uint8_t *bytes, uint32_t u32);
70 
76 void bytes_htonll(uint8_t *bytes, uint64_t u64);
77 
82 void gettimeofday_wrap(struct timeval *tv);
83 
89 void *malloc_zero(const size_t size);
90 
98 int timeval_subtract (struct timeval *result,
99  const struct timeval *x, const struct timeval *y);
100 
101 #endif /* __UTILS_H */