Add address type registration.

Now address types are setup just like field types and must be registered with a structure that provides its string representation (and more things in the future).  Address types that are limited to a single dissector are registered by the dissector.  More "common" ones are globally registered.  There are still a few that really belong in a dissector, but have other dependencies currently not accounted for in the address type support.

Many of the "address to string" conversions that involved g_sprintf have be changed to use more "performance friendly" methods (some at the cost of needing to_str-int.h)

Leaving all comments regarding this "solution" in address_to_str.c in until all have been implemented

Change-Id: I494f413e016b22859c44675def11135f228796e0
Reviewed-on: https://code.wireshark.org/review/7019
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2015-02-07 22:15:55 -05:00
parent 3b81c360de
commit 4497bb48fd
22 changed files with 1056 additions and 447 deletions

View File

@ -121,6 +121,7 @@ which ATN standard is supported ?
#include <epan/packet.h>
#include <epan/address.h>
#include <epan/conversation.h>
#include <epan/osi-utils.h>
#include "packet-ber.h"
#include "packet-per.h"
#include "packet-atn-ulcs.h"
@ -387,8 +388,8 @@ guint32 get_aircraft_24_bit_address_from_nsap(
guint32 adr_prefix =0;
/* check NSAP address type*/
if( (pinfo->src.type != AT_OSI) ||
(pinfo->dst.type != AT_OSI)) {
if( (pinfo->src.type != get_osi_address_type()) ||
(pinfo->dst.type != get_osi_address_type())) {
return ars; }
/* 20 octets address length required */
@ -459,7 +460,7 @@ int check_heur_msg_type(packet_info *pinfo _U_)
guint32 adr_prefix =0;
/* check NSAP address type*/
if( (pinfo->src.type != AT_OSI) || (pinfo->dst.type != AT_OSI)) {
if( (pinfo->src.type != get_osi_address_type()) || (pinfo->dst.type != get_osi_address_type())) {
return t; }
/* check NSAP address length; 20 octets address length required */

View File

@ -1556,6 +1556,7 @@ set(LIBWIRESHARK_FILES
addr_and_mask.c
addr_resolv.c
address_to_str.c
address_types.c
afn.c
aftypes.c
app_mem_usage.c
@ -1612,7 +1613,6 @@ set(LIBWIRESHARK_FILES
req_resp_hdrs.c
show_exception.c
sminmpec.c
sna-utils.c
stat_tap_ui.c
stats_tree.c
strutil.c

View File

@ -25,6 +25,7 @@ LIBWIRESHARK_SRC = \
addr_and_mask.c \
addr_resolv.c \
address_to_str.c \
address_types.c \
afn.c \
aftypes.c \
app_mem_usage.c \
@ -80,7 +81,6 @@ LIBWIRESHARK_SRC = \
req_resp_hdrs.c \
show_exception.c \
sminmpec.c \
sna-utils.c \
stat_tap_ui.c \
stats_tree.c \
strutil.c \
@ -146,6 +146,7 @@ LIBWIRESHARK_INCLUDES = \
addr_and_mask.h \
addr_resolv.h \
address.h \
address_types.h \
afn.h \
aftypes.h \
app_mem_usage.h \
@ -235,7 +236,6 @@ LIBWIRESHARK_INCLUDES = \
show_exception.h \
slow_protocol_subtypes.h \
sminmpec.h \
sna-utils.h \
stat_tap_ui.h \
stat_groups.h \
stats_tree.h \

View File

@ -40,10 +40,8 @@ typedef enum {
AT_IPv4, /* IPv4 */
AT_IPv6, /* IPv6 */
AT_IPX, /* IPX */
AT_SNA, /* SNA */
AT_ATALK, /* Appletalk DDP */
AT_VINES, /* Banyan Vines */
AT_OSI, /* OSI NSAP */
AT_ARCNET, /* ARCNET */
AT_FC, /* Fibre Channel */
AT_FCWWN, /* Fibre Channel WWN */
@ -51,19 +49,16 @@ typedef enum {
AT_STRINGZ, /* null-terminated string */
AT_EUI64, /* IEEE EUI-64 */
AT_URI, /* URI/URL/URN */
AT_TIPC, /* TIPC Address Zone,Subnetwork,Processor */
AT_IB, /* Infiniband GID/LID */
AT_USB, /* USB Device address
* (0xffffffff represents the host) */
AT_AX25, /* AX.25 */
AT_IEEE_802_15_4_SHORT,/* IEEE 802.15.4 16-bit short address */
/* (the long addresses are EUI-64's */
AT_J1939, /* J1939 */
AT_DEVICENET /* DeviceNet */
AT_END_OF_LIST /* Must be last in list */
} address_type;
typedef struct _address {
address_type type; /* type of address */
int type; /* type of address */
int hf; /* the specific field that this addr is */
int len; /* length of address, in bytes */
const void *data; /* pointer to address data */
@ -78,7 +73,7 @@ typedef struct _address {
* @param addr_data [in] Pointer to the address data.
*/
static inline void
set_address(address *addr, address_type addr_type, int addr_len, const void * addr_data) {
set_address(address *addr, int addr_type, int addr_len, const void * addr_data) {
addr->data = addr_data;
addr->type = addr_type;
addr->hf = -1;

View File

@ -53,9 +53,9 @@
#include "to_str.h"
#include "value_string.h"
#include "addr_resolv.h"
#include "address_types.h"
#include "wsutil/pint.h"
#include "wsutil/str_util.h"
#include "sna-utils.h"
#include "osi-utils.h"
#include <epan/dissectors/packet-mtp3.h>
#include <stdio.h>
@ -219,20 +219,6 @@ ipxnet_to_str_punct(wmem_allocator_t *scope, const guint32 ad, const char punct)
return buf;
}
static void
vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
{
if (buf_len < 14) {
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
return;
}
buf = dword_to_hex(buf, pntoh32(&addrp[0])); /* 8 bytes */
*buf++ = '.'; /* 1 byte */
buf = word_to_hex(buf, pntoh16(&addrp[4])); /* 4 bytes */
*buf = '\0'; /* 1 byte */
}
/*
This function is very fast and this function is called a lot.
XXX update the address_to_str stuff to use this function.
@ -254,113 +240,6 @@ eui64_to_str(wmem_allocator_t *scope, const guint64 ad) {
return buf;
}
static void
usb_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
{
if(pletoh32(&addrp[0])==0xffffffff){
g_snprintf(buf, buf_len, "host");
} else {
g_snprintf(buf, buf_len, "%d.%d.%d", pletoh16(&addrp[8]),
pletoh32(&addrp[0]), pletoh32(&addrp[4]));
}
}
static void
tipc_addr_to_str_buf( const guint8 *data, gchar *buf, int buf_len){
guint8 zone;
guint16 subnetwork;
guint16 processor;
guint32 tipc_address;
tipc_address = data[0];
tipc_address = (tipc_address << 8) ^ data[1];
tipc_address = (tipc_address << 8) ^ data[2];
tipc_address = (tipc_address << 8) ^ data[3];
processor = tipc_address & 0x0fff;
tipc_address = tipc_address >> 12;
subnetwork = tipc_address & 0x0fff;
tipc_address = tipc_address >> 12;
zone = tipc_address & 0xff;
g_snprintf(buf,buf_len,"%u.%u.%u",zone,subnetwork,processor);
}
static void
ib_addr_to_str_buf( 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: ");
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 */
g_snprintf ( buf, buf_len, BUF_TOO_SMALL_ERR ); /* Let the unexpected value alert user */
} else { /* this is a LID (16 bits) */
guint16 lid_number;
memcpy((void *)&lid_number, addr->data, sizeof lid_number);
g_snprintf(buf,buf_len,"LID: %u",lid_number);
}
}
/* FC Network Header Network Address Authority Identifiers */
#define FC_NH_NAA_IEEE 1 /* IEEE 802.1a */
#define FC_NH_NAA_IEEE_E 2 /* IEEE Exteneded */
#define FC_NH_NAA_LOCAL 3
#define FC_NH_NAA_IP 4 /* 32-bit IP address */
#define FC_NH_NAA_IEEE_R 5 /* IEEE Registered */
#define FC_NH_NAA_IEEE_R_E 6 /* IEEE Registered Exteneded */
/* according to FC-PH 3 draft these are now reclaimed and reserved */
#define FC_NH_NAA_CCITT_INDV 12 /* CCITT 60 bit individual address */
#define FC_NH_NAA_CCITT_GRP 14 /* CCITT 60 bit group address */
static void
fcwwn_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
{
int fmt;
guint8 oui[6];
gchar *ethptr, *manuf_name;
if (buf_len < 200) { /* This is mostly for manufacturer name */
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
return;
}
ethptr = bytes_to_hexstr_punct(buf, addrp, 8, ':'); /* 23 bytes */
fmt = (addrp[0] & 0xF0) >> 4;
switch (fmt) {
case FC_NH_NAA_IEEE:
case FC_NH_NAA_IEEE_E:
memcpy (oui, &addrp[2], 6);
manuf_name = get_manuf_name(NULL, oui);
g_snprintf (ethptr, buf_len-23, " (%s)", manuf_name);
wmem_free(NULL, manuf_name);
break;
case FC_NH_NAA_IEEE_R:
oui[0] = ((addrp[0] & 0x0F) << 4) | ((addrp[1] & 0xF0) >> 4);
oui[1] = ((addrp[1] & 0x0F) << 4) | ((addrp[2] & 0xF0) >> 4);
oui[2] = ((addrp[2] & 0x0F) << 4) | ((addrp[3] & 0xF0) >> 4);
oui[3] = ((addrp[3] & 0x0F) << 4) | ((addrp[4] & 0xF0) >> 4);
oui[4] = ((addrp[4] & 0x0F) << 4) | ((addrp[5] & 0xF0) >> 4);
oui[5] = ((addrp[5] & 0x0F) << 4) | ((addrp[6] & 0xF0) >> 4);
manuf_name = get_manuf_name(NULL, oui);
g_snprintf (ethptr, buf_len-23, " (%s)", manuf_name);
wmem_free(NULL, manuf_name);
break;
default:
*ethptr = '\0';
break;
}
}
static void
atalk_addr_to_str_buf(const struct atalk_ddp_addr *addrp, gchar *buf, int buf_len)
{
@ -418,30 +297,23 @@ 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_IEEE_802_15_4_SHORT:
addr.len = 2;
break;
case AT_ARCNET:
case AT_J1939:
addr.len = 1;
break;
case AT_DEVICENET:
addr.len = 1;
addr.data = GUINT_TO_POINTER((tvb_get_guint8(tvb, offset) & 0x3F));
return address_to_str(scope, &addr);
case AT_OSI:
case AT_SNA:
case AT_SS7PC:
case AT_STRINGZ:
case AT_URI:
case AT_TIPC:
case AT_IB:
/* Have variable length fields, use tvb_address_var_to_str() */
case AT_USB:
/* These addresses are not supported through tvb accessor */
default:
/* XXX - Removed because of dynamic address type range
XXX - Should we check that range?
g_assert_not_reached();
return NULL;
*/
break;
}
switch (addr.len) {
@ -485,131 +357,21 @@ gchar*
address_to_str(wmem_allocator_t *scope, const address *addr)
{
gchar *str;
int len = address_type_get_length(addr);
str=(gchar *)wmem_alloc(scope, MAX_ADDR_STR_LEN);
address_to_str_buf(addr, str, MAX_ADDR_STR_LEN);
if (len <= 0)
len = MAX_ADDR_STR_LEN;
str=(gchar *)wmem_alloc(scope, len);
address_to_str_buf(addr, str, len);
return str;
}
void
address_to_str_buf(const address *addr, gchar *buf, int buf_len)
{
const guint8 *addrdata;
struct atalk_ddp_addr ddp_addr;
guint16 ieee_802_15_4_short_addr;
char temp[32];
char *tempptr = temp;
if (!buf || !buf_len)
return;
switch(addr->type){
case AT_NONE:
buf[0] = '\0';
break;
case AT_ETHER: /* 18 bytes */
tempptr = bytes_to_hexstr_punct(tempptr, (const guint8 *)addr->data, 6, ':'); /* 17 bytes */
break;
case AT_IPv4:
ip_to_str_buf((const guint8 *)addr->data, buf, buf_len);
break;
case AT_IPv6:
ip6_to_str_buf_len((const guchar *)addr->data, buf, buf_len);
break;
case AT_IPX: /* 22 bytes */
addrdata = (const guint8 *)addr->data;
tempptr = bytes_to_hexstr(tempptr, &addrdata[0], 4); /* 8 bytes */
*tempptr++ = '.'; /*1 byte */
tempptr = bytes_to_hexstr(tempptr, &addrdata[4], 6); /* 12 bytes */
break;
case AT_SNA:
sna_fid_to_str_buf(addr, buf, buf_len);
break;
case AT_ATALK:
memcpy(&ddp_addr, addr->data, sizeof ddp_addr);
atalk_addr_to_str_buf(&ddp_addr, buf, buf_len);
break;
case AT_VINES:
vines_addr_to_str_buf((const guint8 *)addr->data, buf, buf_len);
break;
case AT_USB:
usb_addr_to_str_buf((const guint8 *)addr->data, buf, buf_len);
break;
case AT_OSI:
print_nsap_net_buf((const guint8 *)addr->data, addr->len, buf, buf_len);
break;
case AT_ARCNET: /* 5 bytes */
tempptr = g_stpcpy(tempptr, "0x"); /* 2 bytes */
tempptr = bytes_to_hexstr(tempptr, (const guint8 *)addr->data, 1); /* 2 bytes */
break;
case AT_FC: /* 9 bytes */
tempptr = bytes_to_hexstr_punct(tempptr, (const guint8 *)addr->data, 3, '.'); /* 8 bytes */
break;
case AT_FCWWN:
fcwwn_addr_to_str_buf((const guint8 *)addr->data, buf, buf_len);
break;
case AT_SS7PC:
mtp3_addr_to_str_buf((const mtp3_addr_pc_t *)addr->data, buf, buf_len);
break;
case AT_STRINGZ:
g_strlcpy(buf, (const gchar *)addr->data, buf_len);
break;
case AT_EUI64: /* 24 bytes */
tempptr = bytes_to_hexstr_punct(tempptr, (const guint8 *)addr->data, 8, ':'); /* 23 bytes */
break;
case AT_URI: {
int copy_len = addr->len < (buf_len - 1) ? addr->len : (buf_len - 1);
memcpy(buf, addr->data, copy_len );
buf[copy_len] = '\0';
}
break;
case AT_TIPC:
tipc_addr_to_str_buf((const guint8 *)addr->data, buf, buf_len);
break;
case AT_IB:
ib_addr_to_str_buf(addr, buf, buf_len);
break;
case AT_AX25:
addrdata = (const guint8 *)addr->data;
g_snprintf(buf, buf_len, "%c%c%c%c%c%c-%02d",
printable_char_or_period(addrdata[0] >> 1),
printable_char_or_period(addrdata[1] >> 1),
printable_char_or_period(addrdata[2] >> 1),
printable_char_or_period(addrdata[3] >> 1),
printable_char_or_period(addrdata[4] >> 1),
printable_char_or_period(addrdata[5] >> 1),
(addrdata[6] >> 1) & 0x0f );
break;
case AT_IEEE_802_15_4_SHORT:
ieee_802_15_4_short_addr = pletoh16(addr->data);
if (ieee_802_15_4_short_addr == 0xffff)
g_snprintf(buf, buf_len, "Broadcast");
else
g_snprintf(buf, buf_len, "0x%04x", ieee_802_15_4_short_addr);
break;
case AT_J1939:
addrdata = (const guint8 *)addr->data;
g_snprintf(buf, buf_len, "%d", addrdata[0]);
break;
case AT_DEVICENET:
addrdata = (const guint8 *)addr->data;
g_snprintf(buf, buf_len, "%d", addrdata[0] & 0x3f);
break;
default:
g_assert_not_reached();
}
/* copy to output buffer */
if (tempptr != temp) {
size_t temp_len = (size_t) (tempptr - temp);
if (temp_len < (size_t) buf_len) {
memcpy(buf, temp, temp_len);
buf[temp_len] = '\0';
} else
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len);/* Let the unexpected value alert user */
}
/* XXX - Keep this here for now to save changing all of the include headers */
address_type_to_string(addr, buf, buf_len);
}
/*

702
epan/address_types.c Normal file
View File

@ -0,0 +1,702 @@
/* address_types.c
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h> /* needed for <arpa/inet.h> on some platforms */
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h> /* needed to define AF_ values on UNIX */
#endif
#include <string.h> /* for memcmp */
#include "packet.h"
#include "address_types.h"
#include "to_str.h"
#include "to_str-int.h"
#include "addr_resolv.h"
#include "wsutil/pint.h"
#include "wsutil/str_util.h"
#include "wsutil/inet_v6defs.h"
#include <epan/dissectors/packet-mtp3.h>
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;
/* XXX - Some sort of compare functions (like ftype)? ***/
/* XXX - Include functions for name resolution? ***/
};
#define MAX_DISSECTOR_ADDR_TYPE 15
#define MAX_ADDR_TYPE_VALUE (AT_END_OF_LIST+MAX_DISSECTOR_ADDR_TYPE)
static int num_dissector_addr_type;
static address_type_t dissector_type_addresses[MAX_DISSECTOR_ADDR_TYPE];
/* Keep track of address_type_t's via their id number */
static address_type_t* type_list[MAX_ADDR_TYPE_VALUE];
/*
* If a user _does_ pass in a too-small buffer, this is probably
* going to be too long to fit. However, even a partial string
* starting with "[Buf" should provide enough of a clue to be
* useful.
*/
#define BUF_TOO_SMALL_ERR "[Buffer too small]"
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);
/* Don't re-register. */
g_assert(type_list[addr_type] == NULL);
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)
{
int addr_type;
/* Ensure valid data/functions for required fields */
DISSECTOR_ASSERT(name);
DISSECTOR_ASSERT(pretty_name);
DISSECTOR_ASSERT(to_str_func);
DISSECTOR_ASSERT(str_len_func);
/* This shouldn't happen, so flag it for fixing */
DISSECTOR_ASSERT(num_dissector_addr_type < MAX_DISSECTOR_ADDR_TYPE);
addr_type = AT_END_OF_LIST+num_dissector_addr_type;
dissector_type_addresses[num_dissector_addr_type].addr_type = addr_type;
dissector_type_addresses[num_dissector_addr_type].name = 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;
type_list[addr_type] = &dissector_type_addresses[num_dissector_addr_type];
num_dissector_addr_type++;
return addr_type;
}
/******************************************************************************
* AT_NONE
******************************************************************************/
static gboolean none_addr_to_str(const address* addr _U_, gchar *buf, int buf_len _U_)
{
buf[0] = '\0';
return TRUE;
}
static int none_addr_str_len(const address* addr _U_)
{
return 1; /* NULL character for empty string */
}
/******************************************************************************
* AT_ETHER
******************************************************************************/
static gboolean ether_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
bytes_to_hexstr_punct(buf, (const guint8*)addr->data, 6, ':');
buf[17] = '\0';
return TRUE;
}
static int ether_str_len(const address* addr _U_)
{
return 18;
}
/******************************************************************************
* AT_IPv4
******************************************************************************/
static gboolean ipv4_to_str(const address* addr, gchar *buf, int buf_len)
{
ip_to_str_buf((const guint8*)addr->data, buf, buf_len);
return TRUE;
}
static int ipv4_str_len(const address* addr _U_)
{
return MAX_IP_STR_LEN;
}
/******************************************************************************
* AT_IPv6
******************************************************************************/
static gboolean ipv6_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
/* XXX - pull in ip6_to_str_buf_len as this should be the module for it */
ip6_to_str_buf((const struct e_in6_addr*)addr->data, buf/*, buf_len*/);
return TRUE;
}
static int ipv6_str_len(const address* addr _U_)
{
return MAX_IP6_STR_LEN;
}
/******************************************************************************
* AT_IPX
******************************************************************************/
static gboolean ipx_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
const guint8 *addrdata = (const guint8 *)addr->data;
buf = bytes_to_hexstr(buf, &addrdata[0], 4); /* 8 bytes */
*buf++ = '.'; /*1 byte */
buf = bytes_to_hexstr(buf, &addrdata[4], 6); /* 12 bytes */
*buf++ = '\0'; /* NULL terminate */
return TRUE;
}
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
* address type, but need to resolve "address type" as "field type"
******************************************************************************/
static gboolean vines_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
const guint8 *addr_data = (const guint8 *)addr->data;
buf = dword_to_hex(buf, pntoh32(&addr_data[0])); /* 8 bytes */
*buf++ = '.'; /* 1 byte */
buf = word_to_hex(buf, pntoh16(&addr_data[4])); /* 4 bytes */
*buf = '\0'; /* NULL terminate */
return TRUE;
}
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
******************************************************************************/
static gboolean fc_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
buf = bytes_to_hexstr_punct(buf, (const guint8 *)addr->data, 3, '.');
*buf = '\0'; /* NULL terminate */
return TRUE;
}
static int fc_str_len(const address* addr _U_)
{
return 9;
}
/******************************************************************************
* AT_FCWWN
* XXX - Doubles as a "field type", should it be defined here?
* XXX - currently this has some address resolution worked into the "base" string
******************************************************************************/
/* FC Network Header Network Address Authority Identifiers */
#define FC_NH_NAA_IEEE 1 /* IEEE 802.1a */
#define FC_NH_NAA_IEEE_E 2 /* IEEE Exteneded */
#define FC_NH_NAA_LOCAL 3
#define FC_NH_NAA_IP 4 /* 32-bit IP address */
#define FC_NH_NAA_IEEE_R 5 /* IEEE Registered */
#define FC_NH_NAA_IEEE_R_E 6 /* IEEE Registered Exteneded */
/* according to FC-PH 3 draft these are now reclaimed and reserved */
#define FC_NH_NAA_CCITT_INDV 12 /* CCITT 60 bit individual address */
#define FC_NH_NAA_CCITT_GRP 14 /* CCITT 60 bit group address */
static gboolean fcwwn_to_str(const address* addr, gchar *buf, int buf_len)
{
const guint8 *addrp = (const guint8*)addr->data;
int fmt;
guint8 oui[6];
gchar *ethptr, *manuf_name;
if (buf_len < 200) { /* This is mostly for manufacturer name */
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
return FALSE;
}
ethptr = bytes_to_hexstr_punct(buf, addrp, 8, ':'); /* 23 bytes */
fmt = (addrp[0] & 0xF0) >> 4;
switch (fmt) {
case FC_NH_NAA_IEEE:
case FC_NH_NAA_IEEE_E:
memcpy (oui, &addrp[2], 6);
manuf_name = get_manuf_name(NULL, oui);
g_snprintf (ethptr, buf_len-23, " (%s)", manuf_name);
wmem_free(NULL, manuf_name);
break;
case FC_NH_NAA_IEEE_R:
oui[0] = ((addrp[0] & 0x0F) << 4) | ((addrp[1] & 0xF0) >> 4);
oui[1] = ((addrp[1] & 0x0F) << 4) | ((addrp[2] & 0xF0) >> 4);
oui[2] = ((addrp[2] & 0x0F) << 4) | ((addrp[3] & 0xF0) >> 4);
oui[3] = ((addrp[3] & 0x0F) << 4) | ((addrp[4] & 0xF0) >> 4);
oui[4] = ((addrp[4] & 0x0F) << 4) | ((addrp[5] & 0xF0) >> 4);
oui[5] = ((addrp[5] & 0x0F) << 4) | ((addrp[6] & 0xF0) >> 4);
manuf_name = get_manuf_name(NULL, oui);
g_snprintf (ethptr, buf_len-23, " (%s)", manuf_name);
wmem_free(NULL, manuf_name);
break;
default:
*ethptr = '\0';
break;
}
return TRUE;
}
static int fcwwn_str_len(const address* addr _U_)
{
return 200;
}
/******************************************************************************
* AT_SS7PC
* XXX - This should really be a dissector address type as its address string
* is partially determined by a dissector preference.
******************************************************************************/
static gboolean ss7pc_to_str(const address* addr, gchar *buf, int buf_len)
{
mtp3_addr_to_str_buf((const mtp3_addr_pc_t *)addr->data, buf, buf_len);
return TRUE;
}
static int ss7pc_str_len(const address* addr _U_)
{
return 50;
}
/******************************************************************************
* AT_STRINGZ
******************************************************************************/
static gboolean stringz_addr_to_str(const address* addr, gchar *buf, int buf_len)
{
g_strlcpy(buf, (const gchar *)addr->data, buf_len);
return TRUE;
}
static int stringz_addr_str_len(const address* addr)
{
return addr->len+1;
}
/******************************************************************************
* AT_EUI64
******************************************************************************/
static gboolean eui64_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
buf = bytes_to_hexstr_punct(buf, (const guint8 *)addr->data, 8, ':');
*buf = '\0'; /* NULL terminate */
return TRUE;
}
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
******************************************************************************/
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: ");
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 */
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
} else { /* this is a LID (16 bits) */
guint16 lid_number;
memcpy((void *)&lid_number, addr->data, sizeof lid_number);
g_snprintf(buf,buf_len,"LID: %u",lid_number);
}
return TRUE;
}
static int ib_str_len(const address* addr _U_)
{
return MAX_ADDR_STR_LEN; /* XXX - This is overkill */
}
/******************************************************************************
* AT_USB
* XXX - This functionality should really be in packet-usb.c as a dissector
* address type, but currently need support of AT_USB in conversation_table.c
******************************************************************************/
static gboolean usb_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
const guint8 *addrp = (const guint8 *)addr->data;
if(pletoh32(&addrp[0])==0xffffffff){
g_strlcpy(buf, "host", buf_len);
} else {
g_snprintf(buf, buf_len, "%d.%d.%d", pletoh16(&addrp[8]),
pletoh32(&addrp[0]), pletoh32(&addrp[4]));
}
return TRUE;
}
static int usb_addr_str_len(const address* addr _U_)
{
return 50;
}
/******************************************************************************
* AT_AX25
******************************************************************************/
static gboolean ax25_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
const guint8 *addrdata = (const guint8 *)addr->data;
*buf++ = printable_char_or_period(addrdata[0] >> 1);
*buf++ = printable_char_or_period(addrdata[1] >> 1);
*buf++ = printable_char_or_period(addrdata[2] >> 1);
*buf++ = printable_char_or_period(addrdata[3] >> 1);
*buf++ = printable_char_or_period(addrdata[4] >> 1);
*buf++ = printable_char_or_period(addrdata[5] >> 1);
*buf++ = '-';
buf = uint_to_str_back(buf, (addrdata[6] >> 1) & 0x0f);
*buf = '\0'; /* NULL terminate */
return TRUE;
}
static int ax25_addr_str_len(const address* addr _U_)
{
return 21; /* Leaves extra space (10 bytes) just for uint_to_str_back() */
}
/******************************************************************************
* END OF PROVIDED ADDRESS TYPES
******************************************************************************/
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
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 */
};
num_dissector_addr_type = 0;
/* Initialize the type array. This is mostly for handling
"dissector registered" address type range (for NULL checking) */
memset(type_list, 0, MAX_ADDR_TYPE_VALUE*sizeof(address_type_t*));
address_type_register(AT_NONE, &none_address );
address_type_register(AT_ETHER, &ether_address );
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 );
}
/* Given an address type id, return an address_type_t* */
#define ADDR_TYPE_LOOKUP(addr_type, result) \
/* Check input */ \
g_assert(addr_type < MAX_ADDR_TYPE_VALUE); \
result = type_list[addr_type];
/* 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;
ADDR_TYPE_LOOKUP(addr->type, at);
if ((at == NULL) || (at->addr_str_len == NULL))
return 0;
return at->addr_str_len(addr);
}
void address_type_to_string(const address* addr, gchar *buf, int buf_len)
{
address_type_t *at;
if (!buf || !buf_len)
return;
ADDR_TYPE_LOOKUP(addr->type, at);
if ((at == NULL) || (at->addr_to_str == NULL))
{
buf[0] = '\0';
return;
}
at->addr_to_str(addr, buf, buf_len);
}
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

68
epan/address_types.h Normal file
View File

@ -0,0 +1,68 @@
/* address_types.h
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __ADDRESS_TYPES_H__
#define __ADDRESS_TYPES_H__
#include "address.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef gboolean (*AddrValueToString)(const address* addr, gchar *buf, int buf_len);
typedef int (*AddrValueToStringLen)(const address* addr);
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);
void address_types_initialize(void);
/* XXX - Temporary? Here at least until all of the address type handling is finalized
* Otherwise should be folded into address_types.c or just be handled with function pointers
*/
int address_type_get_length(const address* addr);
void address_type_to_string(const address* addr, gchar *buf, int buf_len);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __ADDRESS_TYPES_H__ */
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -27,7 +27,6 @@
#include "column-utils.h"
#include "timestamp.h"
#include "sna-utils.h"
#include "to_str.h"
#include "packet_info.h"
#include "wsutil/pint.h"

