Airframe Application Utilities
libairframe 2.12.0 API documentation

Macros | Typedefs | Enumerations | Functions
airutil.h File Reference

Airframe utility functions. More...

#include <airframe/autoinc.h>

Go to the source code of this file.

Macros

#define AIR_TIME_BUF_MINSZ   20
 Minimum buffer size for air_time_buf_print()
 
#define AIR_IPADDR_BUF_MINSZ   16
 Minimum buffer size for air_ipaddr_buf_print()
 
#define AIR_IP6ADDR_BUF_MINSZ   40
 Minimum buffer size for air_ip6addr_buf_print()
 

Typedefs

typedef enum air_timefmt_en AirTimeFormat
 Time format description for air_time_* functions.
 

Enumerations

enum  air_timefmt_en { AIR_TIME_ISO8601, AIR_TIME_ISO8601_NS, AIR_TIME_SQUISHED, AIR_TIME_ISO8601_HMS }
 Time format description for air_time_* functions. More...
 

Functions

void air_time_g_string_append (GString *str, time_t time, AirTimeFormat fmtid)
 Append a string format of a time to a given GString in a given format. More...
 
void air_mstime_g_string_append (GString *str, uint64_t mstime, AirTimeFormat fmtid)
 Append a string format of a time in epoch milliseconds to a given GString in a given format. More...
 
void air_time_buf_print (char *buf, time_t time, AirTimeFormat fmtid)
 Write a string format of a time to a given buffer in a given format. More...
 
time_t air_time_gm (uint32_t year, uint32_t mon, uint32_t day, uint32_t hour, uint32_t min, uint32_t sec)
 Portable, less unix-ish timegm() implementation. More...
 
void air_ipaddr_buf_print (char *buf, uint32_t ipaddr)
 Write the dotted quad format of an IPv4 address to a given buffer. More...
 
void air_ip6addr_buf_print (char *buf, uint8_t *ipaddr)
 Write the presentation format of an IPv6 address to a given buffer. More...
 
uint32_t air_mask_from_prefix (uint32_t pfx)
 Given a CIDR prefix length, return a mask for extracting the network part of the address. More...
 
void air_hexdump_g_string_append (GString *str, char *lpfx, uint8_t *buf, uint32_t len)
 Append a given binary buffer as a hex + ASCII dump with 16 bytes per line to the given GString. More...
 
gboolean air_sock_maxrcvbuf (int sock, int *size)
 Maximize socket receive buffer size. More...
 
gboolean air_sock_maxsndbuf (int sock, int *size)
 Maximize socket send buffer size. More...
 
void air_ignore_sigpipe (void)
 Ignore SIGPIPE, so that failed pipe writes or TCP writes on reset sockets will return EPIPE instead of terminating the application.
 

Detailed Description

Airframe utility functions.

A home for utility functions that have no other.

Enumeration Type Documentation

◆ air_timefmt_en

Time format description for air_time_* functions.

Enumerator
AIR_TIME_ISO8601 

ISO8601 format with space between date and time.

AIR_TIME_ISO8601_NS 

ISO8601 format with T between date and time.

AIR_TIME_SQUISHED 

Time format squished into single string for ASCII sort by time.

AIR_TIME_ISO8601_HMS 

ISO8601 format with time only.

Function Documentation

◆ air_hexdump_g_string_append()

void air_hexdump_g_string_append ( GString *  str,
char *  lpfx,
uint8_t *  buf,
uint32_t  len 
)

Append a given binary buffer as a hex + ASCII dump with 16 bytes per line to the given GString.

Parameters
strstring to append to
lpfxstring to prefix each line of output with. Use for indentation and labeling.
bufBuffer to dump to GString
lenLength of buf

◆ air_ip6addr_buf_print()

void air_ip6addr_buf_print ( char *  buf,
uint8_t *  ipaddr 
)

Write the presentation format of an IPv6 address to a given buffer.

The buffer must be at least AIR_IP6ADDR_BUF_MINSZ (40) bytes long.

Parameters
bufbuffer to write to
ipaddraddress to print

◆ air_ipaddr_buf_print()

void air_ipaddr_buf_print ( char *  buf,
uint32_t  ipaddr 
)

Write the dotted quad format of an IPv4 address to a given buffer.

The buffer must be at least AIR_IPADDR_BUF_MINSZ (16) bytes long.

Parameters
bufbuffer to write to
ipaddraddress to print

◆ air_mask_from_prefix()

uint32_t air_mask_from_prefix ( uint32_t  pfx)

Given a CIDR prefix length, return a mask for extracting the network part of the address.

Parameters
pfxprefix length (0-32)
Returns
network-part mask bits

◆ air_mstime_g_string_append()

void air_mstime_g_string_append ( GString *  str,
uint64_t  mstime,
AirTimeFormat  fmtid 
)

Append a string format of a time in epoch milliseconds to a given GString in a given format.

Parameters
strstring to append to
mstimetime to append in epoch milliseconds
fmtidtime format description

◆ air_sock_maxrcvbuf()

gboolean air_sock_maxrcvbuf ( int  sock,
int *  size 
)

Maximize socket receive buffer size.

Sets the socket's receive buffer to the highest available size less than or equal to the given size.

Parameters
socksocket to increase buffer size of
sizepointer to maximum size to set. Returns actually set size.
Returns
TRUE on success, FALSE otherwise.

◆ air_sock_maxsndbuf()

gboolean air_sock_maxsndbuf ( int  sock,
int *  size 
)

Maximize socket send buffer size.

Sets the socket's receive buffer to the highest available size less than or equal to the given size.

Parameters
socksocket to increase buffer size of
sizepointer to maximum size to set. Returns actually set size.
Returns
TRUE on success, FALSE otherwise.

◆ air_time_buf_print()

void air_time_buf_print ( char *  buf,
time_t  time,
AirTimeFormat  fmtid 
)

Write a string format of a time to a given buffer in a given format.

Parameters
bufbuffer to write to
timetime to print in epoch seconds
fmtidtime format description

◆ air_time_g_string_append()

void air_time_g_string_append ( GString *  str,
time_t  time,
AirTimeFormat  fmtid 
)

Append a string format of a time to a given GString in a given format.

Parameters
strstring to append to
timetime to append in epoch seconds
fmtidtime format description

◆ air_time_gm()

time_t air_time_gm ( uint32_t  year,
uint32_t  mon,
uint32_t  day,
uint32_t  hour,
uint32_t  min,
uint32_t  sec 
)

Portable, less unix-ish timegm() implementation.

Converts a UTC year, month, day, hour, minute, and second into a time in epoch seconds. Handles leap years but not leap seconds. mon is 1-based (as in English representations), and year is CE, not 1900-based.

Parameters
yearyear of date to convert (year CE)
monmonth of date to convert (1-12)
dayday of date to convert (1-31)
hourhour of date to convert (0-23)
minminute of date to convert (0-59)
secsecond of date to convert (0-59)
Returns
epoch seconds