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