View File

@ -129,6 +129,7 @@ which ATN standard is supported ?
#include <epan/packet.h>
#include <epan/address.h>
#include <epan/conversation.h>
#include <epan/osi-utils.h>
#include "packet-ber.h"
#include "packet-per.h"
#include "packet-atn-ulcs.h"
@ -276,7 +277,7 @@ static int hf_atn_ulcs_ACSE_requirements_authentication = -1;
static int hf_atn_ulcs_ACSE_requirements_application_context_negotiation = -1;
/*--- End of included file: packet-atn-ulcs-hf.c ---*/
#line 194 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
#line 195 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
/*--- Included file: packet-atn-ulcs-ett.c ---*/
@ -308,7 +309,7 @@ static gint ett_atn_ulcs_RelativeDistinguishedName = -1;
static gint ett_atn_ulcs_AttributeTypeAndValue = -1;
/*--- End of included file: packet-atn-ulcs-ett.c ---*/
#line 196 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
#line 197 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
static gint ett_atn_ulcs = -1;
static gint ett_atn_acse = -1;
@ -1599,7 +1600,7 @@ static int dissect_ACSE_apdu_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, prot
/*--- End of included file: packet-atn-ulcs-fn.c ---*/
#line 200 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
#line 201 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
#if 0
/* re-implementing external data: packet-per.c */
@ -1790,8 +1791,8 @@ guint32 get_aircraft_24_bit_address_from_nsap(
guint32 adr_prefix =0;
/* check NSAP address type*/
if( (pinfo->src.type != AT_OSI) ||
(pinfo->dst.type != AT_OSI)) {
if( (pinfo->src.type != get_osi_address_type()) ||
(pinfo->dst.type != get_osi_address_type())) {
return ars; }
/* 20 octets address length required */
@ -1862,7 +1863,7 @@ int check_heur_msg_type(packet_info *pinfo _U_)
guint32 adr_prefix =0;
/* check NSAP address type*/
if( (pinfo->src.type != AT_OSI) || (pinfo->dst.type != AT_OSI)) {
if( (pinfo->src.type != get_osi_address_type()) || (pinfo->dst.type != get_osi_address_type())) {
return t; }
/* check NSAP address length; 20 octets address length required */
@ -2484,7 +2485,7 @@ void proto_register_atn_ulcs (void)
NULL, HFILL }},
/*--- End of included file: packet-atn-ulcs-hfarr.c ---*/
#line 792 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
#line 793 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
{&hf_atn_ses_type,
{ "SPDU Type",
"atn-ulcs.ses.type",
@ -2572,7 +2573,7 @@ void proto_register_atn_ulcs (void)
&ett_atn_ulcs_AttributeTypeAndValue,
/*--- End of included file: packet-atn-ulcs-ettarr.c ---*/
#line 850 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
#line 851 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
&ett_atn_ses,
&ett_atn_pres,
&ett_atn_acse,

View File

@ -391,8 +391,8 @@ dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
dst_addr = tvb_get_ptr(tvb, offset, dst_len);
nsel = tvb_get_guint8(tvb, offset + dst_len - 1);
TVB_SET_ADDRESS(&pinfo->net_dst, AT_OSI, tvb, offset, dst_len);
TVB_SET_ADDRESS(&pinfo->dst, AT_OSI, tvb, offset, dst_len);
TVB_SET_ADDRESS(&pinfo->net_dst, get_osi_address_type(), tvb, offset, dst_len);
TVB_SET_ADDRESS(&pinfo->dst, get_osi_address_type(), tvb, offset, dst_len);
proto_tree_add_bytes_format_value(clnp_tree, hf_clnp_dest, tvb, offset, dst_len,
NULL,
"%s",
@ -428,8 +428,8 @@ dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
return;
}
src_addr = tvb_get_ptr(tvb, offset, src_len);
TVB_SET_ADDRESS(&pinfo->net_src, AT_OSI, tvb, offset, src_len);
TVB_SET_ADDRESS(&pinfo->src, AT_OSI, tvb, offset, src_len);
TVB_SET_ADDRESS(&pinfo->net_src, get_osi_address_type(), tvb, offset, src_len);
TVB_SET_ADDRESS(&pinfo->src, get_osi_address_type(), tvb, offset, src_len);
proto_tree_add_bytes_format_value(clnp_tree, hf_clnp_src, tvb,
offset, src_len,
NULL,
@ -738,6 +738,8 @@ proto_register_clnp(void)
clnp_heur_subdissector_list = register_heur_dissector_list("clnp");
register_init_routine(clnp_reassemble_init);
register_osi_address_type();
clnp_module = prefs_register_protocol(proto_clnp, NULL);
prefs_register_uint_preference(clnp_module, "tp_nsap_selector",
"NSAP selector for Transport Protocol (last byte in hex)",

View File

@ -30,6 +30,8 @@
#include <epan/uat.h>
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/address_types.h>
#include <epan/to_str-int.h>
#include "packet-cip.h"
void proto_register_devicenet(void);
@ -106,6 +108,8 @@ static expert_field ei_devicenet_invalid_can_id = EI_INIT;
static expert_field ei_devicenet_invalid_msg_id = EI_INIT;
static expert_field ei_devicenet_frag_not_supported = EI_INIT;
static int devicenet_address_type = -1;
enum node_behavior {
NODE_BEHAVIOR_8_8 = 0,
NODE_BEHAVIOR_8_16 = 1,
@ -449,7 +453,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
/* Set source address */
src_address = (guint8*)wmem_alloc(pinfo->pool, 1);
*src_address = (guint8)(can_id.id & MESSAGE_GROUP_1_MAC_ID_MASK);
SET_ADDRESS(&pinfo->src, AT_DEVICENET, 1, (const void*)src_address);
SET_ADDRESS(&pinfo->src, devicenet_address_type, 1, (const void*)src_address);
message_id = can_id.id & MESSAGE_GROUP_1_MSG_MASK;
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg1_vals, "Other Group 1 Message"));
@ -474,7 +478,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
/* Set source address */
src_address = (guint8*)wmem_alloc(pinfo->pool, 1);
*src_address = (guint8)((can_id.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3);
SET_ADDRESS(&pinfo->src, AT_DEVICENET, 1, (const void*)src_address);
SET_ADDRESS(&pinfo->src, devicenet_address_type, 1, (const void*)src_address);
content_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_contents, NULL, "Contents");
@ -520,7 +524,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
/* Set source address */
src_address = (guint8*)wmem_alloc(pinfo->pool, 1);
*src_address = (guint8)(can_id.id & MESSAGE_GROUP_3_MAC_ID_MASK);
SET_ADDRESS(&pinfo->src, AT_DEVICENET, 1, (const void*)src_address);
SET_ADDRESS(&pinfo->src, devicenet_address_type, 1, (const void*)src_address);
message_id = can_id.id & MESSAGE_GROUP_3_MSG_MASK;
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg3_vals, "Unknown"));
@ -535,7 +539,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
/* XXX - This may be source address depending on message type. Need to adjust accordingly) */
dest_address = (guint8*)wmem_alloc(pinfo->pool, 1);
*dest_address = (guint8)source_mac;
SET_ADDRESS(&pinfo->dst, AT_DEVICENET, 1, (const void*)dest_address);
SET_ADDRESS(&pinfo->dst, devicenet_address_type, 1, (const void*)dest_address);
offset++;
if (byte1 & MESSAGE_GROUP_3_FRAG_MASK)
@ -771,7 +775,21 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
"Invalid CAN Message 0x%04X", can_id.id);
}
return tvb_length(tvb);
return tvb_captured_length(tvb);
}
static gboolean devicenet_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
guint8 addrdata = *((guint8*)addr->data) & 0x3F;
buf = uint_to_str_back(buf, addrdata);
*buf = '\0';
return TRUE;
}
static int devicenet_addr_str_len(const address* addr _U_)
{
return 11; /* Leaves required space (10 bytes) for uint_to_str_back() */
}
void proto_register_devicenet(void)
@ -1004,6 +1022,8 @@ 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_module = prefs_register_protocol(proto_devicenet, NULL);
devicenet_uat = uat_new("Node bodytypes",

View File

@ -66,9 +66,11 @@
#include <epan/crc16-tvb.h>
#include <epan/expert.h>
#include <epan/addr_resolv.h>
#include <epan/address_types.h>
#include <epan/prefs.h>
#include <epan/uat.h>
#include <epan/strutil.h>
#include <epan/to_str-int.h>
#include <epan/show_exception.h>
#include <wsutil/pint.h>
@ -294,6 +296,7 @@ static expert_field ei_ieee802154_decrypt_error = EI_INIT;
static expert_field ei_ieee802154_dst = EI_INIT;
static expert_field ei_ieee802154_src = EI_INIT;
static int ieee802_15_4_short_address_type = -1;
/*
* Dissector handles
* - beacon dissection is always heuristic.
@ -387,6 +390,31 @@ static gboolean ieee802154_extend_auth = TRUE;
#define IEEE802154_CRC_XOROUT 0xFFFF
#define ieee802154_crc_tvb(tvb, offset) (crc16_ccitt_tvb_seed(tvb, offset, IEEE802154_CRC_SEED) ^ IEEE802154_CRC_XOROUT)
static gboolean ieee802_15_4_short_address_to_str(const address* addr, gchar *buf, int buf_len)
{
guint16 ieee_802_15_4_short_addr = pletoh16(addr->data);
if (ieee_802_15_4_short_addr == 0xffff)
{
g_strlcpy(buf, "Broadcast", buf_len);
return TRUE;
}
*buf++ = '0';
*buf++ = 'x';
buf = word_to_hex(buf, ieee_802_15_4_short_addr);
*buf = '\0'; /* NULL terminate */
return TRUE;
}
static int ieee802_15_4_short_address_str_len(const address* addr _U_)
{
return 11;
}
/*FUNCTION:------------------------------------------------------
* NAME
* dissect_ieee802154_fcf
@ -716,8 +744,8 @@ dissect_ieee802154_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, g
ieee_hints->dst16 = packet->dst16;
}
TVB_SET_ADDRESS(&pinfo->dl_dst, AT_IEEE_802_15_4_SHORT, tvb, offset, 2);
TVB_SET_ADDRESS(&pinfo->dst, AT_IEEE_802_15_4_SHORT, tvb, offset, 2);
TVB_SET_ADDRESS(&pinfo->dl_dst, ieee802_15_4_short_address_type, tvb, offset, 2);
TVB_SET_ADDRESS(&pinfo->dst, ieee802_15_4_short_address_type, tvb, offset, 2);
if (tree) {
proto_tree_add_uint(ieee802154_tree, hf_ieee802154_dst16, tvb, offset, 2, packet->dst16);
@ -810,8 +838,8 @@ dissect_ieee802154_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, g
}
}
TVB_SET_ADDRESS(&pinfo->dl_src, AT_IEEE_802_15_4_SHORT, tvb, offset, 2);
TVB_SET_ADDRESS(&pinfo->src, AT_IEEE_802_15_4_SHORT, tvb, offset, 2);
TVB_SET_ADDRESS(&pinfo->dl_src, ieee802_15_4_short_address_type, tvb, offset, 2);
TVB_SET_ADDRESS(&pinfo->src, ieee802_15_4_short_address_type, tvb, offset, 2);
/* Add the addressing info to the tree. */
if (tree) {
@ -2755,6 +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);
/* add a user preference to set the 802.15.4 ethertype */
ieee802154_module = prefs_register_protocol(proto_ieee802154,
proto_reg_handoff_ieee802154);

