Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
inet_addr.h
1 /* inet_addr.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef __WS_INET_ADDR_H__
11 #define __WS_INET_ADDR_H__
12 
13 #include "ws_symbol_export.h"
14 #include "ws_attributes.h"
15 
16 #ifdef HAVE_NETINET_IN_H
17 #include <netinet/in.h>
18 #endif
19 
20 #include <glib.h>
21 #include "inet_ipv4.h"
22 #include "inet_ipv6.h"
23 
24 /*
25  * These are the values specified by RFC 2133 and its successors for
26  * INET_ADDRSTRLEN and INET6_ADDRSTRLEN.
27  *
28  * On UN*X systems, INET_ADDRSTRLEN and INET6_ADDRSTRLEN are defined
29  * to the values from RFC 2133 and its successors.
30  *
31  * However, on Windows:
32  *
33  * There are APIs RtlIpv4AddressToStringEx(), which converts an
34  * IPv4 address *and transport-layer port* to the address in the
35  * standard text form, followed by a colon and the port number,
36  * and RtlIpv6AddressToStringEx(), which converts an IPv6 address
37  * *and scope ID and transport-layer port* to the address in the
38  * standard text form, followed by a percent sign and the scope
39  * ID (with the address and scope ID in square brackets), followed
40  * by a colon and the port number.
41  *
42  * Instead of defining INET_ADDRSTRLEN_EX as 22 and INET6_ADDRSTRLEN_EX
43  * as 65, and saying *those* were the buffer sizes to use for
44  * RtlIpv4AddressToStringEx() and RtlIpv6AddressToStringEx(), they
45  * defined INET_ADDRSTRLEN to be 22 and INET6_ADDRSTRLEN to be 65 - and
46  * recommend using those as the size for the buffers passed to
47  * RtlIpv4AddressToStringEx() and RtlIpv6AddressToStringEx().
48  *
49  * At least they document inet_ntop() as requiring a 16-byte or larger
50  * buffer for IPv4 addresses and a 46-byte or larger buffer for
51  * IPv6 addresses.
52  */
53 #ifdef INET_ADDRSTRLEN
54  #define WS_INET_ADDRSTRLEN INET_ADDRSTRLEN
55 #else
56  #define WS_INET_ADDRSTRLEN 16
57 #endif
58 #ifdef INET6_ADDRSTRLEN
59  #define WS_INET6_ADDRSTRLEN INET6_ADDRSTRLEN
60 #else
61  #define WS_INET6_ADDRSTRLEN 46
62 #endif
63 
64 /*
65  * To check for errors set errno to zero before calling ws_inet_ntop{4,6}.
66  * ENOSPC is set if the result exceeds the given buffer size.
67  */
68 WS_DLL_PUBLIC WS_RETNONNULL const gchar *
69 ws_inet_ntop4(gconstpointer src, gchar *dst, guint dst_size);
70 
71 WS_DLL_PUBLIC WS_RETNONNULL const gchar *
72 ws_inet_ntop6(gconstpointer src, gchar *dst, guint dst_size);
73 
74 WS_DLL_PUBLIC gboolean
75 ws_inet_pton4(const gchar *src, ws_in4_addr *dst);
76 
77 WS_DLL_PUBLIC gboolean
78 ws_inet_pton6(const gchar *src, ws_in6_addr *dst);
79 
80 #endif
Definition: inet_ipv6.h:20