aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2005-02-22 01:55:04 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2005-02-22 01:55:04 +0000
commitf0c8a7ab65ef1de88c904b2e7cad1a7271a8080f (patch)
tree4b6368356b747ae30172bb23aaf62df99b2d20fa /epan
parent9edd68b0e18abc9fd5ec454ead938d282b3ce525 (diff)
From Francisco Alcoba:
changed the behaviour of get_addr_name: - resolve to a name if the address supports it - call address_to_str if it does not, but the address is valid - return "NONE" if it is AT_NONE svn path=/trunk/; revision=13463
Diffstat (limited to 'epan')
-rw-r--r--epan/addr_resolv.c78
-rw-r--r--epan/addr_resolv.h28
-rw-r--r--epan/address.h3
-rw-r--r--epan/column-utils.c10
4 files changed, 84 insertions, 35 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) {