View File

@ -25,6 +25,8 @@
#include "config.h"
#include <epan/packet.h>
#include <epan/address_types.h>
#include <epan/to_str-int.h>
void proto_register_j1939(void);
@ -49,6 +51,7 @@ static gint ett_j1939 = -1;
static gint ett_j1939_can = -1;
static gint ett_j1939_message = -1;
static int j1939_address_type = -1;
static dissector_table_t subdissector_pgn_table;
static const value_string j1939_address_vals[] = {
@ -215,7 +218,7 @@ static int dissect_j1939(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo
/* Set source address */
src_addr = (guint8*)wmem_alloc(pinfo->pool, 1);
*src_addr = (guint8)(can_id.id & 0xFF);
SET_ADDRESS(&pinfo->src, AT_J1939, 1, (const void*)src_addr);
SET_ADDRESS(&pinfo->src, j1939_address_type, 1, (const void*)src_addr);
pgn = (can_id.id & 0x3FFFF00) >> 8;
@ -236,7 +239,7 @@ static int dissect_j1939(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo
/* Fill in "destination" address even if its "broadcast" */
dest_addr = (guint8*)wmem_alloc(pinfo->pool, 1);
*dest_addr = (guint8)((can_id.id & 0xFF00) >> 8);
SET_ADDRESS(&pinfo->dst, AT_J1939, 1, (const void*)dest_addr);
SET_ADDRESS(&pinfo->dst, j1939_address_type, 1, (const void*)dest_addr);
col_add_fstr(pinfo->cinfo, COL_INFO, "PGN: %d", pgn);
@ -253,7 +256,21 @@ static int dissect_j1939(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo
proto_tree_add_item(msg_tree, hf_j1939_data, tvb, 0, -1, ENC_NA);
}
return tvb_length(tvb);
return tvb_captured_length(tvb);
}
static gboolean J1939_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
const guint8 *addrdata = (const guint8 *)addr->data;
buf = uint_to_str_back(buf, *addrdata);
*buf = '\0';
return TRUE;
}
static int J1939_addr_str_len(const address* addr _U_)
{
return 11; /* Leaves required space (10 bytes) for uint_to_str_back() */
}
void proto_register_j1939(void)
@ -319,6 +336,8 @@ void proto_register_j1939(void)
new_register_dissector("j1939", dissect_j1939, proto_j1939);
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);
}
/*

View File

@ -27,9 +27,11 @@
#include <epan/packet.h>
#include <epan/llcsaps.h>
#include <epan/ppptypes.h>
#include <epan/sna-utils.h>
#include <epan/address_types.h>
#include <epan/prefs.h>
#include <epan/reassemble.h>
#include <epan/to_str-int.h>
#include "wsutil/pint.h"
/*
* http://www.wanresources.com/snacell.html
@ -303,6 +305,8 @@ static gint ett_sna_control_0e = -1;
static dissector_handle_t data_handle;
static int sna_address_type = -1;
/* Defragment fragmented SNA BIUs*/
static gboolean sna_defragment = TRUE;
static reassembly_table sna_reassembly_table;
@ -805,6 +809,17 @@ enum parse {
KL
};
/*
* Structure used to represent an FID Type 4 address; gives the layout of the
* data pointed to by an AT_SNA "address" structure if the size is
* SNA_FID_TYPE_4_ADDR_LEN.
*/
#define SNA_FID_TYPE_4_ADDR_LEN 6
struct sna_fid_type_4_addr {
guint32 saf;
guint16 ef;
};
typedef enum next_dissection_enum next_dissection_t;
static void dissect_xid (tvbuff_t*, packet_info*, proto_tree*, proto_tree*);
@ -814,6 +829,50 @@ static void dissect_gds (tvbuff_t*, packet_info*, proto_tree*, proto_tree*);
static void dissect_rh (tvbuff_t*, int, proto_tree*);
static void dissect_control(tvbuff_t*, int, int, proto_tree*, int, enum parse);
static gboolean sna_fid_to_str_buf(const address *addr, gchar *buf, int buf_len _U_)
{
const guint8 *addrdata;
struct sna_fid_type_4_addr sna_fid_type_4_addr;
switch (addr->len) {
case 1:
addrdata = (const guint8 *)addr->data;
word_to_hex(buf, addrdata[0]);
buf[4] = '\0';
break;
case 2:
addrdata = (const guint8 *)addr->data;
word_to_hex(buf, pntoh16(&addrdata[0]));
buf[4] = '\0';
break;
case SNA_FID_TYPE_4_ADDR_LEN:
/* FID Type 4 */
memcpy(&sna_fid_type_4_addr, addr->data, SNA_FID_TYPE_4_ADDR_LEN);
buf = dword_to_hex(buf, sna_fid_type_4_addr.saf);
*buf++ = '.';
buf = word_to_hex(buf, sna_fid_type_4_addr.ef);
*buf++ = '\0'; /* NULL terminate */
break;
default:
buf[0] = '\0';
return FALSE;
}
return TRUE;
}
static int sna_address_str_len(const address* addr _U_)
{
/* We could do this based on address length, but 14 bytes isn't THAT much space */
return 14;
}
/* --------------------------------------------------------------------
* Chapter 2 High-Performance Routing (HPR) Headers
* --------------------------------------------------------------------
@ -1668,14 +1727,14 @@ dissect_fid0_1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
/* Set DST addr */
TVB_SET_ADDRESS(&pinfo->net_dst, AT_SNA, tvb, 2, SNA_FID01_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->dst, AT_SNA, tvb, 2, SNA_FID01_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->net_dst, sna_address_type, tvb, 2, SNA_FID01_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->dst, sna_address_type, tvb, 2, SNA_FID01_ADDR_LEN);
proto_tree_add_item(tree, hf_sna_th_oaf, tvb, 4, 2, ENC_BIG_ENDIAN);
/* Set SRC addr */
TVB_SET_ADDRESS(&pinfo->net_src, AT_SNA, tvb, 4, SNA_FID01_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->src, AT_SNA, tvb, 4, SNA_FID01_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->net_src, sna_address_type, tvb, 4, SNA_FID01_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->src, sna_address_type, tvb, 4, SNA_FID01_ADDR_LEN);
proto_tree_add_item(tree, hf_sna_th_snf, tvb, 6, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(tree, hf_sna_th_dcf, tvb, 8, 2, ENC_BIG_ENDIAN);
@ -1720,15 +1779,15 @@ dissect_fid2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
}
/* Set DST addr */
TVB_SET_ADDRESS(&pinfo->net_dst, AT_SNA, tvb, 2, SNA_FID2_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->dst, AT_SNA, tvb, 2, SNA_FID2_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->net_dst, sna_address_type, tvb, 2, SNA_FID2_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->dst, sna_address_type, tvb, 2, SNA_FID2_ADDR_LEN);
/* Byte 3 */
proto_tree_add_item(tree, hf_sna_th_oaf, tvb, 3, 1, ENC_BIG_ENDIAN);
/* Set SRC addr */
TVB_SET_ADDRESS(&pinfo->net_src, AT_SNA, tvb, 3, SNA_FID2_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->src, AT_SNA, tvb, 3, SNA_FID2_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->net_src, sna_address_type, tvb, 3, SNA_FID2_ADDR_LEN);
TVB_SET_ADDRESS(&pinfo->src, sna_address_type, tvb, 3, SNA_FID2_ADDR_LEN);
id = tvb_get_ntohs(tvb, 4);
proto_tree_add_item(tree, hf_sna_th_snf, tvb, 4, 2, ENC_BIG_ENDIAN);
@ -1918,8 +1977,8 @@ dissect_fid4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
dst = wmem_new0(pinfo->pool, struct sna_fid_type_4_addr);
dst->saf = dsaf;
dst->ef = def;
SET_ADDRESS(&pinfo->net_dst, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN, dst);
SET_ADDRESS(&pinfo->dst, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN, dst);
SET_ADDRESS(&pinfo->net_dst, sna_address_type, SNA_FID_TYPE_4_ADDR_LEN, dst);
SET_ADDRESS(&pinfo->dst, sna_address_type, SNA_FID_TYPE_4_ADDR_LEN, dst);
oef = tvb_get_ntohs(tvb, 20);
proto_tree_add_uint(tree, hf_sna_th_oef, tvb, offset+2, 2, oef);
@ -1928,8 +1987,8 @@ dissect_fid4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
src = wmem_new0(pinfo->pool, struct sna_fid_type_4_addr);
src->saf = osaf;
src->ef = oef;
SET_ADDRESS(&pinfo->net_src, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN, src);
SET_ADDRESS(&pinfo->src, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN, src);
SET_ADDRESS(&pinfo->net_src, sna_address_type, SNA_FID_TYPE_4_ADDR_LEN, src);
SET_ADDRESS(&pinfo->src, sna_address_type, SNA_FID_TYPE_4_ADDR_LEN, src);
proto_tree_add_item(tree, hf_sna_th_snf, tvb, offset+4, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(tree, hf_sna_th_dcf, tvb, offset+6, 2, ENC_BIG_ENDIAN);
@ -3422,6 +3481,8 @@ 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);
/* Register configuration options */
sna_module = prefs_register_protocol(proto_sna, NULL);
prefs_register_bool_preference(sna_module, "defragment",

View File

@ -34,6 +34,7 @@
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/etypes.h>
#include <epan/address_types.h>
#include <epan/reassemble.h>
#include "packet-tcp.h"
@ -184,6 +185,8 @@ static gint ett_tipc_data = -1;
static expert_field ei_tipc_words_unused_for_user = EI_INIT;
static int tipc_address_type = -1;
/* protocol preferences */
static gboolean tipc_defragment = TRUE;
static gboolean dissect_tipc_data = TRUE;
@ -574,16 +577,12 @@ tipc_defragment_init(void)
&addresses_reassembly_table_functions);
}
static gchar*
tipc_addr_to_str(guint tipc_address)
tipc_addr_value_to_buf(guint tipc_address, gchar *buf, int buf_len)
{
guint8 zone;
guint16 subnetwork;
guint16 processor;
gchar *buff;
buff = (gchar *)wmem_alloc(wmem_packet_scope(), MAX_TIPC_ADDRESS_STR_LEN);
processor = tipc_address & 0x0fff;
@ -593,11 +592,40 @@ tipc_addr_to_str(guint tipc_address)
tipc_address = tipc_address >> 12;
zone = tipc_address & 0xff;
g_snprintf(buff, MAX_TIPC_ADDRESS_STR_LEN, "%u.%u.%u", zone, subnetwork, processor);
return buff;
g_snprintf(buf, buf_len, "%u.%u.%u", zone, subnetwork, processor);
return buf;
}
static gchar*
tipc_addr_to_str(guint tipc_address)
{
gchar *buf;
buf = (gchar *)wmem_alloc(wmem_packet_scope(), MAX_TIPC_ADDRESS_STR_LEN);
return tipc_addr_value_to_buf(tipc_address, buf, MAX_TIPC_ADDRESS_STR_LEN);
}
static gboolean
tipc_addr_to_str_buf(const address* addr, gchar *buf, int buf_len)
{
const guint8 *data = (const guint8 *)addr->data;
guint32 tipc_address;
tipc_address = data[0];
tipc_address = (tipc_address << 8) ^ data[1];
tipc_address = (tipc_address << 8) ^ data[2];
tipc_address = (tipc_address << 8) ^ data[3];
tipc_addr_value_to_buf(tipc_address, buf, buf_len);
return TRUE;
}
static int tipc_addr_str_len(const address* addr _U_)
{
return MAX_TIPC_ADDRESS_STR_LEN;
}
/*
All name distributor messages have a data part containing one or more table elements with
the following five-word structure:
@ -2069,18 +2097,18 @@ dissect_tipc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
/* Data type header */
if (hdr_size > 5 && user <4) {
/* W6 Originating Processor */
TVB_SET_ADDRESS(&pinfo->src, AT_TIPC, tipc_tvb, offset + 24, 4);
TVB_SET_ADDRESS(&pinfo->src, tipc_address_type, tipc_tvb, offset + 24, 4);
/* W7 Destination Processor */
TVB_SET_ADDRESS(&pinfo->dst, AT_TIPC, tipc_tvb, offset + 28, 4);
TVB_SET_ADDRESS(&pinfo->dst, tipc_address_type, tipc_tvb, offset + 28, 4);
} else {
/* Short data hdr */
/* W2 Previous Processor */
TVB_SET_ADDRESS(&pinfo->src, AT_TIPC, tipc_tvb, offset + 8, 4);
TVB_SET_ADDRESS(&pinfo->src, tipc_address_type, tipc_tvb, offset + 8, 4);
}
} else {
/* W2 Previous Processor */
TVB_SET_ADDRESS(&pinfo->src, AT_TIPC, tipc_tvb, offset + 8, 4);
TVB_SET_ADDRESS(&pinfo->src, tipc_address_type, tipc_tvb, offset + 8, 4);
}
break;
case TIPCv2:
@ -2105,28 +2133,28 @@ dissect_tipc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
if (datatype_hdr) {
if (hdr_size > 6) {
/* W6 Originating Processor */
TVB_SET_ADDRESS(&pinfo->src, AT_TIPC, tipc_tvb, offset + 24, 4);
TVB_SET_ADDRESS(&pinfo->src, tipc_address_type, tipc_tvb, offset + 24, 4);
/* W7 Destination Processor */
TVB_SET_ADDRESS(&pinfo->dst, AT_TIPC, tipc_tvb, offset + 28, 4);
TVB_SET_ADDRESS(&pinfo->dst, tipc_address_type, tipc_tvb, offset + 28, 4);
} else {
/* W3 Previous Processor */
TVB_SET_ADDRESS(&pinfo->src, AT_TIPC, tipc_tvb, offset + 12, 4);
TVB_SET_ADDRESS(&pinfo->src, tipc_address_type, tipc_tvb, offset + 12, 4);
}
} else {
if (user != TIPCv2_NEIGHBOUR_DISCOVERY) {
/* W6 Originating Processor */
TVB_SET_ADDRESS(&pinfo->src, AT_TIPC, tipc_tvb, offset + 24, 4);
TVB_SET_ADDRESS(&pinfo->src, tipc_address_type, tipc_tvb, offset + 24, 4);
/* W7 Destination Processor */
TVB_SET_ADDRESS(&pinfo->dst, AT_TIPC, tipc_tvb, offset + 28, 4);
TVB_SET_ADDRESS(&pinfo->dst, tipc_address_type, tipc_tvb, offset + 28, 4);
} else {
/* W2 Destination Domain */
TVB_SET_ADDRESS(&pinfo->dst, AT_TIPC, tipc_tvb, offset + 8, 4);
TVB_SET_ADDRESS(&pinfo->dst, tipc_address_type, tipc_tvb, offset + 8, 4);
/* W3 Previous Node */
TVB_SET_ADDRESS(&pinfo->src, AT_TIPC, tipc_tvb, offset + 12, 4);
TVB_SET_ADDRESS(&pinfo->src, tipc_address_type, tipc_tvb, offset + 12, 4);
}
}
break;
@ -2933,6 +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);
/* Set default ports */
range_convert_str(&global_tipc_udp_port_range, DEFAULT_TIPC_PORT_RANGE, MAX_TCP_PORT);

