Feature #5980
closedin-kernel inet_ntop should format IPv4 addresses like userland one
100%
Description
The in-kernel inet_ntop() formats 10.10.0.4 like this:
010.010.000.004
The leading zeros are different from how the standard inet_ntop() formats IPv4 addresses.
The old behavior is not "wrong" but is inconvenient, so this is an RFE.
Related issues
Updated by Joshua M. Clulow over 7 years ago
In the past we made some changes to the behaviour of inet_pton
in the kernel, as well. We retained the old behaviour for binary modules that could not be rebuilt, and used #pragma redefine_extname
to enable the fixed behaviour for newly compiled modules. We could do the same thing here, with a structure like:
#define ERROR_BAD_ADDRESS "<badaddr>" #define ERROR_BAD_FAMILY "<badfamily>" #define IPV4_PAD "%03d.%03d.%03d.%03d" #define IPV4_NOPAD "%d.%d.%d.%d" #define UC(b) (((int)b) & 0xff) /* * Common implementation. */ static char * inet_ntop_common(int af, const void *addr, char *buf, int addrlen, boolean_t ipv4_padding) { in6_addr_t *v6addr; uchar_t *v4addr; char *caddr; VERIFY(buf != NULL); VERIFY(addr != NULL); switch (af) { case AF_INET: VERIFY(addrlen >= INET_ADDRSTRLEN); v4addr = (uchar_t *)addr; (void) sprintf(buf, ipv4_padding ? IPV4_PAD : IPV4_NOPAD, UC(v4addr[0]), UC(v4addr[1]), UC(v4addr[2]), UC(v4addr[3])); return (buf); ... default: return (ERROR_BAD_FAMILY); } } /* * New wrapper. Using "#pragma redefine_extname" in the header to make this the * function that new users of "inet_ntop()" get. */ char * _inet_ntop(int af, const void *addr, char *buf, int addrlen) { return (inet_ntop_common(af, addr, buf, addrlen, B_FALSE)); } /* * Old wrapper. */ char * inet_ntop(int af, const void *addr, char *buf, int addrlen) { static char local_buf[INET6_ADDRSTRLEN]; ASSERT(buf != NULL); if (buf == NULL) { buf = local_buf; } return (inet_ntop_common(af, addr, buf, addrlen, B_TRUE)); }
Noting, of course, that if we're going to do this then we should scrub out all of the latent sadness in the current implementation (e.g. the static buffer, out-of-date comments, poorly defined macros, etc).
Updated by Marcel Telka over 7 years ago
- Related to Bug #6026: Zero-padded IP address strings returned by SMB added
Updated by Yuri Pankov over 5 years ago
- Subject changed from In-kernel inet_ntop should format IPv4 addresses like libnsl:inet_ntop to in-kernel inet_ntop should format IPv4 addresses like userland one
- Category set to kernel
- Status changed from New to In Progress
- Assignee set to Yuri Pankov
- % Done changed from 0 to 30
- Tags deleted (
needs-triage)
Updated by Yuri Pankov over 5 years ago
- Precedes Bug #8474: inet_ntop's addrlen argument should be socklen_t added
Updated by Yuri Pankov over 5 years ago
- Related to Bug #8488: mdb: idm module doesn't need a copy of kernel's inet_ntop added
Updated by Electric Monk over 5 years ago
- Status changed from In Progress to Closed
- % Done changed from 30 to 100
git commit 0b905b49d460a57773d88d714cd880ffe0182b7c
commit 0b905b49d460a57773d88d714cd880ffe0182b7c Author: Yuri Pankov <yuri.pankov@nexenta.com> Date: 2017-07-29T17:41:44.000Z 5980 in-kernel inet_ntop should format IPv4 addresses like userland one Reviewed by: Igor Kozhukhov <igor@dilos.org> Reviewed by: Dan McDonald <danmcd@joyent.com> Reviewed by: Vitaliy Gusev <gusev.vitaliy@icloud.com> Approved by: Richard Lowe <richlowe@richlowe.net>
Updated by Yuri Pankov over 3 years ago
- Related to Bug #11647: 6026 regressed after 5980 added