Hi,
as part of #7729, we have to parse a text string that contains an IPv6
address and convert it into a sequence of bytes - and detect malformed
addresses.
The current proposal does the parsing manually. I was wondering if we
could simplify things by using getaddrinfo(). It seems that it's
available for >=WinXP and *NIX. Calling it on windows needs some winsock
initializations but in general, there wouldn't be huge differences
between platforms.
I'd be thinking about something like
-------------------
struct addrinfo hints, *res = NULL;
struct sockaddr_in6 *sin6;
const char service[] = "discard"; /* well-known, unique port */
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_NUMERICHOST; /* no DNS lookup */
ret = getaddrinfo(addr, service, &hints, &res);
if (ret!=0)
goto end;
if (res->ai_addr->sa_family!=AF_INET6)
goto end;
sin6 = (struct sockaddr_in6 *)(res->ai_addr);
/* take bytes from sin6->sin6_addr */
freeaddrinfo(res);
-------------------
Any views about this?
Thanks,
Martin