diff options
author | Ronnie Sahlberg <ronnie_sahlberg@ozemail.com.au> | 2003-08-24 02:50:32 +0000 |
---|---|---|
committer | Ronnie Sahlberg <ronnie_sahlberg@ozemail.com.au> | 2003-08-24 02:50:32 +0000 |
commit | 521db7b61f23abc4bad8fb5003d477dcdd3fcab6 (patch) | |
tree | 741d9cbae5a289c7b4975fe6c827253382af179e /epan | |
parent | dd59725fc1d576d62a35a9e52389ee76eef37c93 (diff) | |
download | wireshark-521db7b61f23abc4bad8fb5003d477dcdd3fcab6.tar.gz wireshark-521db7b61f23abc4bad8fb5003d477dcdd3fcab6.tar.bz2 wireshark-521db7b61f23abc4bad8fb5003d477dcdd3fcab6.zip |
Add a new function address_to_str to to_str.c
Implement conersion from address to string for IPv4 and IPv6
and update the conversation tables to use the new interface.
svn path=/trunk/; revision=8234
Diffstat (limited to 'epan')
-rw-r--r-- | epan/to_str.c | 40 | ||||
-rw-r--r-- | epan/to_str.h | 3 |
2 files changed, 41 insertions, 2 deletions
diff --git a/epan/to_str.c b/epan/to_str.c index 735bc32952..6ef139b69e 100644 --- a/epan/to_str.c +++ b/epan/to_str.c @@ -1,7 +1,7 @@ /* to_str.c * Routines for utilities to convert various other types to strings. * - * $Id: to_str.c,v 1.31 2003/08/24 01:06:21 guy Exp $ + * $Id: to_str.c,v 1.32 2003/08/24 02:50:31 sahlberg Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -127,6 +127,9 @@ ether_to_str(const guint8 *ad) return bytestring_to_str(ad, 6, ':'); } +/* XXX FIXME +remove this one later when every call has been converted to address_to_str() +*/ gchar * ip_to_str(const guint8 *ad) { static gchar str[4][16]; @@ -178,6 +181,10 @@ ip_to_str_buf(const guint8 *ad, gchar *buf) *p = '\0'; } + +/* XXX FIXME +remove this one later when every call has been converted to address_to_str() +*/ gchar * ip6_to_str(const struct e_in6_addr *ad) { #ifndef INET6_ADDRSTRLEN @@ -714,3 +721,34 @@ decode_numeric_bitfield(guint32 val, guint32 mask, int width, sprintf(p, fmt, (val & mask) >> shift); return buf; } + + +/* convert an address struct into a printable string */ +gchar* +address_to_str(address *addr) +{ +#ifndef INET6_ADDRSTRLEN +#define INET6_ADDRSTRLEN 46 +#endif + static int i=0; + static gchar *strp, str[16][INET6_ADDRSTRLEN];/* IPv6 is the largest one */ + + i++; + if(i>=16){ + i=0; + } + strp=str[i]; + + switch(addr->type){ + case AT_IPv4: + ip_to_str_buf(addr->data, strp); + return strp; + case AT_IPv6: + inet_ntop(AF_INET6, addr->data, strp, INET6_ADDRSTRLEN); + return strp; + } + + /* unknown type of address */ + g_assert_not_reached(); + return NULL; +} diff --git a/epan/to_str.h b/epan/to_str.h index df0e68be79..d04e708026 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -1,7 +1,7 @@ /* to_str.h * Definitions for utilities to convert various other types to strings. * - * $Id: to_str.h,v 1.17 2003/08/24 01:06:21 guy Exp $ + * $Id: to_str.h,v 1.18 2003/08/24 02:50:31 sahlberg Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -46,6 +46,7 @@ typedef enum { struct e_in6_addr; +extern gchar* address_to_str(address *); extern gchar* ether_to_str(const guint8 *); extern gchar* ip_to_str(const guint8 *); extern void ip_to_str_buf(const guint8 *, gchar *); |