Wireshark  4.3.0
The Wireshark network protocol analyzer
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 #include "inet_ipv4.h"
16 #include "inet_ipv6.h"
17 
18 /*
19  * These are the values specified by RFC 2133 and its successors for
20  * INET_ADDRSTRLEN and INET6_ADDRSTRLEN.
21  *
22  * On UN*X systems, INET_ADDRSTRLEN and INET6_ADDRSTRLEN are defined
23  * to the values from RFC 2133 and its successors.
24  *
25  * However, on Windows:
26  *
27  * There are APIs RtlIpv4AddressToStringEx(), which converts an
28  * IPv4 address *and transport-layer port* to the address in the
29  * standard text form, followed by a colon and the port number,
30  * and RtlIpv6AddressToStringEx(), which converts an IPv6 address
31  * *and scope ID and transport-layer port* to the address in the
32  * standard text form, followed by a percent sign and the scope
33  * ID (with the address and scope ID in square brackets), followed
34  * by a colon and the port number.
35  *
36  * Instead of defining INET_ADDRSTRLEN_EX as 22 and INET6_ADDRSTRLEN_EX
37  * as 65, and saying *those* were the buffer sizes to use for
38  * RtlIpv4AddressToStringEx() and RtlIpv6AddressToStringEx(), they
39  * defined INET_ADDRSTRLEN to be 22 and INET6_ADDRSTRLEN to be 65 - and
40  * recommend using those as the size for the buffers passed to
41  * RtlIpv4AddressToStringEx() and RtlIpv6AddressToStringEx().
42  *
43  * At least they document inet_ntop() as requiring a 16-byte or larger
44  * buffer for IPv4 addresses and a 46-byte or larger buffer for
45  * IPv6 addresses. For this reason, use hard-coded numeric constants rather than
46  * INET_ADDRSTRLEN and INET6_ADDRSTRLEN.
47  */
48 #define WS_INET_ADDRSTRLEN 16
49 #define WS_INET6_ADDRSTRLEN 46
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif /* __cplusplus */
54 
55 /*
56  * To check for errors set errno to zero before calling ws_inet_ntop{4,6}.
57  * ENOSPC is set if the result exceeds the given buffer size.
58  */
59 WS_DLL_PUBLIC WS_RETNONNULL const char *
60 ws_inet_ntop4(const void *src, char *dst, size_t dst_size);
61 
62 WS_DLL_PUBLIC WS_RETNONNULL const char *
63 ws_inet_ntop6(const void *src, char *dst, size_t dst_size);
64 
65 WS_DLL_PUBLIC bool
66 ws_inet_pton4(const char *src, ws_in4_addr *dst);
67 
68 WS_DLL_PUBLIC bool
69 ws_inet_pton6(const char *src, ws_in6_addr *dst);
70 
71 #ifdef __cplusplus
72 }
73 #endif /* __cplusplus */
74 
75 #endif
Definition: inet_ipv6.h:21