[PATCH 1/1] ping: Add support for IPv4-mapped IPv6 address format
Steffen Nurpmeso
steffen at sdaoden.eu
Wed Oct 23 21:17:52 UTC 2024
David Leonard wrote in
<1qs786o8-714q-23nn-649q-o331s404so3r at nqncgvir-ragrecevfrf.pbz>:
|On Sun, 20 Oct 2024, Lars Uffmann wrote:
|> As for the points David brings up:
|> On 2024-10-20 13:51:32, Petr Vorel wrote:
|>>>> I'm not a fan of this patch because ping is a low-level diagnostic \
|>>>> tool.
|> While I would acknowlege the low-level diagnostic part, I do think \
|> it has
|> uses that go beyond that - since most operating systems can be configure\
|> d to
|
|I spent some time with your application trying to understand what
|networking it's doing and the motivating context... and I would
|recommend you look at getaddrinfo() and getnodeinfo(). These are
|supported by cygwin64 (mentioned in file comments). My general advice
|to you is to try and make your application address agnostic.
|
|It seems clear that this patch to ping exists only because of your
|application's deliberate construction of IPv4-mapped IPv6
|addresses to fit a poor choice of type/represenation.
|
|I see that the code had previously been using uint32_t for addresses,
|and switched to in6_addr for IPv6 support. The incorrect assumption is
|that in6_addr is simply a superspace of IPv4. (It's not.) You would be
|better off using something to track address families, such as
|a struct sockaddr_storage or struct addrinfo (latter is more portable).
On the other hand Linux (and OpenIndiana/Solaris) just (seem to)
work neatlessly with IPv4-mapped addresses (for server sockets).
In a simple thing i thus used
/* Whether we should open distinct IPv4 and IPv6 sockets */
#undef a_DISTINCT_SOCKS
#if defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
# define a_DISTINCT_SOCKS
#endif
and then mess like
#ifdef a_DISTINCT_SOCKS
fd_set rfds;
struct sockaddr_in soa4;
int sofd4;
#endif
struct sockaddr_in6 soa6;
int sofd6, es;
as well as
#if defined a_DISTINCT_SOCKS && defined IPV6_V6ONLY
int one;
one = 1;
if(setsockopt(sofd6, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&one, sizeof(one)) == -1){
fprintf(stderr, "IPv6 cannot set server socket option V6ONLY: %s\n", strerror(errno));
es = a_EX_OSERR;
goto jleave;
}
#endif
ie, if relying on (the standardized) IPv4-mapped addresses one can
avoid a whole bunch of things, including polling/selection,
system-specific problems etc.
...
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)
More information about the busybox
mailing list