Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: [Wireshark-dev] parsing an IPv6 address from a text string

From: Martin Kaiser <lists@xxxxxxxxx>
Date: Sun, 14 Oct 2012 19:50:53 +0200
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