Wireshark mailing list archives
parsing an IPv6 address from a text string
From: Martin Kaiser <lists () kaiser cx>
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
___________________________________________________________________________
Sent via: Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives: http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
Current thread:
- parsing an IPv6 address from a text string Martin Kaiser (Oct 14)
- Re: parsing an IPv6 address from a text string Guy Harris (Oct 14)
- Re: parsing an IPv6 address from a text string Alexander Koeppe (Oct 15)
- Re: parsing an IPv6 address from a text string Alexander Koeppe (Oct 15)
- Re: parsing an IPv6 address from a text string Guy Harris (Oct 14)
