forked from osmocom/wireshark
Add a new "ip_to_str_buf()" routine that takes a pointer to an IP
address and a pointer to a character buffer as arguments, and puts a printable form of the IP address into the buffer. Make "ip_to_str()" use it. Make "host_name_lookup()" use "ip_to_str_buf()", not "ip_to_str()", so that it doesn't trash any strings that a dissector has gotten with "ip_to_str()" (for example, the ARP dissector gets strings for the source and target protocol addresses, and then may attempt to register names for the source and target hardware addresses with "add_ether_byip()"; if "host_name_lookup()" fails to find a host name for the IP address, it shouldn't use "ip_to_str()" to generate an IP address string to associate with the IP address, as if that's done twice it'll run out of "ip_to_str()" buffers - there're only 3 of them - and trash one of the IP address strings the ARP dissector got). svn path=/trunk/; revision=2850
This commit is contained in:
parent
43ccfd8054
commit
0ae122c3a9
|
@ -1,7 +1,7 @@
|
|||
/* packet.c
|
||||
* Routines for packet disassembly
|
||||
*
|
||||
* $Id: packet.c,v 1.13 2001/01/09 06:32:06 guy Exp $
|
||||
* $Id: packet.c,v 1.14 2001/01/09 09:57:06 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -181,10 +181,6 @@ gchar *
|
|||
ip_to_str(const guint8 *ad) {
|
||||
static gchar str[3][16];
|
||||
static gchar *cur;
|
||||
gchar *p;
|
||||
int i;
|
||||
guint32 octet;
|
||||
guint32 digit;
|
||||
|
||||
if (cur == &str[0][0]) {
|
||||
cur = &str[1][0];
|
||||
|
@ -193,25 +189,41 @@ ip_to_str(const guint8 *ad) {
|
|||
} else {
|
||||
cur = &str[0][0];
|
||||
}
|
||||
p = &cur[16];
|
||||
*--p = '\0';
|
||||
i = 3;
|
||||
ip_to_str_buf(ad, cur);
|
||||
return cur;
|
||||
}
|
||||
|
||||
void
|
||||
ip_to_str_buf(const guint8 *ad, gchar *buf)
|
||||
{
|
||||
gchar *p;
|
||||
int i;
|
||||
guint32 octet;
|
||||
guint32 digit;
|
||||
gboolean saw_nonzero;
|
||||
|
||||
p = buf;
|
||||
i = 0;
|
||||
for (;;) {
|
||||
saw_nonzero = FALSE;
|
||||
octet = ad[i];
|
||||
*--p = (octet%10) + '0';
|
||||
octet /= 10;
|
||||
digit = octet/100;
|
||||
if (digit != 0) {
|
||||
*p++ = digit + '0';
|
||||
saw_nonzero = TRUE;
|
||||
}
|
||||
octet %= 100;
|
||||
digit = octet/10;
|
||||
if (saw_nonzero || digit != 0)
|
||||
*p++ = digit + '0';
|
||||
digit = octet%10;
|
||||
octet /= 10;
|
||||
if (digit != 0 || octet != 0)
|
||||
*--p = digit + '0';
|
||||
if (octet != 0)
|
||||
*--p = octet + '0';
|
||||
if (i == 0)
|
||||
*p++ = digit + '0';
|
||||
if (i == 3)
|
||||
break;
|
||||
*--p = '.';
|
||||
i--;
|
||||
*p++ = '.';
|
||||
i++;
|
||||
}
|
||||
return p;
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
gchar *
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* packet.h
|
||||
* Definitions for packet disassembly structures and routines
|
||||
*
|
||||
* $Id: packet.h,v 1.17 2001/01/09 06:32:06 guy Exp $
|
||||
* $Id: packet.h,v 1.18 2001/01/09 09:57:06 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -302,6 +302,7 @@ void call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
|
|||
gchar* ether_to_str(const guint8 *);
|
||||
gchar* ether_to_str_punct(const guint8 *, char);
|
||||
gchar* ip_to_str(const guint8 *);
|
||||
void ip_to_str_buf(const guint8 *, gchar *);
|
||||
struct e_in6_addr;
|
||||
gchar* ip6_to_str(struct e_in6_addr *);
|
||||
gchar* ipx_addr_to_str(guint32, const guint8 *);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* resolv.c
|
||||
* Routines for network object lookup
|
||||
*
|
||||
* $Id: resolv.c,v 1.4 2000/11/19 19:45:54 gerald Exp $
|
||||
* $Id: resolv.c,v 1.5 2001/01/09 09:57:06 guy Exp $
|
||||
*
|
||||
* Laurent Deniel <deniel@worldnet.fr>
|
||||
*
|
||||
|
@ -306,7 +306,7 @@ static u_char *host_name_lookup(u_int addr, gboolean *found)
|
|||
|
||||
/* unknown host or DNS timeout */
|
||||
|
||||
sprintf(tp->name, "%s", ip_to_str((guint8 *)&addr));
|
||||
ip_to_str_buf((guint8 *)&addr, tp->name);
|
||||
tp->is_dummy_entry = TRUE;
|
||||
*found = FALSE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue