lwpa
0.1.0
LightWeight Platform Abstraction (lwpa)
|
View other versions:
|
POSIX-like identifiers for IP addresses and network interfaces.
#include "lwpa_inet.h"
Data Structures | |
struct | LwpaIpAddr |
An IP address. More... | |
struct | LwpaSockaddr |
An IP address with associated interface and port. More... | |
struct | LwpaNetintInfo |
A description of a network interface. More... | |
Macros | |
#define | IPV6_BYTES 16 |
The number of bytes in an IPv6 address. | |
#define | lwpasock_ip_port_equal(sockptr1, sockptr2) (lwpaip_equal(&(sockptr1)->ip, &(sockptr2)->ip) && ((sockptr1)->port == (sockptr2)->port)) |
Determine whether two instances of LwpaSockaddr contain identical IP addresses and ports. More... | |
#define | NETINTINFO_MAC_LEN 6 |
#define | NETINTINFO_NAME_LEN 64 |
Typedefs | |
typedef struct LwpaIpAddr | LwpaIpAddr |
An IP address. More... | |
typedef struct LwpaSockaddr | LwpaSockaddr |
An IP address with associated interface and port. More... | |
typedef struct LwpaNetintInfo | LwpaNetintInfo |
A description of a network interface. | |
Enumerations | |
enum | lwpa_iptype_t { LWPA_IP_INVALID = 0 , LWPA_IPV4 = 1 , LWPA_IPV6 = 2 } |
Used to identify the type of IP address contained in a LwpaIpAddr. More... | |
lwpa_ip macros | |
A set of macros for interacting with a LwpaIpAddr. It is recommended to use these macros where possible rather than accessing the structure members directly; otherwise, it's easy to forget to fill in a field. | |
#define | lwpaip_is_v4(lwpa_ip_ptr) ((lwpa_ip_ptr)->type == LWPA_IPV4) |
Determine whether a LwpaIpAddr contains an IPv4 address. More... | |
#define | lwpaip_is_v6(lwpa_ip_ptr) ((lwpa_ip_ptr)->type == LWPA_IPV6) |
Determine whether a LwpaIpAddr contains an IPv6 address. More... | |
#define | lwpaip_is_invalid(lwpa_ip_ptr) ((lwpa_ip_ptr)->type == LWPA_IP_INVALID) |
Determine whether a LwpaIpAddr contains an invalid address. More... | |
#define | lwpaip_v4_address(lwpa_ip_ptr) ((lwpa_ip_ptr)->addr.v4) |
Get the IPv4 address from a LwpaIpAddr. More... | |
#define | lwpaip_v6_address(lwpa_ip_ptr) ((lwpa_ip_ptr)->addr.v6) |
Get the IPv6 address from a LwpaIpAddr. More... | |
#define | lwpaip_set_v4_address(lwpa_ip_ptr, val) |
Set the IPv4 address in a LwpaIpAddr. More... | |
#define | lwpaip_set_v6_address(lwpa_ip_ptr, val) |
Set the IPv6 address in a LwpaIpAddr. More... | |
#define | lwpaip_set_invalid(lwpa_ip_ptr) ((lwpa_ip_ptr)->type = LWPA_IP_INVALID) |
Set the type field in a LwpaIpAddr to indicate that it does not contain a valid address. More... | |
#define | lwpaip_is_multicast(lwpa_ip_ptr) |
Determine whether a LwpaIpAddr contains a multicast address. More... | |
#define | lwpaip_equal(ipptr1, ipptr2) |
Determine whether two instances of LwpaIpAddr contain identical addresses. More... | |
#define | lwpaip_cmp(ipptr1, ipptr2) |
A comparison algorithm for lwpa_ip addresses. More... | |
#define | LWPA_INADDR_ANY 0 |
#define | lwpaip_make_any_v4(lwpa_ip_ptr) lwpaip_set_v4_address(lwpa_ip_ptr, LWPA_INADDR_ANY) |
Set a LwpaIpAddr to the IPv4 wildcard address. More... | |
#define | lwpaip_make_any_v6(lwpa_ip_ptr) |
Set a LwpaIpAddr to the IPv6 wildcard address. More... | |
#define lwpaip_cmp | ( | ipptr1, | |
ipptr2 | |||
) |
A comparison algorithm for lwpa_ip addresses.
All IPv4 addresses are considered to be < all IPv6 addresses. For matching types, the numerical address value is compared.
ipptr1 | Pointer to the first LwpaIpAddr to compare. |
ipptr2 | Pointer to the second LwpaIpAddr to compare. |
#define lwpaip_equal | ( | ipptr1, | |
ipptr2 | |||
) |
Determine whether two instances of LwpaIpAddr contain identical addresses.
The type (IPv4 or IPv6) must be the same, as well as the value of the relevant address.
ipptr1 | Pointer to the first LwpaIpAddr to compare. |
ipptr2 | Pointer to the second LwpaIpAddr to compare. |
#define lwpaip_is_invalid | ( | lwpa_ip_ptr | ) | ((lwpa_ip_ptr)->type == LWPA_IP_INVALID) |
Determine whether a LwpaIpAddr contains an invalid address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpaip_is_multicast | ( | lwpa_ip_ptr | ) |
Determine whether a LwpaIpAddr contains a multicast address.
Works for either an IPv4 or an IPv6 address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpaip_is_v4 | ( | lwpa_ip_ptr | ) | ((lwpa_ip_ptr)->type == LWPA_IPV4) |
Determine whether a LwpaIpAddr contains an IPv4 address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpaip_is_v6 | ( | lwpa_ip_ptr | ) | ((lwpa_ip_ptr)->type == LWPA_IPV6) |
Determine whether a LwpaIpAddr contains an IPv6 address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpaip_make_any_v4 | ( | lwpa_ip_ptr | ) | lwpaip_set_v4_address(lwpa_ip_ptr, LWPA_INADDR_ANY) |
Set a LwpaIpAddr to the IPv4 wildcard address.
Use this macro; do not use LWPA_INADDR_ANY directly.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpaip_make_any_v6 | ( | lwpa_ip_ptr | ) |
Set a LwpaIpAddr to the IPv6 wildcard address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpaip_set_invalid | ( | lwpa_ip_ptr | ) | ((lwpa_ip_ptr)->type = LWPA_IP_INVALID) |
Set the type field in a LwpaIpAddr to indicate that it does not contain a valid address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpaip_set_v4_address | ( | lwpa_ip_ptr, | |
val | |||
) |
Set the IPv4 address in a LwpaIpAddr.
Also sets the type field to indicate that this LwpaIpAddr contains an IPv4 address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
val | IPv4 address to set (uint32_t). |
#define lwpaip_set_v6_address | ( | lwpa_ip_ptr, | |
val | |||
) |
Set the IPv6 address in a LwpaIpAddr.
Also sets the type field to indicate that this LwpaIpAddr contains an IPv6 address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
val | IPv6 address to set (uint8_t[]). Must be at least of length IPV6_BYTES. Gets copied into the struct. |
#define lwpaip_v4_address | ( | lwpa_ip_ptr | ) | ((lwpa_ip_ptr)->addr.v4) |
Get the IPv4 address from a LwpaIpAddr.
It is recommended to first use lwpaip_is_v4() to make sure this LwpaIpAddr contains a valid IPv4 address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpaip_v6_address | ( | lwpa_ip_ptr | ) | ((lwpa_ip_ptr)->addr.v6) |
Get the IPv6 address from a LwpaIpAddr.
It is recommended to first use lwpaip_is_v6() to make sure this LwpaIpAddr contains a valid IPv6 address.
lwpa_ip_ptr | Pointer to a LwpaIpAddr. |
#define lwpasock_ip_port_equal | ( | sockptr1, | |
sockptr2 | |||
) | (lwpaip_equal(&(sockptr1)->ip, &(sockptr2)->ip) && ((sockptr1)->port == (sockptr2)->port)) |
Determine whether two instances of LwpaSockaddr contain identical IP addresses and ports.
sockptr1 | Pointer to first LwpaSockaddr to compare. |
sockptr2 | Pointer to second LwpaSockaddr to compare. |
typedef struct LwpaIpAddr LwpaIpAddr |
An IP address.
Can hold either an IPv4 or IPv6 address. IPv4 addresses are in host byte order.
typedef struct LwpaSockaddr LwpaSockaddr |
An IP address with associated interface and port.
Ports are in host byte order.
enum lwpa_iptype_t |
Used to identify the type of IP address contained in a LwpaIpAddr.
Enumerator | |
---|---|
LWPA_IP_INVALID | This lwpa_ip is not valid. |
LWPA_IPV4 | This lwpa_ip contains an IPv4 address. |
LWPA_IPV6 | This lwpa_ip contains an IPv6 address. |