Skip to Content
[CAIDA - Cooperative Association for Internet Data Analysis logo]
The Cooperative Association for 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.
#define STR(a)   XSTR(a)
 Stringify a macro value.
#define ntohll(x)
 Byte-swap a 64-bit integer.
#define htonll(x)   ntohll(x)
 Byte-swap a 64-bit integer.

Functions

void bytes_htons (uint8_t *bytes, uint16_t u16)
 Convert a host ordered short to a network ordered byte array.
void bytes_htonl (uint8_t *bytes, uint32_t u32)
 Convert a host ordered long to a network ordered byte array.
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.
void * malloc_zero (const size_t size)
 Allocate memory and set it to zero.
int timeval_subtract (struct timeval *result, const struct timeval *x, const struct timeval *y)
 Find the delta between two timevals.

Detailed Description

Header file for common utility functions.

Author:
Alistair King

Definition in file utils.h.


Macro Definition Documentation

#define htonll (   x)    ntohll(x)

Byte-swap a 64-bit integer.

Definition at line 55 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 51 of file utils.h.

#define STR (   a)    XSTR(a)

Stringify a macro value.

Definition at line 46 of file utils.h.

Referenced by corsaro_get_monitorname().

#define XSTR (   a)    #a

Internal to the STR macro.

Definition at line 43 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.

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.

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.

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.

void* malloc_zero ( const size_t  size)

Allocate memory and set it to zero.

Parameters:
sizeThe size of memory to allocate
Returns:
a pointer to zeroed memory if successful, -1 if an error occurs

Definition at line 78 of file utils.c.

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.