diff options
-rw-r--r-- | epan/addr_resolv.c | 78 | ||||
-rw-r--r-- | epan/addr_resolv.h | 28 | ||||
-rw-r--r-- | epan/address.h | 3 | ||||
-rw-r--r-- | epan/column-utils.c | 10 | ||||
-rw-r--r-- | gtk/conversations_table.c | 4 | ||||
-rw-r--r-- | gtk/hostlist_table.c | 10 |
6 files changed, 88 insertions, 45 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index 70b3859a85..9cb4e9d792 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -524,6 +524,33 @@ static gchar *host_name_lookup6(struct e_in6_addr *addr, gboolean *found) } /* host_name_lookup6 */ +const gchar *solve_address_to_name(address *addr) +{ + guint32 ipv4_addr; + struct e_in6_addr ipv6_addr; + + switch (addr->type) { + + case AT_ETHER: + return get_ether_name(addr->data); + + case AT_IPv4: + memcpy(&ipv4_addr, addr->data, sizeof ipv4_addr); + return get_hostname(ipv4_addr); + + case AT_IPv6: + memcpy(&ipv6_addr.s6_addr, addr->data, sizeof ipv6_addr.s6_addr); + return get_hostname6(&ipv6_addr); + + case AT_STRINGZ: + return addr->data; + + default: + return NULL; + } +} /* solve_address_to_name */ + + /* * Miscellaneous functions */ @@ -1897,31 +1924,40 @@ extern gchar *get_sctp_port(guint port) } /* get_sctp_port */ + const gchar *get_addr_name(address *addr) { - guint32 ipv4_addr; - struct e_in6_addr ipv6_addr; - - switch (addr->type) { - - case AT_ETHER: - return get_ether_name(addr->data); - - case AT_IPv4: - memcpy(&ipv4_addr, addr->data, sizeof ipv4_addr); - return get_hostname(ipv4_addr); - - case AT_IPv6: - memcpy(&ipv6_addr.s6_addr, addr->data, sizeof ipv6_addr.s6_addr); - return get_hostname6(&ipv6_addr); + const gchar *result; + + result = solve_address_to_name(addr); + + if (result!=NULL){ + return result; + } + + /* if it gets here, either it is of type AT_NONE, */ + /* or it should be solvable in address_to_str -unless addr->type is wrongly defined- */ + + if (addr->type == AT_NONE){ + return "NONE"; + } + + return(address_to_str(addr)); +} /* get_addr_name */ + + +void get_addr_name_buf(address *addr, gchar *buf, guint size) +{ + const gchar *result; + + result = get_addr_name(addr); + + strncpy(buf,result,size); + buf[size]='\0'; + return; - case AT_STRINGZ: - return addr->data; +} /* get_addr_name_buf */ - default: - return NULL; - } -} extern gchar *get_ether_name(const guint8 *addr) { diff --git a/epan/addr_resolv.h b/epan/addr_resolv.h index a9276ea9cb..d760fc2e35 100644 --- a/epan/addr_resolv.h +++ b/epan/addr_resolv.h @@ -80,15 +80,29 @@ extern gchar *get_tcp_port(guint port); */ extern gchar *get_sctp_port(guint port); -/* - * For address types that support name resolution, and for AT_STRINGZ, - * "get_addr_name()" returns the name corresponding to the address, - * or a string for the address if not found. - * - * For other address types, it returns a null pointer. - */ +/* get_addr_name takes as input an "address", as defined in address.h */ +/* it returns a string that contains: */ +/* - if the address is of a type that can be translated into a name, and the user */ +/* has activated name resolution, the translated name */ +/* - if the address is of type AT_NONE, a pointer to the string "NONE" */ +/* - if the address is of any other type, the result of address_to_str on the argument, */ +/* which should be a string representation for the answer -e.g. "10.10.10.10" for IPv4 */ +/* address 10.10.10.10 */ +/* take into account that get_addr_name might eventually call address_to_str and return */ +/* its result; this means that the returned pointer is only guaranteed to point to a valid */ +/* string immediately after return, because address_to_str overwrites its previous results */ +/* and it must not be g_free'd */ + const gchar *get_addr_name(address *addr); +/* get_addr_name_buf solves an address in the same way as get_addr_name above */ +/* The difference is that get_addr_name_buf takes as input a buffer, in which it puts */ +/* the result, and a maximum string length -size-. the buffer should be large enough to */ +/* contain size characters plus the terminator */ + +void get_addr_name_buf(address *addr, gchar *buf, guint size); + + /* * Asynchronous host name lookup initialization, processing, and cleanup */ diff --git a/epan/address.h b/epan/address.h index e0618474f8..c373275a8c 100644 --- a/epan/address.h +++ b/epan/address.h @@ -27,6 +27,9 @@ #define __ADDRESS_H__ /* Types of addresses Ethereal knows about. */ +/* If a new address type is added here, a string representation procedure should */ +/* also be included in address_to_str_buf defined in to_str.c, for presentation purposes */ + typedef enum { AT_NONE, /* no link-layer address */ AT_ETHER, /* MAC (Ethernet, 802.x, FDDI) address */ diff --git a/epan/column-utils.c b/epan/column-utils.c index c8f7d3578d..facb458097 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -574,20 +574,16 @@ static void col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res, gboolean is_src) { - const char *addr_string; struct e_in6_addr ipv6_addr; pinfo->cinfo->col_expr[col][0] = '\0'; pinfo->cinfo->col_expr_val[col][0] = '\0'; + if (addr->type == AT_NONE) return; /* no address, nothing to do */ + if (is_res) { - addr_string = get_addr_name(addr); - if (addr_string != NULL) { - strncpy(pinfo->cinfo->col_buf[col], addr_string, COL_MAX_LEN); - pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0'; - } else - address_to_str_buf(addr, pinfo->cinfo->col_buf[col]); + get_addr_name_buf(addr, pinfo->cinfo->col_buf[col],COL_MAX_LEN-1); } else { switch (addr->type) { diff --git a/gtk/conversations_table.c b/gtk/conversations_table.c index e8766d26ae..624ebfbdaa 100644 --- a/gtk/conversations_table.c +++ b/gtk/conversations_table.c @@ -962,8 +962,6 @@ draw_ct_table_address(conversations_table *ct, int conversation_idx) entry=address_to_str(&ct->conversations[conversation_idx].src_address); else { entry=get_addr_name(&ct->conversations[conversation_idx].src_address); - if(!entry) - entry=address_to_str(&ct->conversations[conversation_idx].src_address); } gtk_clist_set_text(ct->table, rownum, 0, entry); @@ -986,8 +984,6 @@ draw_ct_table_address(conversations_table *ct, int conversation_idx) entry=address_to_str(&ct->conversations[conversation_idx].dst_address); else { entry=get_addr_name(&ct->conversations[conversation_idx].dst_address); - if(!entry) - entry=address_to_str(&ct->conversations[conversation_idx].dst_address); } gtk_clist_set_text(ct->table, rownum, 2, entry); diff --git a/gtk/hostlist_table.c b/gtk/hostlist_table.c index 1bba285cdc..c47f175637 100644 --- a/gtk/hostlist_table.c +++ b/gtk/hostlist_table.c @@ -472,14 +472,12 @@ draw_hostlist_table_address(hostlist_table *hl, int hostlist_idx) rownum=gtk_clist_find_row_from_data(hl->table, (gpointer)hostlist_idx); - if(!hl->resolve_names) + if (!hl->resolve_names) entry=address_to_str(&hl->hosts[hostlist_idx].address); - else { + else entry=get_addr_name(&hl->hosts[hostlist_idx].address); - if(!entry) - entry=address_to_str(&hl->hosts[hostlist_idx].address); - } - gtk_clist_set_text(hl->table, rownum, 0, entry); + + gtk_clist_set_text(hl->table, rownum, 0, entry); pt = hl->hosts[hostlist_idx].port_type; if(!hl->resolve_names) pt = PT_NONE; |