forked from osmocom/wireshark
Add address_to_bytes API.
This will copy an address's "byte format" into a buffer. The original intended design is for export_pdu functionality, which tries to do this "manually" for many address types (and creates undesired dependencies) The default functionality if a "byte format function" isn't provided (currently the case for all address types) is a memcpy of the address data. Providing "address to byte" functions to aid export PDU functionality will be provided later. Change-Id: I3703f9e617a8cef09165ad53a0f98c6372676b9b Reviewed-on: https://code.wireshark.org/review/16070 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
c664f72f36
commit
0bf1cb2342
|
@ -43,6 +43,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
|
|||
add_itu_tcap_subdissector@Base 1.9.1
|
||||
add_new_data_source@Base 1.9.1
|
||||
add_srt_table_data@Base 1.99.8
|
||||
address_to_bytes@Base 2.1.1
|
||||
address_to_display@Base 1.99.2
|
||||
address_to_name@Base 2.1.0
|
||||
address_to_str@Base 1.12.0~rc1
|
||||
|
|
|
@ -352,6 +352,8 @@ add_address_to_hash64(guint64 hash_val, const address *addr) {
|
|||
return hash_val;
|
||||
}
|
||||
|
||||
WS_DLL_PUBLIC guint address_to_bytes(const address *addr, guint8 *buf, guint buf_len);
|
||||
|
||||
/* Types of port numbers Wireshark knows about. */
|
||||
typedef enum {
|
||||
PT_NONE, /* no port number */
|
||||
|
|
|
@ -37,6 +37,7 @@ struct _address_type_t {
|
|||
const char *pretty_name;
|
||||
AddrValueToString addr_to_str;
|
||||
AddrValueToStringLen addr_str_len;
|
||||
AddrValueToByte addr_to_byte;
|
||||
AddrColFilterString addr_col_filter;
|
||||
AddrFixedLen addr_fixed_len;
|
||||
AddrNameResolutionToString addr_name_res_str;
|
||||
|
@ -84,7 +85,7 @@ static void address_type_register(int addr_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,
|
||||
AddrColFilterString col_filter_str_func, AddrFixedLen fixed_len_func,
|
||||
AddrValueToByte to_bytes_func, AddrColFilterString col_filter_str_func, AddrFixedLen fixed_len_func,
|
||||
AddrNameResolutionToString name_res_str_func, AddrNameResolutionLen name_res_len_func)
|
||||
{
|
||||
int addr_type;
|
||||
|
@ -107,6 +108,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_to_byte = to_bytes_func;
|
||||
dissector_type_addresses[num_dissector_addr_type].addr_col_filter = col_filter_str_func;
|
||||
dissector_type_addresses[num_dissector_addr_type].addr_fixed_len = fixed_len_func;
|
||||
dissector_type_addresses[num_dissector_addr_type].addr_name_res_str = name_res_str_func;
|
||||
|
@ -134,7 +136,6 @@ int address_type_get_by_name(const char* name)
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* AT_NONE
|
||||
******************************************************************************/
|
||||
|
@ -512,6 +513,7 @@ void address_types_initialize(void)
|
|||
"No address", /* pretty_name */
|
||||
none_addr_to_str, /* addr_to_str */
|
||||
none_addr_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
NULL, /* addr_col_filter */
|
||||
none_addr_len, /* addr_fixed_len */
|
||||
none_name_res_str, /* addr_name_res_str */
|
||||
|
@ -524,6 +526,7 @@ void address_types_initialize(void)
|
|||
"Ethernet address", /* pretty_name */
|
||||
ether_to_str, /* addr_to_str */
|
||||
ether_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
ether_col_filter_str, /* addr_col_filter */
|
||||
ether_len, /* addr_fixed_len */
|
||||
ether_name_resolution_str, /* addr_name_res_str */
|
||||
|
@ -536,6 +539,7 @@ void address_types_initialize(void)
|
|||
"IPv4 address", /* pretty_name */
|
||||
ipv4_to_str, /* addr_to_str */
|
||||
ipv4_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
ipv4_col_filter_str, /* addr_col_filter */
|
||||
ipv4_len, /* addr_fixed_len */
|
||||
ipv4_name_res_str, /* addr_name_res_str */
|
||||
|
@ -548,6 +552,7 @@ void address_types_initialize(void)
|
|||
"IPv6 address", /* pretty_name */
|
||||
ipv6_to_str, /* addr_to_str */
|
||||
ipv6_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
ipv6_col_filter_str, /* addr_col_filter */
|
||||
ipv6_len, /* addr_fixed_len */
|
||||
ipv6_name_res_str, /* addr_name_res_str */
|
||||
|
@ -560,6 +565,7 @@ void address_types_initialize(void)
|
|||
"IPX address", /* pretty_name */
|
||||
ipx_to_str, /* addr_to_str */
|
||||
ipx_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
NULL, /* addr_col_filter */
|
||||
ipx_len, /* addr_fixed_len */
|
||||
NULL, /* addr_name_res_str */
|
||||
|
@ -572,6 +578,7 @@ void address_types_initialize(void)
|
|||
"FC address", /* pretty_name */
|
||||
fc_to_str, /* addr_to_str */
|
||||
fc_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
NULL, /* addr_col_filter */
|
||||
fc_len, /* addr_fixed_len */
|
||||
NULL, /* addr_name_res_str */
|
||||
|
@ -584,6 +591,7 @@ void address_types_initialize(void)
|
|||
"Fibre Channel WWN", /* pretty_name */
|
||||
fcwwn_to_str, /* addr_to_str */
|
||||
fcwwn_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
NULL, /* addr_col_filter */
|
||||
fcwwn_len, /* addr_fixed_len */
|
||||
fcwwn_name_res_str, /* addr_name_res_str */
|
||||
|
@ -596,6 +604,7 @@ void address_types_initialize(void)
|
|||
"String address", /* pretty_name */
|
||||
stringz_addr_to_str, /* addr_to_str */
|
||||
stringz_addr_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
NULL, /* addr_col_filter */
|
||||
NULL, /* addr_fixed_len */
|
||||
NULL, /* addr_name_res_str */
|
||||
|
@ -608,6 +617,7 @@ void address_types_initialize(void)
|
|||
"IEEE EUI-64", /* pretty_name */
|
||||
eui64_addr_to_str, /* addr_to_str */
|
||||
eui64_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
NULL, /* addr_col_filter */
|
||||
eui64_len, /* addr_fixed_len */
|
||||
NULL, /* addr_name_res_str */
|
||||
|
@ -620,6 +630,7 @@ void address_types_initialize(void)
|
|||
"Infiniband GID/LID", /* pretty_name */
|
||||
ib_addr_to_str, /* addr_to_str */
|
||||
ib_str_len, /* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
NULL, /* addr_col_filter */
|
||||
NULL, /* addr_fixed_len */
|
||||
NULL, /* addr_name_res_str */
|
||||
|
@ -632,6 +643,7 @@ void address_types_initialize(void)
|
|||
"AX.25 Address", /* pretty_name */
|
||||
ax25_addr_to_str, /* addr_to_str */
|
||||
ax25_addr_str_len,/* addr_str_len */
|
||||
NULL, /* addr_to_byte */
|
||||
ax25_col_filter_str, /* addr_col_filter */
|
||||
ax25_len, /* addr_fixed_len */
|
||||
NULL, /* addr_name_res_str */
|
||||
|
@ -707,6 +719,34 @@ void address_to_str_buf(const address* addr, gchar *buf, int buf_len)
|
|||
at->addr_to_str(addr, buf, buf_len);
|
||||
}
|
||||
|
||||
|
||||
guint address_to_bytes(const address *addr, guint8 *buf, guint buf_len)
|
||||
{
|
||||
address_type_t *at;
|
||||
guint copy_len = 0;
|
||||
|
||||
if (!buf || !buf_len)
|
||||
return 0;
|
||||
|
||||
ADDR_TYPE_LOOKUP(addr->type, at);
|
||||
|
||||
if (at == NULL)
|
||||
return 0;
|
||||
|
||||
if (at->addr_to_byte == NULL)
|
||||
{
|
||||
/* If a specific function isn't provided, just do a memcpy */
|
||||
copy_len = MIN(((guint)addr->len), buf_len);
|
||||
memcpy(buf, addr->data, copy_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
copy_len = at->addr_to_byte(addr, buf, buf_len);
|
||||
}
|
||||
|
||||
return copy_len;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
address_to_name(const address *addr)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@ extern "C" {
|
|||
|
||||
typedef int (*AddrValueToString)(const address* addr, gchar *buf, int buf_len);
|
||||
typedef int (*AddrValueToStringLen)(const address* addr);
|
||||
typedef guint (*AddrValueToByte)(const address* addr, guint8 *buf, guint buf_len);
|
||||
typedef int (*AddrFixedLen)(void);
|
||||
typedef const char* (*AddrColFilterString)(const address* addr, gboolean src);
|
||||
typedef int (*AddrNameResolutionLen)(void);
|
||||
|
@ -41,7 +42,7 @@ typedef struct _address_type_t address_type_t;
|
|||
|
||||
WS_DLL_PUBLIC int address_type_dissector_register(const char* name, const char* pretty_name,
|
||||
AddrValueToString to_str_func, AddrValueToStringLen str_len_func,
|
||||
AddrColFilterString col_filter_str_func, AddrFixedLen fixed_len_func,
|
||||
AddrValueToByte to_bytes_func, AddrColFilterString col_filter_str_func, AddrFixedLen fixed_len_func,
|
||||
AddrNameResolutionToString name_res_str_func, AddrNameResolutionLen name_res_len_func);
|
||||
|
||||
WS_DLL_PUBLIC int address_type_get_by_name(const char* name);
|
||||
|
|
|
@ -394,7 +394,7 @@ proto_register_arcnet (void)
|
|||
arcnet_dissector_table = register_dissector_table ("arcnet.protocol_id", "ARCNET Protocol ID",
|
||||
proto_arcnet, FT_UINT8, BASE_HEX, DISSECTOR_TABLE_NOT_ALLOW_DUPLICATE);
|
||||
|
||||
arcnet_address_type = address_type_dissector_register("AT_ARCNET", "ARCNET Address", arcnet_to_str, arcnet_str_len, arcnet_col_filter_str, arcnet_len, NULL, NULL);
|
||||
arcnet_address_type = address_type_dissector_register("AT_ARCNET", "ARCNET Address", arcnet_to_str, arcnet_str_len, NULL, arcnet_col_filter_str, arcnet_len, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2075,7 +2075,7 @@ proto_register_atalk(void)
|
|||
ddp_dissector_table = register_dissector_table("ddp.type", "DDP packet type", proto_ddp,
|
||||
FT_UINT8, BASE_HEX, DISSECTOR_TABLE_ALLOW_DUPLICATE);
|
||||
|
||||
atalk_address_type = address_type_dissector_register("AT_ATALK", "Appletalk DDP", atalk_to_str, atalk_str_len, atalk_col_filter_str, atalk_len, NULL, NULL);
|
||||
atalk_address_type = address_type_dissector_register("AT_ATALK", "Appletalk DDP", atalk_to_str, atalk_str_len, NULL, atalk_col_filter_str, atalk_len, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1034,7 +1034,7 @@ void proto_register_devicenet(void)
|
|||
expert_devicenet = expert_register_protocol(proto_devicenet);
|
||||
expert_register_field_array(expert_devicenet, ei, array_length(ei));
|
||||
|
||||
devicenet_address_type = address_type_dissector_register("AT_DEVICENET", "DeviceNet Address", devicenet_addr_to_str, devicenet_addr_str_len, NULL, devicenet_addr_len, NULL, NULL);
|
||||
devicenet_address_type = address_type_dissector_register("AT_DEVICENET", "DeviceNet Address", devicenet_addr_to_str, devicenet_addr_str_len, NULL, NULL, devicenet_addr_len, NULL, NULL);
|
||||
|
||||
devicenet_module = prefs_register_protocol(proto_devicenet, NULL);
|
||||
|
||||
|
|
|
@ -27407,9 +27407,9 @@ proto_register_ieee80211 (void)
|
|||
wlan_tap = register_tap("wlan");
|
||||
register_conversation_table(proto_wlan, TRUE, wlan_conversation_packet, wlan_hostlist_packet);
|
||||
|
||||
wlan_address_type = address_type_dissector_register("AT_ETHER_WLAN", "WLAN Address", ether_to_str, ether_str_len, wlan_col_filter_str,
|
||||
wlan_address_type = address_type_dissector_register("AT_ETHER_WLAN", "WLAN Address", ether_to_str, ether_str_len, NULL, wlan_col_filter_str,
|
||||
ether_len, ether_name_resolution_str, ether_name_resolution_len);
|
||||
wlan_bssid_address_type = address_type_dissector_register("AT_ETHER_BSSID", "WLAN BSSID Address", ether_to_str, ether_str_len, wlan_bssid_col_filter_str,
|
||||
wlan_bssid_address_type = address_type_dissector_register("AT_ETHER_BSSID", "WLAN BSSID Address", ether_to_str, ether_str_len, NULL, wlan_bssid_col_filter_str,
|
||||
ether_len, ether_name_resolution_str, ether_name_resolution_len);
|
||||
set_address(&bssid_broadcast, wlan_bssid_address_type, 6, bssid_broadcast_data);
|
||||
|
||||
|
|
|
@ -3551,7 +3551,7 @@ void proto_register_ieee802154(void)
|
|||
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, NULL, ieee802_15_4_short_address_len, NULL, NULL);
|
||||
ieee802_15_4_short_address_to_str, ieee802_15_4_short_address_str_len, NULL, NULL, ieee802_15_4_short_address_len, NULL, NULL);
|
||||
|
||||
/* add a user preference to set the 802.15.4 ethertype */
|
||||
ieee802154_module = prefs_register_protocol(proto_ieee802154,
|
||||
|
|
|
@ -350,7 +350,7 @@ void proto_register_j1939(void)
|
|||
|
||||
subdissector_pgn_table = register_dissector_table("j1939.pgn", "PGN Handle", proto_j1939, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
|
||||
|
||||
j1939_address_type = address_type_dissector_register("AT_J1939", "J1939 Address", J1939_addr_to_str, J1939_addr_str_len, J1939_col_filter_str, J1939_addr_len, NULL, NULL);
|
||||
j1939_address_type = address_type_dissector_register("AT_J1939", "J1939 Address", J1939_addr_to_str, J1939_addr_str_len, NULL, J1939_col_filter_str, J1939_addr_len, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -2355,7 +2355,7 @@ 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, NULL, NULL, NULL);
|
||||
uri_address_type = address_type_dissector_register("AT_URI", "URI/URL/URN", uri_to_str, uri_str_len, NULL, uri_col_filter_str, NULL, NULL, NULL);
|
||||
|
||||
/* Register preferences */
|
||||
/* register re-init routine */
|
||||
|
|
|
@ -1538,7 +1538,7 @@ proto_register_mp2t(void)
|
|||
expert_mp2t = expert_register_protocol(proto_mp2t);
|
||||
expert_register_field_array(expert_mp2t, ei, array_length(ei));
|
||||
|
||||
mp2t_no_address_type = address_type_dissector_register("AT_MP2T_NONE", "No MP2T Address", none_addr_to_str, none_addr_str_len, NULL, none_addr_len, NULL, NULL);
|
||||
mp2t_no_address_type = address_type_dissector_register("AT_MP2T_NONE", "No MP2T Address", none_addr_to_str, none_addr_str_len, NULL, NULL, none_addr_len, NULL, NULL);
|
||||
|
||||
heur_subdissector_list = register_heur_dissector_list("mp2t.pid", proto_mp2t);
|
||||
/* Register init of processing of fragmented DEPI packets */
|
||||
|
|
|
@ -465,7 +465,7 @@ proto_register_mstp(void)
|
|||
"MSTP Vendor specific Frametypes", proto_mstp, FT_UINT24, BASE_DEC, DISSECTOR_TABLE_NOT_ALLOW_DUPLICATE);
|
||||
/* 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, mstp_len, NULL, NULL);
|
||||
mstp_address_type = address_type_dissector_register("AT_MSTP", "BACnet MS/TP Address", mstp_to_str, mstp_str_len, NULL, mstp_col_filter_str, mstp_len, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1077,7 +1077,7 @@ proto_register_mtp3(void)
|
|||
"MTP3 Service indicator",
|
||||
proto_mtp3, FT_UINT8, BASE_HEX, DISSECTOR_TABLE_NOT_ALLOW_DUPLICATE);
|
||||
|
||||
mtp3_address_type = address_type_dissector_register("AT_SS7PC", "SS7 Point Code", mtp3_addr_to_str, mtp3_str_addr_len, NULL,
|
||||
mtp3_address_type = address_type_dissector_register("AT_SS7PC", "SS7 Point Code", mtp3_addr_to_str, mtp3_str_addr_len, NULL, NULL,
|
||||
mtp3_addr_len, NULL, NULL);
|
||||
|
||||
|
||||
|
|
|
@ -3468,7 +3468,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, NULL, NULL, NULL, NULL);
|
||||
sna_address_type = address_type_dissector_register("AT_SNA", "SNA Address", sna_fid_to_str_buf, sna_address_str_len, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
/* Register configuration options */
|
||||
sna_module = prefs_register_protocol(proto_sna, NULL);
|
||||
|
|
|
@ -3046,7 +3046,7 @@ proto_register_tipc(void)
|
|||
tipc_module = prefs_register_protocol(proto_tipc, proto_reg_handoff_tipc);
|
||||
|
||||
tipc_address_type = address_type_dissector_register("AT_TIPC", "TIPC Address Zone,Subnetwork,Processor",
|
||||
tipc_addr_to_str_buf, tipc_addr_str_len, NULL, NULL, NULL, NULL);
|
||||
tipc_addr_to_str_buf, tipc_addr_str_len, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
/* Set default ports */
|
||||
range_convert_str(&global_tipc_udp_port_range, DEFAULT_TIPC_PORT_RANGE, MAX_TCP_PORT);
|
||||
|
|
|
@ -5315,7 +5315,7 @@ proto_register_usb(void)
|
|||
register_decode_as(&usb_product_da);
|
||||
register_decode_as(&usb_device_da);
|
||||
|
||||
usb_address_type = address_type_dissector_register("AT_USB", "USB Address", usb_addr_to_str, usb_addr_str_len, NULL, NULL, NULL, NULL);
|
||||
usb_address_type = address_type_dissector_register("AT_USB", "USB Address", usb_addr_to_str, usb_addr_str_len, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
register_conversation_table(proto_usb, TRUE, usb_conversation_packet, usb_hostlist_packet);
|
||||
}
|
||||
|
|
|
@ -726,7 +726,7 @@ proto_register_vines_ip(void)
|
|||
vines_ip_handle = create_dissector_handle(dissect_vines_ip,
|
||||
proto_vines_ip);
|
||||
|
||||
vines_address_type = address_type_dissector_register("AT_VINES", "Banyan Vines address", vines_to_str, vines_str_len, NULL, vines_len, NULL, NULL);
|
||||
vines_address_type = address_type_dissector_register("AT_VINES", "Banyan Vines address", vines_to_str, vines_str_len, NULL, NULL, vines_len, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -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, NULL, NULL, NULL, NULL);
|
||||
osi_address_type = address_type_dissector_register("AT_OSI", "OSI Address", osi_address_to_str, osi_address_str_len, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2230,7 +2230,7 @@ void proto_register_irda(void)
|
|||
}
|
||||
proto_register_subtree_array(ett_iap_e, MAX_IAP_ENTRIES);
|
||||
|
||||
irda_address_type = address_type_dissector_register("AT_IRDA", "IRDA Address", irda_addr_to_str, irda_addr_str_len, irda_col_filter_str, irda_addr_len, NULL, NULL);
|
||||
irda_address_type = address_type_dissector_register("AT_IRDA", "IRDA Address", irda_addr_to_str, irda_addr_str_len, NULL, irda_col_filter_str, irda_addr_len, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue