Loading...
Searching...
No Matches
IPv4 addresses

IPv4 address types and helper function. More...

Detailed Description

IPv4 address types and helper function.

Files

file  addr.h
 IPv4 address type and helper functions definitions.
 

Data Structures

union  ipv4_addr_t
 Data type to represent an IPv4 address. More...
 

Macros

#define IPV4_ADDR_MAX_STR_LEN   (sizeof("255.255.255.255"))
 Maximum length of an IPv4 address as string.
 
#define IPV4_ADDR_INIT(a, b, c, d)   { .u8 = {a, b, c, d} }
 Static initializer for an IPv4 address.
 

Functions

static bool ipv4_addr_equal (const ipv4_addr_t *a, const ipv4_addr_t *b)
 Checks if two IPv4 addresses are equal.
 
static bool ipv4_addr_is_multicast (const ipv4_addr_t *addr)
 Check if addr is a multicast address.
 
char * ipv4_addr_to_str (char *result, const ipv4_addr_t *addr, uint8_t result_len)
 Converts an IPv4 address to its string representation.
 
ipv4_addr_tipv4_addr_from_str (ipv4_addr_t *result, const char *addr)
 Converts an IPv4 address string representation to a byte-represented IPv4 address.
 
ipv4_addr_tipv4_addr_from_buf (ipv4_addr_t *result, const char *addr, size_t addr_len)
 Converts an IPv4 address from a buffer of characters to a byte-represented IPv4 address.
 
void ipv4_addr_print (const ipv4_addr_t *addr)
 Print IPv4 address to stdout.
 

Macro Definition Documentation

◆ IPV4_ADDR_INIT

#define IPV4_ADDR_INIT (   a,
  b,
  c,
 
)    { .u8 = {a, b, c, d} }

Static initializer for an IPv4 address.

Parameters
[in]a1st octet
[in]b2nd octet
[in]c3rd octet
[in]d4th octet
Returns
initialized IPv4 address

Definition at line 48 of file addr.h.

◆ IPV4_ADDR_MAX_STR_LEN

#define IPV4_ADDR_MAX_STR_LEN   (sizeof("255.255.255.255"))

Maximum length of an IPv4 address as string.

Definition at line 36 of file addr.h.

Function Documentation

◆ ipv4_addr_equal()

static bool ipv4_addr_equal ( const ipv4_addr_t a,
const ipv4_addr_t b 
)
inlinestatic

Checks if two IPv4 addresses are equal.

Parameters
[in]aAn IPv4 address.
[in]bAnother IPv4 address.
Returns
true, if a and b are equal
false, otherwise.

Definition at line 67 of file addr.h.

◆ ipv4_addr_from_buf()

ipv4_addr_t * ipv4_addr_from_buf ( ipv4_addr_t result,
const char *  addr,
size_t  addr_len 
)

Converts an IPv4 address from a buffer of characters to a byte-represented IPv4 address.

Note
addr_len should be between 0 and IPV4_ADDR_MAX_STR_LEN
Parameters
[out]resultThe resulting byte representation
[in]addrAn IPv4 address string representation
[in]addr_lenThe amount of characters to parse
Returns
result, on success
NULL, if addr was malformed
NULL, if result or addr was NULL

◆ ipv4_addr_from_str()

ipv4_addr_t * ipv4_addr_from_str ( ipv4_addr_t result,
const char *  addr 
)

Converts an IPv4 address string representation to a byte-represented IPv4 address.

Parameters
[out]resultThe resulting byte representation
[in]addrAn IPv4 address string representation
Returns
result, on success
NULL, if addr was malformed
NULL, if result or addr was NULL

◆ ipv4_addr_is_multicast()

static bool ipv4_addr_is_multicast ( const ipv4_addr_t addr)
inlinestatic

Check if addr is a multicast address.

See also
RFC 1112, section 4
Parameters
[in]addrAn IPv4 address.
Returns
true, if addr is multicast address,
false, otherwise.

Definition at line 84 of file addr.h.

◆ ipv4_addr_print()

void ipv4_addr_print ( const ipv4_addr_t addr)

Print IPv4 address to stdout.

Parameters
[in]addrPointer to ipv4_addr_t to print

◆ ipv4_addr_to_str()

char * ipv4_addr_to_str ( char *  result,
const ipv4_addr_t addr,
uint8_t  result_len 
)

Converts an IPv4 address to its string representation.

Parameters
[out]resultThe resulting string representation of at least IPV4_ADDR_MAX_STR_LEN.
[in]addrAn IPv4 address
[in]result_lenLength of result
Returns
result, on success
NULL, if result_len was lesser than IPV4_ADDR_MAX_STR_LEN
NULL, if result or addr was NULL