| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
inet_addr.h
Go to the documentation of this file.
1
10#ifndef __WS_INET_ADDR_H__
11#define __WS_INET_ADDR_H__
12
13#include <wireshark.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif /* __cplusplus */
18
22 typedef uint32_t ws_in4_addr;
23
27 typedef struct e_in6_addr {
28 uint8_t bytes[16];
29} ws_in6_addr;
30
31
37#define in4_addr_is_local_network_control_block(addr) \
38 ((addr & 0xffffff00) == 0xe0000000)
39
44#define in4_addr_is_multicast(addr) \
45 ((addr & 0xf0000000) == 0xe0000000)
46
53#define in4_addr_is_private(addr) \
54 (((addr & 0xff000000) == 0x0a000000) || \
55 ((addr & 0xfff00000) == 0xac100000) || \
56 ((addr & 0xffff0000) == 0xc0a80000))
57
62#define in4_addr_is_link_local(addr) \
63 ((addr & 0xffff0000) == 0xa9fe0000)
64
69static inline bool
70in6_addr_is_linklocal(const ws_in6_addr *a)
71{
72 return (a->bytes[0] == 0xfe) && ((a->bytes[1] & 0xc0) == 0x80);
73}
74
75static inline bool
76in6_addr_is_sitelocal(const ws_in6_addr *a)
77{
78 return (a->bytes[0] == 0xfe) && ((a->bytes[1] & 0xc0) == 0xc0);
79}
80
81static inline bool in6_addr_is_uniquelocal(const ws_in6_addr *a)
82{
83 return (a->bytes[0] & 0xfe) == 0xfc;
84}
85
89static inline bool
90in6_addr_is_multicast(const ws_in6_addr *a)
91{
92 return a->bytes[0] == 0xff;
93}
94
95/*
96 * These are the values specified by RFC 2133 and its successors for
97 * INET_ADDRSTRLEN and INET6_ADDRSTRLEN.
98 *
99 * On UN*X systems, INET_ADDRSTRLEN and INET6_ADDRSTRLEN are defined
100 * to the values from RFC 2133 and its successors.
101 *
102 * However, on Windows:
103 *
104 * There are APIs RtlIpv4AddressToStringEx(), which converts an
105 * IPv4 address *and transport-layer port* to the address in the
106 * standard text form, followed by a colon and the port number,
107 * and RtlIpv6AddressToStringEx(), which converts an IPv6 address
108 * *and scope ID and transport-layer port* to the address in the
109 * standard text form, followed by a percent sign and the scope
110 * ID (with the address and scope ID in square brackets), followed
111 * by a colon and the port number.
112 *
113 * Instead of defining INET_ADDRSTRLEN_EX as 22 and INET6_ADDRSTRLEN_EX
114 * as 65, and saying *those* were the buffer sizes to use for
115 * RtlIpv4AddressToStringEx() and RtlIpv6AddressToStringEx(), they
116 * defined INET_ADDRSTRLEN to be 22 and INET6_ADDRSTRLEN to be 65 - and
117 * recommend using those as the size for the buffers passed to
118 * RtlIpv4AddressToStringEx() and RtlIpv6AddressToStringEx().
119 *
120 * At least they document inet_ntop() as requiring a 16-byte or larger
121 * buffer for IPv4 addresses and a 46-byte or larger buffer for
122 * IPv6 addresses. For this reason, use hard-coded numeric constants rather than
123 * INET_ADDRSTRLEN and INET6_ADDRSTRLEN.
124 */
125#define WS_INET_ADDRSTRLEN 16
126#define WS_INET6_ADDRSTRLEN 46
127
128/*
129 * Utility for CIDR notation of subnets
130 */
131#define WS_INET_CIDRADDRSTRLEN 19
132
133/*
134 * To check for errors set errno to zero before calling ws_inet_ntop{4,6}.
135 * ENOSPC is set if the result exceeds the given buffer size.
136 */
137WS_DLL_PUBLIC WS_RETNONNULL
138const char *
139ws_inet_ntop4(const void *src, char *dst, size_t dst_size);
140
141WS_DLL_PUBLIC WS_RETNONNULL
142const char *
143ws_inet_ntop6(const void *src, char *dst, size_t dst_size);
144
156WS_DLL_PUBLIC
157bool
158 ws_inet_pton4(const char *src, ws_in4_addr *dst);
159
171WS_DLL_PUBLIC
172bool
173 ws_inet_pton6(const char *src, ws_in6_addr *dst);
174
175#ifdef __cplusplus
176}
177#endif /* __cplusplus */
178
179#endif
ws_inet_pton6
WS_DLL_PUBLIC bool ws_inet_pton6(const char *src, ws_in6_addr *dst)
Definition inet_addr.c:99
ws_in6_addr
struct e_in6_addr ws_in6_addr
Represents a 128-bit IPv6 address.
ws_in4_addr
uint32_t ws_in4_addr
Represents a 32-bit IPv4 address in network byte order.
Definition inet_addr.h:22
ws_inet_pton4
WS_DLL_PUBLIC bool ws_inet_pton4(const char *src, ws_in4_addr *dst)
Definition inet_addr.c:87
e_in6_addr
Represents a 128-bit IPv6 address.
Definition inet_addr.h:27
e_in6_addr::bytes
uint8_t bytes[16]
Definition inet_addr.h:28