Skip to Content
[CAIDA - Center for Applied Internet Data Analysis logo]
The Center for Applied Internet Data Analysis
utils.h File Reference

Header file for common utility functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define XSTR(a)   #a
 Internal to the STR macro. More...
 
#define STR(a)   XSTR(a)
 Stringify a macro value. More...
 
#define ARR_CNT(a)   (sizeof(a) / sizeof(a[0]))
 Count the number of elements in an arbitrary array. More...
 
#define ntohll(x)
 Byte-swap a 64-bit integer. More...
 
#define htonll(x)   ntohll(x)
 Byte-swap a 64-bit integer. More...
 

Functions

void bytes_htons (uint8_t *bytes, uint16_t u16)
 Convert a host ordered short to a network ordered byte array. More...
 
void bytes_htonl (uint8_t *bytes, uint32_t u32)
 Convert a host ordered long to a network ordered byte array. More...
 
void bytes_htonll (uint8_t *bytes, uint64_t u64)
 Convert a host ordered long-long (64 bit) to a network ordered byte array. More...
 
void gettimeofday_wrap (struct timeval *tv)
 Convenience function to get the current time of day. More...
 
void * malloc_zero (const size_t size)
 Allocate memory and set it to zero. More...
 
int timeval_subtract (struct timeval *result, const struct timeval *x, const struct timeval *y)
 Find the delta between two timevals. More...
 
void chomp (char *line)
 Remove a newline from the given string. More...
 

Detailed Description

Header file for common utility functions.

Author
Alistair King

Definition in file utils.h.

Macro Definition Documentation

#define ARR_CNT (   a)    (sizeof(a) / sizeof(a[0]))

Count the number of elements in an arbitrary array.

Definition at line 60 of file utils.h.

Referenced by corsaro_geo_get_provider_name(), and corsaro_geo_get_provider_names().

#define htonll (   x)    ntohll(x)

Byte-swap a 64-bit integer.

Definition at line 72 of file utils.h.

Referenced by bytes_htonll().

#define ntohll (   x)
Value:
(((uint64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
(uint32_t)ntohl(((int)(x >> 32))))

Byte-swap a 64-bit integer.

Definition at line 66 of file utils.h.

Referenced by validate_attack_vector().

#define STR (   a)    XSTR(a)

Stringify a macro value.

Definition at line 57 of file utils.h.

Referenced by corsaro_init(), and usage().

#define XSTR (   a)    #a

Internal to the STR macro.

Definition at line 54 of file utils.h.

Function Documentation

void bytes_htonl ( uint8_t *  bytes,
uint32_t  u32 
)

Convert a host ordered long to a network ordered byte array.

Parameters
[out]bytesThe converted byte array
u32The host-ordered long

Definition at line 57 of file utils.c.

Referenced by binary_dump(), and corsaro_dos_end_interval().

void bytes_htonll ( uint8_t *  bytes,
uint64_t  u64 
)

Convert a host ordered long-long (64 bit) to a network ordered byte array.

Parameters
[out]bytesThe converted byte array
u64The host-ordered long-long (64 bit)

Definition at line 64 of file utils.c.

References htonll.

Referenced by binary_dump().

void bytes_htons ( uint8_t *  bytes,
uint16_t  u16 
)

Convert a host ordered short to a network ordered byte array.

Parameters
[out]bytesThe converted byte array
u16The host-ordered short

Definition at line 50 of file utils.c.

Referenced by binary_dump().

void chomp ( char *  line)

Remove a newline from the given string.

Parameters
lineA pointer to the string to be chomped
Note
This function replaces the first occurance of '
' with '\0'. Therefore it is only useful for strings where the newline is at the end. e.g. those returned by fgets (or similar)

Definition at line 114 of file utils.c.

Referenced by read_country_file(), read_pfx_file(), and read_routeviews().

void gettimeofday_wrap ( struct timeval *  tv)

Convenience function to get the current time of day.

Parameters
[out]tvA pointer to a timeval containing the time of day

Definition at line 71 of file utils.c.

Referenced by corsaro_init().

int timeval_subtract ( struct timeval *  result,
const struct timeval *  x,
const struct timeval *  y 
)

Find the delta between two timevals.

Parameters
[out]resultA pointer to a timeval containing the delta
xThe start timeval
yThe end timeval
Returns
1 if the result is negative, 0 otherwise

Definition at line 88 of file utils.c.

Referenced by attack_vector_is_attack().