IPv4 addresses

IPv4 address types and helper function. More...

Detailed Description

IPv4 address types and helper function.

Files

file  addr.h
 IPv6 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.
 

Functions

static bool ipv4_addr_equal (ipv4_addr_t *a, ipv4_addr_t *b)
 Checks if two IPv4 addresses are equal. More...
 
char * ipv4_addr_to_str (char *result, const ipv4_addr_t *addr, uint8_t result_len)
 Converts an IPv4 address to its string representation. More...
 
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. More...
 
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. More...
 

Function Documentation

◆ ipv4_addr_equal()

static bool ipv4_addr_equal ( ipv4_addr_t a,
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 55 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_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