View File

@ -32,6 +32,8 @@
#include "tvbuff.h"
#include "osi-utils.h"
#include "address.h"
#include "address_types.h"
/*
* XXX - shouldn't there be a centralized routine for dissecting NSAPs?
@ -57,7 +59,7 @@ print_nsap_net_buf( const guint8 *ad, int length, gchar *buf, int buf_len)
/* to do : NSAP / NET decoding */
if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
g_snprintf(buf, buf_len, "<Invalid length of NSAP>");
g_strlcpy(buf, "<Invalid length of NSAP>", buf_len);
return;
}
cur = buf;
@ -100,7 +102,7 @@ print_system_id_buf( const guint8 *ad, int length, gchar *buf, int buf_len)
int tmp;
if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
g_snprintf(buf, buf_len, "<Invalid length of SYSTEM ID>");
g_strlcpy(buf, "<Invalid length of SYSTEM ID>", buf_len);
return;
}
@ -158,7 +160,7 @@ print_area_buf(const guint8 *ad, int length, gchar *buf, int buf_len)
* and take away all these stupid resource consuming local statics
*/
if (length <= 0 || length > MAX_AREA_LEN) {
g_snprintf(buf, buf_len, "<Invalid length of AREA>");
g_strlcpy(buf, "<Invalid length of AREA>", buf_len);
return;
}
@ -213,6 +215,36 @@ print_area_buf(const guint8 *ad, int length, gchar *buf, int buf_len)
}
} /* print_area_buf */
/******************************************************************************
* OSI Address Type
******************************************************************************/
static int osi_address_type = -1;
static gboolean osi_address_to_str(const address* addr, gchar *buf, int buf_len)
{
print_nsap_net_buf((const guint8 *)addr->data, addr->len, buf, buf_len);
return TRUE;
}
static int osi_address_str_len(const address* addr _U_)
{
return MAX_NSAP_LEN * 3 + 50;
}
int get_osi_address_type(void)
{
return osi_address_type;
}
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);
}
/*
* Editor modelines
*

View File

@ -53,6 +53,9 @@ gchar* print_system_id(wmem_allocator_t *, const guint8 *, int );
gchar* tvb_print_system_id( tvbuff_t *, const gint, int );
void print_system_id_buf( const guint8 *, int, gchar *, int);
int get_osi_address_type(void);
void register_osi_address_type(void);
#endif /* __OSI_UTILS_H__ */
/*

View File

@ -37,7 +37,6 @@
#include "packet.h"
#include "timestamp.h"
#include "sna-utils.h"
#include "osi-utils.h"
#include "to_str.h"

View File

@ -39,6 +39,7 @@
#include "ptvcursor.h"
#include "strutil.h"
#include "addr_resolv.h"
#include "address_types.h"
#include "oids.h"
#include "proto.h"
#include "epan_dissect.h"
@ -464,6 +465,9 @@ proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_da
/* Initialize the ftype subsystem */
ftypes_initialize();
/* Initialize the addres type subsystem */
address_types_initialize();
/* Register one special-case FT_TEXT_ONLY field for use when
converting wireshark to new-style proto_tree. These fields
are merely strings on the GUI tree; they are not filterable */

