diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-10-28 22:30:37 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-10-29 05:31:31 +0000 |
commit | ce25b358a94205c92e3b2612abf12119c50af1c4 (patch) | |
tree | 30bbef25f65270275d480b5991907ec9d4ebf555 /wsutil/inet_addr.h | |
parent | 0527747e23f85bb9d3cf4ca69364e615bd22e1e9 (diff) |
Go with the RFC 2133-and-successors values for IPv4 and IPv6 address strings.
Add a comment explaining why Windows has different, larger values for
INET_ADDRSTRLEN and INET6_ADDRSTRLEN.
Change-Id: I4ad53c6cffae46d108f778460ce653dcc9343c64
Reviewed-on: https://code.wireshark.org/review/24155
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil/inet_addr.h')
-rw-r--r-- | wsutil/inet_addr.h | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/wsutil/inet_addr.h b/wsutil/inet_addr.h index 078acc7afa..768c8e9a10 100644 --- a/wsutil/inet_addr.h +++ b/wsutil/inet_addr.h @@ -28,10 +28,37 @@ #include <glib.h> #include "inet_ipv6.h" -/* Choose a buffer size big enough for all implementations */ -#define WS_INET_ADDRSTRLEN 30 -#define WS_INET6_ADDRSTRLEN 80 - +/* + * These are the values specified by RFC 2133 and its successors for + * INET_ADDRSTRLEN and INET6_ADDRSTRLEN. + * + * On UN*X systems, INET_ADDRSTRLEN and INET6_ADDRSTRLEN are defined + * to the values from RFC 2133 and its successors. + * + * However, on Windows: + * + * There are APIs RtlIpv4AddressToStringEx(), which converts an + * IPv4 address *and transport-layer port* to the address in the + * standard text form, followed by a colon and the port number, + * and RtlIpv6AddressToStringEx(), which converts an IPv6 address + * *and scope ID and transport-layer port* to the address in the + * standard text form, followed by a percent sign and the scope + * ID (with the address and scope ID in square brackets), followed + * by a colon and the port number. + * + * Instead of defining INET_ADDRSTRLEN_EX as 22 and INET6_ADDRSTRLEN_EX + * as 65, and saying *those* were the buffer sizes to use for + * RtlIpv4AddressToStringEx() and RtlIpv6AddressToStringEx(), they + * defined INET_ADDRSTRLEN to be 22 and INET6_ADDRSTRLEN to be 65 - and + * recommend using those as the size for the buffers passed to + * RtlIpv4AddressToStringEx() and RtlIpv6AddressToStringEx(). + * + * At least they document inet_ntop() as requiring a 16-byte or larger + * buffer for IPv4 addresses and a 46-byte or larger buffer for + * IPv6 addresses. + */ +#define WS_INET_ADDRSTRLEN 16 +#define WS_INET6_ADDRSTRLEN 46 WS_DLL_PUBLIC WS_RETNONNULL const gchar * ws_inet_ntop4(gconstpointer src, gchar *dst, guint dst_size); |