diff --git a/epan/address.h b/epan/address.h index 3b0ac47a3a..0d433ece8a 100644 --- a/epan/address.h +++ b/epan/address.h @@ -40,15 +40,12 @@ typedef enum { AT_IPv4, /* IPv4 */ AT_IPv6, /* IPv6 */ AT_IPX, /* IPX */ - AT_ATALK, /* Appletalk DDP */ AT_VINES, /* Banyan Vines */ - AT_ARCNET, /* ARCNET */ AT_FC, /* Fibre Channel */ AT_FCWWN, /* Fibre Channel WWN */ AT_SS7PC, /* SS7 Point Code */ AT_STRINGZ, /* null-terminated string */ AT_EUI64, /* IEEE EUI-64 */ - AT_URI, /* URI/URL/URN */ AT_IB, /* Infiniband GID/LID */ AT_USB, /* USB Device address * (0xffffffff represents the host) */ diff --git a/epan/address_to_str.c b/epan/address_to_str.c index bcdf3f770b..228133a58c 100644 --- a/epan/address_to_str.c +++ b/epan/address_to_str.c @@ -240,22 +240,6 @@ eui64_to_str(wmem_allocator_t *scope, const guint64 ad) { return buf; } -static void -atalk_addr_to_str_buf(const struct atalk_ddp_addr *addrp, gchar *buf, int buf_len) -{ - g_snprintf(buf, buf_len, "%u.%u", addrp->net, addrp->node ); -} - -gchar * -atalk_addr_to_str(const struct atalk_ddp_addr *addrp) -{ - gchar *cur; - - cur=(gchar *)wmem_alloc(wmem_packet_scope(), 14); - atalk_addr_to_str_buf(addrp, cur, 14); - return cur; -} - gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, const gint offset) { @@ -281,7 +265,6 @@ tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, co case AT_IPX: addr.len = 10; break; - case AT_ATALK: case AT_FC: addr.len = 3; break; @@ -297,12 +280,8 @@ tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, co case AT_AX25: addr.len = AX25_ADDR_LEN; break; - case AT_ARCNET: - addr.len = 1; - break; case AT_SS7PC: case AT_STRINGZ: - case AT_URI: case AT_IB: /* Have variable length fields, use tvb_address_var_to_str() */ case AT_USB: diff --git a/epan/address_types.c b/epan/address_types.c index 96dc3da4a5..7c7c9783a2 100644 --- a/epan/address_types.c +++ b/epan/address_types.c @@ -46,11 +46,12 @@ #include struct _address_type_t { - int addr_type; /* From address_type enumeration or registered value */ - const char *name; - const char *pretty_name; - AddrValueToString addr_to_str; - AddrValueToStringLen addr_str_len; + int addr_type; /* From address_type enumeration or registered value */ + const char *name; + const char *pretty_name; + AddrValueToString addr_to_str; + AddrValueToStringLen addr_str_len; + AddrColFilterString addr_col_filter; /* XXX - Some sort of compare functions (like ftype)? ***/ /* XXX - Include functions for name resolution? ***/ @@ -73,20 +74,21 @@ static address_type_t* type_list[MAX_ADDR_TYPE_VALUE]; */ #define BUF_TOO_SMALL_ERR "[Buffer too small]" -void address_type_register(int addr_type, address_type_t *at) +static void address_type_register(int addr_type, address_type_t *at) { - /* Check input */ - g_assert(addr_type < MAX_ADDR_TYPE_VALUE); - g_assert(addr_type == at->addr_type); + /* Check input */ + g_assert(addr_type < MAX_ADDR_TYPE_VALUE); + g_assert(addr_type == at->addr_type); - /* Don't re-register. */ - g_assert(type_list[addr_type] == NULL); + /* Don't re-register. */ + g_assert(type_list[addr_type] == NULL); - type_list[addr_type] = at; + type_list[addr_type] = at; } int address_type_dissector_register(const char* name, const char* pretty_name, - AddrValueToString to_str_func, AddrValueToStringLen str_len_func) + AddrValueToString to_str_func, AddrValueToStringLen str_len_func, + AddrColFilterString col_filter_str_func) { int addr_type; @@ -105,6 +107,7 @@ int address_type_dissector_register(const char* name, const char* pretty_name, dissector_type_addresses[num_dissector_addr_type].pretty_name = pretty_name; dissector_type_addresses[num_dissector_addr_type].addr_to_str = to_str_func; dissector_type_addresses[num_dissector_addr_type].addr_str_len = str_len_func; + dissector_type_addresses[num_dissector_addr_type].addr_col_filter = col_filter_str_func; type_list[addr_type] = &dissector_type_addresses[num_dissector_addr_type]; @@ -142,6 +145,14 @@ static int ether_str_len(const address* addr _U_) return 18; } +const char* ether_col_filter_str(const address* addr _U_, gboolean is_src) +{ + if (is_src) + return "eth.src"; + + return "eth.dst"; +} + /****************************************************************************** * AT_IPv4 ******************************************************************************/ @@ -156,6 +167,14 @@ static int ipv4_str_len(const address* addr _U_) return MAX_IP_STR_LEN; } +const char* ipv4_col_filter_str(const address* addr _U_, gboolean is_src) +{ + if (is_src) + return "ip.src"; + + return "ip.dst"; +} + /****************************************************************************** * AT_IPv6 ******************************************************************************/ @@ -172,6 +191,14 @@ static int ipv6_str_len(const address* addr _U_) return MAX_IP6_STR_LEN; } +const char* ipv6_col_filter_str(const address* addr _U_, gboolean is_src) +{ + if (is_src) + return "ipv6.src"; + + return "ipv6.dst"; +} + /****************************************************************************** * AT_IPX ******************************************************************************/ @@ -191,30 +218,6 @@ static int ipx_str_len(const address* addr _U_) return 22; } - -/****************************************************************************** - * AT_ATALK - * XXX - This functionality should really be in packet-atalk.c as a dissector - * address type, but currently need support of AT_ATALK in column-utils.c - ******************************************************************************/ -static gboolean atalk_to_str(const address* addr, gchar *buf, int buf_len _U_) -{ - struct atalk_ddp_addr atalk; - memcpy(&atalk, addr->data, sizeof atalk); - - buf = word_to_hex(buf, atalk.net); - *buf++ = '.'; - buf = bytes_to_hexstr(buf, &atalk.node, 1); - *buf++ = '\0'; /* NULL terminate */ - - return TRUE; -} - -static int atalk_str_len(const address* addr _U_) -{ - return 14; -} - /****************************************************************************** * AT_VINES * XXX - This functionality should really be in packet-vines.c as a dissector @@ -237,26 +240,6 @@ static int vines_str_len(const address* addr _U_) return 14; } -/****************************************************************************** - * AT_ARCNET - * XXX - This functionality should really be in packet-arcnet.c as a dissector - * address type, but currently need support of AT_ARCNET in column-utils.c - ******************************************************************************/ -static gboolean arcnet_to_str(const address* addr, gchar *buf, int buf_len _U_) -{ - *buf++ = '0'; - *buf++ = 'x'; - buf = bytes_to_hexstr(buf, (const guint8 *)addr->data, 1); - *buf = '\0'; /* NULL terminate */ - - return TRUE; -} - -static int arcnet_str_len(const address* addr _U_) -{ - return 5; -} - /****************************************************************************** * AT_FC ******************************************************************************/ @@ -386,24 +369,6 @@ static int eui64_str_len(const address* addr _U_) return 24; } -/****************************************************************************** - * AT_URI - * XXX - This functionality should really be in packet-jxta.c as a dissector - * address type, but currently need support of AT_URI in column-utils.c - ******************************************************************************/ -static gboolean uri_to_str(const address* addr, gchar *buf, int buf_len) -{ - int copy_len = addr->len < (buf_len - 1) ? addr->len : (buf_len - 1); - memcpy(buf, addr->data, copy_len ); - buf[copy_len] = '\0'; - return TRUE; -} - -static int uri_str_len(const address* addr) -{ - return addr->len+1; -} - /****************************************************************************** * AT_IB ******************************************************************************/ @@ -411,7 +376,7 @@ static gboolean ib_addr_to_str( const address *addr, gchar *buf, int buf_len){ if (addr->len >= 16) { /* GID is 128bits */ #define PREAMBLE_STR_LEN ((int)(sizeof("GID: ") - 1)) - g_snprintf(buf,buf_len,"GID: "); + g_strlcpy(buf, "GID: ", buf_len); if (buf_len < PREAMBLE_STR_LEN || inet_ntop(AF_INET6, addr->data, buf + PREAMBLE_STR_LEN, buf_len - PREAMBLE_STR_LEN) == NULL ) /* Returns NULL if no space and does not touch buf */ @@ -480,6 +445,14 @@ static int ax25_addr_str_len(const address* addr _U_) return 21; /* Leaves extra space (10 bytes) just for uint_to_str_back() */ } +const char* ax25_col_filter_str(const address* addr _U_, gboolean is_src) +{ + if (is_src) + return "ax25.src"; + + return "ax25.dst"; +} + /****************************************************************************** * END OF PROVIDED ADDRESS TYPES ******************************************************************************/ @@ -490,139 +463,129 @@ static int ax25_addr_str_len(const address* addr _U_) void address_types_initialize(void) { static address_type_t none_address = { - AT_NONE, /* addr_type */ - "AT_NONE", /* name */ - "No address", /* pretty_name */ - none_addr_to_str, /* addr_to_str */ - none_addr_str_len /* addr_str_len */ + AT_NONE, /* addr_type */ + "AT_NONE", /* name */ + "No address", /* pretty_name */ + none_addr_to_str, /* addr_to_str */ + none_addr_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t ether_address = { - AT_ETHER, /* addr_type */ - "AT_ETHER", /* name */ - "Ethernet address", /* pretty_name */ - ether_to_str, /* addr_to_str */ - ether_str_len /* addr_str_len */ + AT_ETHER, /* addr_type */ + "AT_ETHER", /* name */ + "Ethernet address", /* pretty_name */ + ether_to_str, /* addr_to_str */ + ether_str_len, /* addr_str_len */ + ether_col_filter_str /* addr_col_filter */ }; static address_type_t ipv4_address = { - AT_IPv4, /* addr_type */ - "AT_IPv4", /* name */ - "IPv4 address", /* pretty_name */ - ipv4_to_str, /* addr_to_str */ - ipv4_str_len /* addr_str_len */ + AT_IPv4, /* addr_type */ + "AT_IPv4", /* name */ + "IPv4 address", /* pretty_name */ + ipv4_to_str, /* addr_to_str */ + ipv4_str_len, /* addr_str_len */ + ipv4_col_filter_str /* addr_col_filter */ }; static address_type_t ipv6_address = { - AT_IPv6, /* addr_type */ - "AT_IPv6", /* name */ - "IPv6 address", /* pretty_name */ - ipv6_to_str, /* addr_to_str */ - ipv6_str_len /* addr_str_len */ - }; + AT_IPv6, /* addr_type */ + "AT_IPv6", /* name */ + "IPv6 address", /* pretty_name */ + ipv6_to_str, /* addr_to_str */ + ipv6_str_len, /* addr_str_len */ + ipv6_col_filter_str /* addr_col_filter */ + }; static address_type_t ipx_address = { - AT_IPX, /* addr_type */ - "AT_IPX", /* name */ - "IPX address", /* pretty_name */ - ipx_to_str, /* addr_to_str */ - ipx_str_len /* addr_str_len */ - }; - - static address_type_t atalk_address = { - AT_ATALK, /* addr_type */ - "AT_ATALK", /* name */ - "ATALK address", /* pretty_name */ - atalk_to_str, /* addr_to_str */ - atalk_str_len /* addr_str_len */ + AT_IPX, /* addr_type */ + "AT_IPX", /* name */ + "IPX address", /* pretty_name */ + ipx_to_str, /* addr_to_str */ + ipx_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t vines_address = { - AT_VINES, /* addr_type */ - "AT_VINES", /* name */ - "Banyan Vines address", /* pretty_name */ - vines_to_str, /* addr_to_str */ - vines_str_len /* addr_str_len */ - }; - - static address_type_t arcnet_address = { - AT_ARCNET, /* addr_type */ - "AT_ARCNET", /* name */ - "ARCNET address", /* pretty_name */ - arcnet_to_str, /* addr_to_str */ - arcnet_str_len /* addr_str_len */ + AT_VINES, /* addr_type */ + "AT_VINES", /* name */ + "Banyan Vines address", /* pretty_name */ + vines_to_str, /* addr_to_str */ + vines_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t fc_address = { - AT_FC, /* addr_type */ - "AT_FC", /* name */ - "FC address", /* pretty_name */ - fc_to_str, /* addr_to_str */ - fc_str_len /* addr_str_len */ + AT_FC, /* addr_type */ + "AT_FC", /* name */ + "FC address", /* pretty_name */ + fc_to_str, /* addr_to_str */ + fc_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t fcwwn_address = { - AT_FCWWN, /* addr_type */ - "AT_FCWWN", /* name */ - "Fibre Channel WWN", /* pretty_name */ - fcwwn_to_str, /* addr_to_str */ - fcwwn_str_len /* addr_str_len */ + AT_FCWWN, /* addr_type */ + "AT_FCWWN", /* name */ + "Fibre Channel WWN", /* pretty_name */ + fcwwn_to_str, /* addr_to_str */ + fcwwn_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t ss7pc_address = { - AT_SS7PC, /* addr_type */ - "AT_SS7PC", /* name */ - "SS7 Point Code", /* pretty_name */ - ss7pc_to_str, /* addr_to_str */ - ss7pc_str_len /* addr_str_len */ + AT_SS7PC, /* addr_type */ + "AT_SS7PC", /* name */ + "SS7 Point Code", /* pretty_name */ + ss7pc_to_str, /* addr_to_str */ + ss7pc_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t stringz_address = { - AT_STRINGZ, /* addr_type */ - "AT_STRINGZ", /* name */ - "String address", /* pretty_name */ - stringz_addr_to_str, /* addr_to_str */ - stringz_addr_str_len /* addr_str_len */ + AT_STRINGZ, /* addr_type */ + "AT_STRINGZ", /* name */ + "String address", /* pretty_name */ + stringz_addr_to_str, /* addr_to_str */ + stringz_addr_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t eui64_address = { - AT_EUI64, /* addr_type */ - "AT_EUI64", /* name */ - "IEEE EUI-64", /* pretty_name */ - eui64_addr_to_str, /* addr_to_str */ - eui64_str_len /* addr_str_len */ - }; - - static address_type_t uri_address = { - AT_URI, /* addr_type */ - "AT_URI", /* name */ - "URI/URL/URN", /* pretty_name */ - uri_to_str, /* addr_to_str */ - uri_str_len /* addr_str_len */ + AT_EUI64, /* addr_type */ + "AT_EUI64", /* name */ + "IEEE EUI-64", /* pretty_name */ + eui64_addr_to_str, /* addr_to_str */ + eui64_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t ib_address = { - AT_IB, /* addr_type */ - "AT_IB", /* name */ - "Infiniband GID/LID", /* pretty_name */ - ib_addr_to_str, /* addr_to_str */ - ib_str_len /* addr_str_len */ + AT_IB, /* addr_type */ + "AT_IB", /* name */ + "Infiniband GID/LID", /* pretty_name */ + ib_addr_to_str, /* addr_to_str */ + ib_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t usb_address = { - AT_USB, /* addr_type */ - "AT_USB", /* name */ - "USB Address", /* pretty_name */ - usb_addr_to_str, /* addr_to_str */ - usb_addr_str_len /* addr_str_len */ + AT_USB, /* addr_type */ + "AT_USB", /* name */ + "USB Address", /* pretty_name */ + usb_addr_to_str, /* addr_to_str */ + usb_addr_str_len, /* addr_str_len */ + NULL /* addr_col_filter */ }; static address_type_t ax25_address = { - AT_AX25, /* addr_type */ - "AT_AX25", /* name */ - "AX.25 Address", /* pretty_name */ - ax25_addr_to_str, /* addr_to_str */ - ax25_addr_str_len /* addr_str_len */ + AT_AX25, /* addr_type */ + "AT_AX25", /* name */ + "AX.25 Address", /* pretty_name */ + ax25_addr_to_str, /* addr_to_str */ + ax25_addr_str_len,/* addr_str_len */ + ax25_col_filter_str /* addr_col_filter */ }; num_dissector_addr_type = 0; @@ -636,15 +599,12 @@ void address_types_initialize(void) address_type_register(AT_IPv4, &ipv4_address ); address_type_register(AT_IPv6, &ipv6_address ); address_type_register(AT_IPX, &ipx_address ); - address_type_register(AT_ATALK, &atalk_address ); address_type_register(AT_VINES, &vines_address ); - address_type_register(AT_ARCNET, &arcnet_address ); address_type_register(AT_FC, &fc_address ); address_type_register(AT_FCWWN, &fcwwn_address ); address_type_register(AT_SS7PC, &ss7pc_address ); address_type_register(AT_STRINGZ, &stringz_address ); address_type_register(AT_EUI64, &eui64_address ); - address_type_register(AT_URI, &uri_address ); address_type_register(AT_IB, &ib_address ); address_type_register(AT_USB, &usb_address ); address_type_register(AT_AX25, &ax25_address ); @@ -659,19 +619,19 @@ void address_types_initialize(void) /* XXX - Temporary? Here at least until all of the address type handling is finalized */ int address_type_get_length(const address* addr) { - address_type_t *at; + address_type_t *at; ADDR_TYPE_LOOKUP(addr->type, at); if ((at == NULL) || (at->addr_str_len == NULL)) return 0; - return at->addr_str_len(addr); + return at->addr_str_len(addr); } void address_type_to_string(const address* addr, gchar *buf, int buf_len) { - address_type_t *at; + address_type_t *at; if (!buf || !buf_len) return; @@ -684,7 +644,21 @@ void address_type_to_string(const address* addr, gchar *buf, int buf_len) return; } - at->addr_to_str(addr, buf, buf_len); + at->addr_to_str(addr, buf, buf_len); +} + +const char* address_type_column_filter_string(const address* addr, gboolean src) +{ + address_type_t *at; + + ADDR_TYPE_LOOKUP(addr->type, at); + + if ((at == NULL) || (at->addr_col_filter == NULL)) + { + return ""; + } + + return at->addr_col_filter(addr, src); } diff --git a/epan/address_types.h b/epan/address_types.h index 195f7dd89e..1146b493f3 100644 --- a/epan/address_types.h +++ b/epan/address_types.h @@ -30,14 +30,14 @@ extern "C" { typedef gboolean (*AddrValueToString)(const address* addr, gchar *buf, int buf_len); typedef int (*AddrValueToStringLen)(const address* addr); +typedef const char* (*AddrColFilterString)(const address* addr, gboolean src); struct _address_type_t; typedef struct _address_type_t address_type_t; -void address_type_register(int address_type, address_type_t *at); - int address_type_dissector_register(const char* name, const char* pretty_name, - AddrValueToString to_str_func, AddrValueToStringLen str_len_func); + AddrValueToString to_str_func, AddrValueToStringLen str_len_func, + AddrColFilterString col_filter_str_func); void address_types_initialize(void); @@ -46,6 +46,7 @@ void address_types_initialize(void); */ int address_type_get_length(const address* addr); void address_type_to_string(const address* addr, gchar *buf, int buf_len); +const char* address_type_column_filter_string(const address* addr, gboolean src); #ifdef __cplusplus diff --git a/epan/column-utils.c b/epan/column-utils.c index 018cdf5efb..06e8fbee23 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -31,6 +31,7 @@ #include "packet_info.h" #include "wsutil/pint.h" #include "addr_resolv.h" +#include "address_types.h" #include "ipv6-utils.h" #include "osi-utils.h" #include "value_string.h" @@ -1850,66 +1851,10 @@ col_set_addr(packet_info *pinfo, const int col, const address *addr, const gbool if (!fill_col_exprs) return; - switch (addr->type) { - case AT_AX25: - if (is_src) - pinfo->cinfo->col_expr.col_expr[col] = "ax25.src"; - else - pinfo->cinfo->col_expr.col_expr[col] = "ax25.dst"; + pinfo->cinfo->col_expr.col_expr[col] = address_type_column_filter_string(addr, is_src); + /* For address types that have a filter, create a string */ + if (strlen(pinfo->cinfo->col_expr.col_expr[col]) > 0) address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN); - break; - - case AT_ETHER: - if (is_src) - pinfo->cinfo->col_expr.col_expr[col] = "eth.src"; - else - pinfo->cinfo->col_expr.col_expr[col] = "eth.dst"; - address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN); - break; - - case AT_IPv4: - if (is_src) - pinfo->cinfo->col_expr.col_expr[col] = "ip.src"; - else - pinfo->cinfo->col_expr.col_expr[col] = "ip.dst"; - ip_to_str_buf((const guint8 *)addr->data, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN); - break; - - case AT_IPv6: - if (is_src) - pinfo->cinfo->col_expr.col_expr[col] = "ipv6.src"; - else - pinfo->cinfo->col_expr.col_expr[col] = "ipv6.dst"; - address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN); - break; - - case AT_ATALK: - if (is_src) - pinfo->cinfo->col_expr.col_expr[col] = "ddp.src"; - else - pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst"; - g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN); - break; - - case AT_ARCNET: - if (is_src) - pinfo->cinfo->col_expr.col_expr[col] = "arcnet.src"; - else - pinfo->cinfo->col_expr.col_expr[col] = "arcnet.dst"; - g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN); - break; - - case AT_URI: - if (is_src) - pinfo->cinfo->col_expr.col_expr[col] = "uri.src"; - else - pinfo->cinfo->col_expr.col_expr[col] = "uri.dst"; - address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN); - break; - - default: - break; - } /* Some addresses (e.g. ieee80211) use a standard format like AT_ETHER but * don't use the same hf_ value (and thus don't use the same filter string). @@ -1917,6 +1862,7 @@ col_set_addr(packet_info *pinfo, const int col, const address *addr, const gbool * value they use. If they did so, we overwrite the default filter string * with their specific one here. See bug #7728 for further discussion. * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7728 */ + /* XXX - can the new address types fix this and prevent the need for this logic? */ if (addr->hf != -1) { pinfo->cinfo->col_expr.col_expr[col] = proto_registrar_get_nth(addr->hf)->abbrev; } diff --git a/epan/dissectors/packet-arcnet.c b/epan/dissectors/packet-arcnet.c index 522f6621cd..a7a1b4e457 100644 --- a/epan/dissectors/packet-arcnet.c +++ b/epan/dissectors/packet-arcnet.c @@ -26,7 +26,9 @@ #include #include #include "packet-arcnet.h" +#include #include +#include #include "packet-ip.h" void proto_register_arcnet(void); @@ -46,9 +48,34 @@ static int hf_arcnet_padding = -1; /* Initialize the subtree pointers */ static gint ett_arcnet = -1; +static int arcnet_address_type = -1; + static dissector_table_t arcnet_dissector_table; static dissector_handle_t data_handle; +static gboolean arcnet_to_str(const address* addr, gchar *buf, int buf_len _U_) +{ + *buf++ = '0'; + *buf++ = 'x'; + buf = bytes_to_hexstr(buf, (const guint8 *)addr->data, 1); + *buf = '\0'; /* NULL terminate */ + + return TRUE; +} + +static int arcnet_str_len(const address* addr _U_) +{ + return 5; +} + +static const char* arcnet_col_filter_str(const address* addr _U_, gboolean is_src) +{ + if (is_src) + return "arcnet.src"; + + return "arcnet.dst"; +} + void capture_arcnet (const guchar *pd, int len, packet_counts *ld, gboolean has_offset, gboolean has_exception) @@ -143,10 +170,10 @@ dissect_arcnet_common (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, src = tvb_get_guint8 (tvb, 0); dst = tvb_get_guint8 (tvb, 1); - TVB_SET_ADDRESS(&pinfo->dl_src, AT_ARCNET, tvb, 0, 1); - TVB_SET_ADDRESS(&pinfo->src, AT_ARCNET, tvb, 0, 1); - TVB_SET_ADDRESS(&pinfo->dl_dst, AT_ARCNET, tvb, 1, 1); - TVB_SET_ADDRESS(&pinfo->dst, AT_ARCNET, tvb, 1, 1); + TVB_SET_ADDRESS(&pinfo->dl_src, arcnet_address_type, tvb, 0, 1); + TVB_SET_ADDRESS(&pinfo->src, arcnet_address_type, tvb, 0, 1); + TVB_SET_ADDRESS(&pinfo->dl_dst, arcnet_address_type, tvb, 1, 1); + TVB_SET_ADDRESS(&pinfo->dst, arcnet_address_type, tvb, 1, 1); ti = proto_tree_add_item (tree, proto_arcnet, tvb, 0, -1, ENC_NA); @@ -352,6 +379,8 @@ proto_register_arcnet (void) /* Required function calls to register the header fields and subtrees used */ proto_register_field_array (proto_arcnet, hf, array_length (hf)); proto_register_subtree_array (ett, array_length (ett)); + + arcnet_address_type = address_type_dissector_register("AT_ARCNET", "ARCNET Address", arcnet_to_str, arcnet_str_len, arcnet_col_filter_str); } diff --git a/epan/dissectors/packet-atalk.c b/epan/dissectors/packet-atalk.c index a105738d92..9e1ca4cf70 100644 --- a/epan/dissectors/packet-atalk.c +++ b/epan/dissectors/packet-atalk.c @@ -34,7 +34,9 @@ #include #include #include +#include #include +#include #include #include "packet-atalk.h" #include "packet-afp.h" @@ -341,6 +343,8 @@ static int hf_pap_eof = -1; static int hf_pap_pad = -1; +static int atalk_address_type = -1; + static const value_string pap_function_vals[] = { {PAPOpenConn , "Open Connection Query"}, {PAPOpenConnReply , "Open Connection Reply"}, @@ -1164,6 +1168,42 @@ dissect_asp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) /* ----------------------------- ZIP protocol cf. inside appletalk chap. 8 */ +/* + * Structure used to represent a DDP address; gives the layout of the + * data pointed to by an Appletalk "address" structure. + */ +struct atalk_ddp_addr { + guint16 net; + guint8 node; +}; + +static gboolean atalk_to_str(const address* addr, gchar *buf, int buf_len _U_) +{ + struct atalk_ddp_addr atalk; + memcpy(&atalk, addr->data, sizeof atalk); + + buf = word_to_hex(buf, atalk.net); + *buf++ = '.'; + buf = bytes_to_hexstr(buf, &atalk.node, 1); + *buf++ = '\0'; /* NULL terminate */ + + return TRUE; +} + +static int atalk_str_len(const address* addr _U_) +{ + return 14; +} + +const char* atalk_col_filter_str(const address* addr _U_, gboolean is_src) +{ + if (is_src) + return "ddp.src"; + + return "ddp.dst"; +} + + static int dissect_atp_zip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) { @@ -1404,10 +1444,10 @@ dissect_ddp_short(tvbuff_t *tvb, packet_info *pinfo, guint8 dnode, src->node = snode; dst->net = 0; dst->node = dnode; - SET_ADDRESS(&pinfo->net_src, AT_ATALK, sizeof(struct atalk_ddp_addr), src); - SET_ADDRESS(&pinfo->src, AT_ATALK, sizeof(struct atalk_ddp_addr), src); - SET_ADDRESS(&pinfo->net_dst, AT_ATALK, sizeof(struct atalk_ddp_addr), dst); - SET_ADDRESS(&pinfo->dst, AT_ATALK, sizeof(struct atalk_ddp_addr), dst); + SET_ADDRESS(&pinfo->net_src, atalk_address_type, sizeof(struct atalk_ddp_addr), src); + SET_ADDRESS(&pinfo->src, atalk_address_type, sizeof(struct atalk_ddp_addr), src); + SET_ADDRESS(&pinfo->net_dst, atalk_address_type, sizeof(struct atalk_ddp_addr), dst); + SET_ADDRESS(&pinfo->dst, atalk_address_type, sizeof(struct atalk_ddp_addr), dst); pinfo->ptype = PT_DDP; pinfo->destport = dport; @@ -1418,10 +1458,10 @@ dissect_ddp_short(tvbuff_t *tvb, packet_info *pinfo, guint8 dnode, if (tree) { hidden_item = proto_tree_add_string(ddp_tree, hf_ddp_src, tvb, - 4, 3, atalk_addr_to_str(src)); + 4, 3, address_to_str(wmem_packet_scope(), &pinfo->src)); PROTO_ITEM_SET_HIDDEN(hidden_item); hidden_item = proto_tree_add_string(ddp_tree, hf_ddp_dst, tvb, - 6, 3, atalk_addr_to_str(dst)); + 6, 3, address_to_str(wmem_packet_scope(), &pinfo->dst)); PROTO_ITEM_SET_HIDDEN(hidden_item); proto_tree_add_uint(ddp_tree, hf_ddp_type, tvb, 4, 1, type); @@ -1455,10 +1495,10 @@ dissect_ddp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) src->node = ddp.snode; dst->net = ddp.dnet; dst->node = ddp.dnode; - SET_ADDRESS(&pinfo->net_src, AT_ATALK, sizeof(struct atalk_ddp_addr), src); - SET_ADDRESS(&pinfo->src, AT_ATALK, sizeof(struct atalk_ddp_addr), src); - SET_ADDRESS(&pinfo->net_dst, AT_ATALK, sizeof(struct atalk_ddp_addr), dst); - SET_ADDRESS(&pinfo->dst, AT_ATALK, sizeof(struct atalk_ddp_addr), dst); + SET_ADDRESS(&pinfo->net_src, atalk_address_type, sizeof(struct atalk_ddp_addr), src); + SET_ADDRESS(&pinfo->src, atalk_address_type, sizeof(struct atalk_ddp_addr), src); + SET_ADDRESS(&pinfo->net_dst, atalk_address_type, sizeof(struct atalk_ddp_addr), dst); + SET_ADDRESS(&pinfo->dst, atalk_address_type, sizeof(struct atalk_ddp_addr), dst); pinfo->ptype = PT_DDP; pinfo->destport = ddp.dport; @@ -1473,11 +1513,11 @@ dissect_ddp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ddp_tree = proto_item_add_subtree(ti, ett_ddp); hidden_item = proto_tree_add_string(ddp_tree, hf_ddp_src, tvb, - 4, 3, atalk_addr_to_str(src)); + 4, 3, address_to_str(wmem_packet_scope(), &pinfo->src)); PROTO_ITEM_SET_HIDDEN(hidden_item); hidden_item = proto_tree_add_string(ddp_tree, hf_ddp_dst, tvb, - 6, 3, atalk_addr_to_str(dst)); + 6, 3, address_to_str(wmem_packet_scope(), &pinfo->dst)); PROTO_ITEM_SET_HIDDEN(hidden_item); proto_tree_add_uint(ddp_tree, hf_ddp_hopcount, tvb, 0, 1, @@ -2022,6 +2062,8 @@ proto_register_atalk(void) /* subdissector code */ ddp_dissector_table = register_dissector_table("ddp.type", "DDP packet type", FT_UINT8, BASE_HEX); + + atalk_address_type = address_type_dissector_register("AT_ATALK", "Appletalk DDP", atalk_to_str, atalk_str_len, atalk_col_filter_str); } void diff --git a/epan/dissectors/packet-devicenet.c b/epan/dissectors/packet-devicenet.c index ff39e108bd..58e7229565 100644 --- a/epan/dissectors/packet-devicenet.c +++ b/epan/dissectors/packet-devicenet.c @@ -1022,7 +1022,7 @@ void proto_register_devicenet(void) new_register_dissector("devicenet", dissect_devicenet, proto_devicenet); - devicenet_address_type = address_type_dissector_register("AT_DEVICENET", "DeviceNet Address", devicenet_addr_to_str, devicenet_addr_str_len); + devicenet_address_type = address_type_dissector_register("AT_DEVICENET", "DeviceNet Address", devicenet_addr_to_str, devicenet_addr_str_len, NULL); devicenet_module = prefs_register_protocol(proto_devicenet, NULL); diff --git a/epan/dissectors/packet-ieee802154.c b/epan/dissectors/packet-ieee802154.c index b0ab5dec41..ff37f1aa36 100644 --- a/epan/dissectors/packet-ieee802154.c +++ b/epan/dissectors/packet-ieee802154.c @@ -2783,7 +2783,8 @@ void proto_register_ieee802154(void) expert_ieee802154 = expert_register_protocol(proto_ieee802154); expert_register_field_array(expert_ieee802154, ei, array_length(ei)); - ieee802_15_4_short_address_type = address_type_dissector_register("AT_IEEE_802_15_4_SHORT", "IEEE 802.15.4 16-bit short address", ieee802_15_4_short_address_to_str, ieee802_15_4_short_address_str_len); + ieee802_15_4_short_address_type = address_type_dissector_register("AT_IEEE_802_15_4_SHORT", "IEEE 802.15.4 16-bit short address", + ieee802_15_4_short_address_to_str, ieee802_15_4_short_address_str_len, NULL); /* add a user preference to set the 802.15.4 ethertype */ ieee802154_module = prefs_register_protocol(proto_ieee802154, diff --git a/epan/dissectors/packet-j1939.c b/epan/dissectors/packet-j1939.c index 675430afa9..94f9b3d981 100644 --- a/epan/dissectors/packet-j1939.c +++ b/epan/dissectors/packet-j1939.c @@ -337,7 +337,7 @@ void proto_register_j1939(void) subdissector_pgn_table = register_dissector_table("j1939.pgn", "PGN Handle", FT_UINT32, BASE_DEC); - j1939_address_type = address_type_dissector_register("AT_J1939", "J1939 Address", J1939_addr_to_str, J1939_addr_str_len); + j1939_address_type = address_type_dissector_register("AT_J1939", "J1939 Address", J1939_addr_to_str, J1939_addr_str_len, NULL); } /* diff --git a/epan/dissectors/packet-jxta.c b/epan/dissectors/packet-jxta.c index 682f9517c4..13c4cc442d 100644 --- a/epan/dissectors/packet-jxta.c +++ b/epan/dissectors/packet-jxta.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include "packet-jxta.h" @@ -161,6 +162,8 @@ static gint *const ett[] = { &ett_jxta_elem_2_flags }; +static int uri_address_type = -1; + /** * global preferences **/ @@ -191,13 +194,13 @@ typedef struct jxta_stream_conversation_data jxta_stream_conversation_data; static const char* jxta_conv_get_filter_type(conv_item_t* conv, conv_filter_type_e filter) { - if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == AT_URI)) + if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == uri_address_type)) return "jxta.message.src"; - if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == AT_URI)) + if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == uri_address_type)) return "jxta.message.dst"; - if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == AT_URI)) + if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == uri_address_type)) return "jxta.message.address"; return CONV_FILTER_INVALID; @@ -219,7 +222,7 @@ jxta_conversation_packet(void *pct, packet_info *pinfo _U_, epan_dissect_t *edt static const char* jxta_host_get_filter_type(hostlist_talker_t* host, conv_filter_type_e filter) { - if ((filter == CONV_FT_ANY_ADDRESS) && (host->myaddress.type == AT_URI)) + if ((filter == CONV_FT_ANY_ADDRESS) && (host->myaddress.type == uri_address_type)) return "jxta.message.address"; return CONV_FILTER_INVALID; @@ -241,6 +244,27 @@ jxta_hostlist_packet(void *pit, packet_info *pinfo _U_, epan_dissect_t *edt _U_, return 1; } +static gboolean uri_to_str(const address* addr, gchar *buf, int buf_len) +{ + int copy_len = addr->len < (buf_len - 1) ? addr->len : (buf_len - 1); + memcpy(buf, addr->data, copy_len ); + buf[copy_len] = '\0'; + return TRUE; +} + +static int uri_str_len(const address* addr) +{ + return addr->len+1; +} + +static const char* uri_col_filter_str(const address* addr _U_, gboolean is_src) +{ + if (is_src) + return "uri.src"; + + return "uri.dst"; +} + /** * Prototypes **/ @@ -907,7 +931,7 @@ static int dissect_jxta_welcome(tvbuff_t * tvb, packet_info * pinfo, proto_tree col_append_str(pinfo->cinfo, COL_INFO, *current_token); if (NULL != found_addr) { - found_addr->type = AT_URI; + found_addr->type = uri_address_type; found_addr->len = (int) strlen(*current_token); found_addr->data = wmem_strdup(wmem_file_scope(), *current_token); } @@ -1308,7 +1332,7 @@ static int dissect_jxta_message(tvbuff_t * tvb, packet_info * pinfo, proto_tree } } - if ((AT_URI == pinfo->src.type) && (AT_URI == pinfo->dst.type)) { + if ((uri_address_type == pinfo->src.type) && (uri_address_type == pinfo->dst.type)) { jxta_tap_header *tap_header = wmem_new(wmem_file_scope(), jxta_tap_header); tap_header->src_address = pinfo->src; @@ -1380,7 +1404,7 @@ static int dissect_jxta_message(tvbuff_t * tvb, packet_info * pinfo, proto_tree PROTO_ITEM_SET_HIDDEN(tree_item); PROTO_ITEM_SET_GENERATED(tree_item); - if(AT_URI == pinfo->src.type) { + if(uri_address_type == pinfo->src.type) { tree_item = proto_tree_add_string(jxta_msg_tree, hf_uri_src, tvb, 0, 0, wmem_strbuf_get_str(src_addr)); PROTO_ITEM_SET_HIDDEN(tree_item); PROTO_ITEM_SET_GENERATED(tree_item); @@ -1396,7 +1420,7 @@ static int dissect_jxta_message(tvbuff_t * tvb, packet_info * pinfo, proto_tree PROTO_ITEM_SET_HIDDEN(tree_item); PROTO_ITEM_SET_GENERATED(tree_item); - if(AT_URI == pinfo->dst.type) { + if(uri_address_type == pinfo->dst.type) { tree_item = proto_tree_add_string(jxta_msg_tree, hf_uri_dst, tvb, 0, 0, wmem_strbuf_get_str(dst_addr)); PROTO_ITEM_SET_HIDDEN(tree_item); PROTO_ITEM_SET_GENERATED(tree_item); @@ -2344,6 +2368,8 @@ void proto_register_jxta(void) /* Register JXTA Sub-tree */ proto_register_subtree_array(ett, array_length(ett)); + uri_address_type = address_type_dissector_register("AT_URI", "URI/URL/URN", uri_to_str, uri_str_len, uri_col_filter_str); + /* Register preferences */ /* register re-init routine */ jxta_module = prefs_register_protocol(proto_jxta, proto_reg_handoff_jxta); diff --git a/epan/dissectors/packet-mstp.c b/epan/dissectors/packet-mstp.c index ba2a830c9e..a4d6d43b7a 100644 --- a/epan/dissectors/packet-mstp.c +++ b/epan/dissectors/packet-mstp.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include "packet-mstp.h" void proto_register_mstp(void); @@ -91,6 +93,7 @@ static int hf_mstp_frame_checksum_good = -1; static expert_field ei_mstp_frame_pdu_len = EI_INIT; static expert_field ei_mstp_frame_checksum_bad = EI_INIT; +static int mstp_address_type = -1; #if defined(BACNET_MSTP_CHECKSUM_VALIDATE) /* Accumulate "dataValue" into the CRC in crcValue. */ @@ -146,6 +149,29 @@ mstp_frame_type_text(guint32 val) "Unknown Frame Type (%u)"); } +static gboolean mstp_to_str(const address* addr, gchar *buf, int buf_len _U_) +{ + *buf++ = '0'; + *buf++ = 'x'; + buf = bytes_to_hexstr(buf, (const guint8 *)addr->data, 1); + *buf = '\0'; /* NULL terminate */ + + return TRUE; +} + +static int mstp_str_len(const address* addr _U_) +{ + return 5; +} + +static const char* mstp_col_filter_str(const address* addr _U_, gboolean is_src) +{ + if (is_src) + return "mstp.src"; + + return "mstp.dst"; +} + /* dissects a BACnet MS/TP frame */ /* preamble 0x55 0xFF is not included in Cimetrics U+4 output */ void @@ -323,11 +349,10 @@ dissect_mstp_wtap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) #endif /* set the MS/TP MAC address in the source/destination */ - /* Use AT_ARCNET since it is similar to BACnet MS/TP */ - TVB_SET_ADDRESS(&pinfo->dl_dst, AT_ARCNET, tvb, offset+3, 1); - TVB_SET_ADDRESS(&pinfo->dst, AT_ARCNET, tvb, offset+3, 1); - TVB_SET_ADDRESS(&pinfo->dl_src, AT_ARCNET, tvb, offset+4, 1); - TVB_SET_ADDRESS(&pinfo->src, AT_ARCNET, tvb, offset+4, 1); + TVB_SET_ADDRESS(&pinfo->dl_dst, mstp_address_type, tvb, offset+3, 1); + TVB_SET_ADDRESS(&pinfo->dst, mstp_address_type, tvb, offset+3, 1); + TVB_SET_ADDRESS(&pinfo->dl_src, mstp_address_type, tvb, offset+4, 1); + TVB_SET_ADDRESS(&pinfo->src, mstp_address_type, tvb, offset+4, 1); #ifdef BACNET_MSTP_SUMMARY_IN_TREE mstp_frame_type = tvb_get_guint8(tvb, offset+2); @@ -434,6 +459,8 @@ proto_register_mstp(void) subdissector_table = register_dissector_table("mstp.vendor_frame_type", "MSTP Vendor specific Frametypes", FT_UINT24, BASE_DEC); /* Table_type: (Vendor ID << 16) + Frametype */ + + mstp_address_type = address_type_dissector_register("AT_MSTP", "BACnet MS/TP Address", mstp_to_str, mstp_str_len, mstp_col_filter_str); } void diff --git a/epan/dissectors/packet-sna.c b/epan/dissectors/packet-sna.c index 942a350e55..be78e0e404 100644 --- a/epan/dissectors/packet-sna.c +++ b/epan/dissectors/packet-sna.c @@ -3481,7 +3481,7 @@ proto_register_sna(void) "Systems Network Architecture XID", "SNA XID", "sna_xid"); register_dissector("sna_xid", dissect_sna_xid, proto_sna_xid); - sna_address_type = address_type_dissector_register("AT_SNA", "SNA Address", sna_fid_to_str_buf, sna_address_str_len); + sna_address_type = address_type_dissector_register("AT_SNA", "SNA Address", sna_fid_to_str_buf, sna_address_str_len, NULL); /* Register configuration options */ sna_module = prefs_register_protocol(proto_sna, NULL); diff --git a/epan/dissectors/packet-tipc.c b/epan/dissectors/packet-tipc.c index 034c6c9a0c..5086e82c48 100644 --- a/epan/dissectors/packet-tipc.c +++ b/epan/dissectors/packet-tipc.c @@ -2961,7 +2961,8 @@ proto_register_tipc(void) /* Register configuration options */ tipc_module = prefs_register_protocol(proto_tipc, proto_reg_handoff_tipc); - tipc_address_type = address_type_dissector_register("tipc_address_type", "TIPC Address Zone,Subnetwork,Processor", tipc_addr_to_str_buf, tipc_addr_str_len); + tipc_address_type = address_type_dissector_register("tipc_address_type", "TIPC Address Zone,Subnetwork,Processor", + tipc_addr_to_str_buf, tipc_addr_str_len, NULL); /* Set default ports */ range_convert_str(&global_tipc_udp_port_range, DEFAULT_TIPC_PORT_RANGE, MAX_TCP_PORT); diff --git a/epan/osi-utils.c b/epan/osi-utils.c index 9ce10b1159..48691ecf79 100644 --- a/epan/osi-utils.c +++ b/epan/osi-utils.c @@ -241,7 +241,7 @@ void register_osi_address_type(void) if (osi_address_type != -1) return; - osi_address_type = address_type_dissector_register("AT_OSI", "OSI Address", osi_address_to_str, osi_address_str_len); + osi_address_type = address_type_dissector_register("AT_OSI", "OSI Address", osi_address_to_str, osi_address_str_len, NULL); } diff --git a/epan/to_str.h b/epan/to_str.h index b7056c5752..56570e87fd 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -95,20 +95,6 @@ WS_DLL_PUBLIC char *decode_bitfield_value(char *buf, const guint64 val, const gu WS_DLL_PUBLIC const gchar* port_type_to_str (port_type type); -/* - * Routines to take a DDP address and generate a string. - */ -/* - * Structure used to represent a DDP address; gives the layout of the - * data pointed to by an AT_ATALK "address" structure. - */ -struct atalk_ddp_addr { - guint16 net; - guint8 node; -}; - -extern gchar *atalk_addr_to_str(const struct atalk_ddp_addr *addrp); - /** Turn an address type retrieved from a tvb into a string. * * @param scope memory allocation scheme used