View File

@ -1,80 +0,0 @@
/* sna-utils.c
* Routines for SNA
* Gilbert Ramirez <gram@alumni.rice.edu>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <string.h>
#include "packet_info.h"
#include "wsutil/pint.h"
#include "sna-utils.h"
gchar *
sna_fid_to_str(const address *addr)
{
gchar *cur;
cur=(gchar *)wmem_alloc(wmem_packet_scope(), 14);
sna_fid_to_str_buf(addr, cur, 14);
return cur;
}
void
sna_fid_to_str_buf(const address *addr, gchar *buf, int buf_len)
{
const guint8 *addrdata;
struct sna_fid_type_4_addr sna_fid_type_4_addr;
switch (addr->len) {
case 1:
addrdata = (const guint8 *)addr->data;
g_snprintf(buf, buf_len, "%04X", addrdata[0]);
break;
case 2:
addrdata = (const guint8 *)addr->data;
g_snprintf(buf, buf_len, "%04X", pntoh16(&addrdata[0]));
break;
case SNA_FID_TYPE_4_ADDR_LEN:
/* FID Type 4 */
memcpy(&sna_fid_type_4_addr, addr->data, SNA_FID_TYPE_4_ADDR_LEN);
g_snprintf(buf, buf_len, "%08X.%04X", sna_fid_type_4_addr.saf,
sna_fid_type_4_addr.ef);
break;
}
}
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local Variables:
* c-basic-offset: 2
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=2 tabstop=8 expandtab:
* :indentSize=2:tabSize=8:noTabs=true:
*/

View File

@ -1,39 +0,0 @@
/* sna-utils.h
* Definitions for SNA dissection.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __SNA_UTILS__
#define __SNA_UTILS__
#include <glib.h>
#include <stdio.h>
/*
* Structure used to represent an FID Type 4 address; gives the layout of the
* data pointed to by an AT_SNA "address" structure if the size is
* SNA_FID_TYPE_4_ADDR_LEN.
*/
#define SNA_FID_TYPE_4_ADDR_LEN 6
struct sna_fid_type_4_addr {
guint32 saf;
guint16 ef;
};
extern gchar *sna_fid_to_str(const address *addr);
extern void sna_fid_to_str_buf(const address *addr, gchar *buf, int buf_len);
#endif

View File

@ -990,7 +990,7 @@ ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len)
register gchar *b=buf;
if (buf_len < MAX_IP_STR_LEN) {
g_snprintf ( buf, buf_len, BUF_TOO_SMALL_ERR ); /* Let the unexpected value alert user */
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
return;
}