Wireshark mailing list archives

Re: parsing an IPv6 address from a text string


From: Alexander Koeppe <format_c () online de>
Date: Mon, 15 Oct 2012 13:50:17 +0200

Am 14.10.2012 21:14, schrieb Guy Harris:

On Oct 14, 2012, at 10:50 AM, Martin Kaiser <lists () kaiser cx> wrote:

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().

You could probably simplify things even more by using inet_pton() (as Alexander Koeppe noted in the bug) rather than 
getaddrinfo().

We're already using inet_pton() (and supply our own version for platforms where it's unavailable), so we can use it 
elsewhere.
___________________________________________________________________________
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


My first version with inet_pton() works quite well. Just considering to
properly include the necessary headers.

From what I can see I have to include ...
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>     /* needed to define AF_ values on UNIX */
#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>       /* needed to define AF_ values on Windows */
#endif

And additionally for non *NIX ....
#ifdef NEED_INET_V6DEFS_H
#include "wsutil/inet_v6defs.h" /* if not a *NIX system */
#endif

Would that be correct?

Cheers
Alex


___________________________________________________________________________
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: