27 #include "lwpa_bool.h"
77 #define lwpaip_is_v4(lwpa_ip_ptr) ((lwpa_ip_ptr)->type == LWPA_IPV4)
82 #define lwpaip_is_v6(lwpa_ip_ptr) ((lwpa_ip_ptr)->type == LWPA_IPV6)
86 #define lwpaip_is_invalid(lwpa_ip_ptr) ((lwpa_ip_ptr)->type == LWPA_IP_INVALID)
92 #define lwpaip_v4_address(lwpa_ip_ptr) ((lwpa_ip_ptr)->addr.v4)
98 #define lwpaip_v6_address(lwpa_ip_ptr) ((lwpa_ip_ptr)->addr.v6)
103 #define lwpaip_set_v4_address(lwpa_ip_ptr, val) \
106 (lwpa_ip_ptr)->type = LWPA_IPV4; \
107 (lwpa_ip_ptr)->addr.v4 = val; \
114 #define lwpaip_set_v6_address(lwpa_ip_ptr, val) \
117 (lwpa_ip_ptr)->type = LWPA_IPV6; \
118 memcpy((lwpa_ip_ptr)->addr.v6, val, IPV6_BYTES); \
123 #define lwpaip_set_invalid(lwpa_ip_ptr) ((lwpa_ip_ptr)->type = LWPA_IP_INVALID)
129 #define lwpaip_is_multicast(lwpa_ip_ptr) \
130 (((lwpa_ip_ptr)->type == LWPA_IPV4) \
131 ? (((lwpa_ip_ptr)->addr.v4 > 0xe0000000) && ((lwpa_ip_ptr)->addr.v4 < 0xefffffff)) \
132 : ((lwpa_ip_ptr)->addr.v6[0] == 0xff))
139 #define lwpaip_equal(ipptr1, ipptr2) \
140 (((ipptr1)->type == (ipptr2)->type) \
141 ? (((ipptr1)->type == LWPA_IPV4) ? ((ipptr1)->addr.v4 == (ipptr2)->addr.v4) \
142 : (0 == memcmp((ipptr1)->addr.v6, (ipptr2)->addr.v6, IPV6_BYTES))) \
151 #define lwpaip_cmp(ipptr1, ipptr2) \
152 (((ipptr1)->type != (ipptr2)->type) \
153 ? ((ipptr1)->type - (ipptr2)->type) \
154 : (((ipptr1)->type == LWPA_IPV4) ? ((int)(ipptr1)->addr.v4 - (int)(ipptr2)->addr.v4) \
155 : memcmp((ipptr1)->addr.v6, (ipptr2)->addr.v6, IPV6_BYTES)))
157 #define LWPA_INADDR_ANY 0
162 #define lwpaip_make_any_v4(lwpa_ip_ptr) lwpaip_set_v4_address(lwpa_ip_ptr, LWPA_INADDR_ANY)
165 #define lwpaip_make_any_v6(lwpa_ip_ptr) \
168 (lwpa_ip_ptr)->type = LWPA_IPV6; \
169 memset(lwpa_ip_v6_address(lwpa_ip_ptr), 0, IPV6_BYTES); \
188 #define lwpasock_ip_port_equal(sockptr1, sockptr2) \
189 (lwpaip_equal(&(sockptr1)->ip, &(sockptr2)->ip) && ((sockptr1)->port == (sockptr2)->port))
191 #define NETINTINFO_MAC_LEN 6
192 #define NETINTINFO_NAME_LEN 64
207 uint8_t
mac[NETINTINFO_MAC_LEN];
209 char name[NETINTINFO_NAME_LEN];
struct LwpaNetintInfo LwpaNetintInfo
A description of a network interface.
lwpa_iptype_t
Used to identify the type of IP address contained in a LwpaIpAddr.
Definition: lwpa_inet.h:40
struct LwpaIpAddr LwpaIpAddr
An IP address.
struct LwpaSockaddr LwpaSockaddr
An IP address with associated interface and port.
#define IPV6_BYTES
The number of bytes in an IPv6 address.
Definition: lwpa_inet.h:50
@ LWPA_IPV6
This lwpa_ip contains an IPv6 address.
Definition: lwpa_inet.h:46
@ LWPA_IP_INVALID
This lwpa_ip is not valid.
Definition: lwpa_inet.h:42
@ LWPA_IPV4
This lwpa_ip contains an IPv4 address.
Definition: lwpa_inet.h:44
An IP address.
Definition: lwpa_inet.h:55
lwpa_iptype_t type
The IP address type (IPv4 or IPv6)
Definition: lwpa_inet.h:57
A description of a network interface.
Definition: lwpa_inet.h:196
int ifindex
The OS-specific network interface number.
Definition: lwpa_inet.h:199
LwpaIpAddr addr
The interface ip address.
Definition: lwpa_inet.h:201
bool is_default
Whether this is the default network interface.
Definition: lwpa_inet.h:211
char name[NETINTINFO_NAME_LEN]
The adapter name as a string.
Definition: lwpa_inet.h:209
LwpaIpAddr gate
The address of the default gateway for this interface.
Definition: lwpa_inet.h:205
LwpaIpAddr mask
The subnet mask for this interface.
Definition: lwpa_inet.h:203
uint8_t mac[NETINTINFO_MAC_LEN]
The adapter MAC address.
Definition: lwpa_inet.h:207
An IP address with associated interface and port.
Definition: lwpa_inet.h:176
uint32_t scope_id
IPv6 scope ID.
Definition: lwpa_inet.h:179
uint16_t port
TCP or UDP port.
Definition: lwpa_inet.h:177
LwpaIpAddr ip
IP address.
Definition: lwpa_inet.h:178
The address, use either v4 or v6 depending on the value of type.
Definition: lwpa_inet.h:60