Create an "address_to_str_buf()" routine, called by "address_to_str()",

which fills in a caller-supplied buffer.

Create "_buf()" versions of various "to_str" routines for various
address types, and create a routine to map SNA FIDs to strings, and use
them to finish up "address_to_str_buf()".

Get rid of the declaration of "sna_fid_type_4_addr_to_str()" in
"packet-sna.h", as that routine has been swallowed up in
"sna_fid_to_str()".

svn path=/trunk/; revision=8260
This commit is contained in:
Guy Harris 2003-08-26 01:00:30 +00:00
parent 9bcebc00c0
commit d9c401c74c
10 changed files with 202 additions and 151 deletions

View File

@ -1,7 +1,7 @@
/* atalk-utils.c
* Routines for Appletalk utilities (DDP, currently).
*
* $Id: atalk-utils.c,v 1.3 2002/08/28 20:40:44 jmayer Exp $
* $Id: atalk-utils.c,v 1.4 2003/08/26 01:00:29 guy Exp $
*
* Simon Wilkinson <sxw@dcs.ed.ac.uk>
*
@ -39,8 +39,12 @@ atalk_addr_to_str(const struct atalk_ddp_addr *addrp)
} else {
cur = &str[0][0];
}
sprintf(cur, "%u.%u", addrp->net, addrp->node );
atalk_addr_to_str_buf(addrp, cur);
return cur;
}
void
atalk_addr_to_str_buf(const struct atalk_ddp_addr *addrp, gchar *buf)
{
sprintf(buf, "%u.%u", addrp->net, addrp->node );
}

View File

@ -1,7 +1,7 @@
/* atalk-utils.h
* Definitions for Appletalk utilities (DDP, currently).
*
* $Id: atalk-utils.h,v 1.3 2002/08/28 20:40:44 jmayer Exp $
* $Id: atalk-utils.h,v 1.4 2003/08/26 01:00:29 guy Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -45,8 +45,10 @@ struct atalk_ddp_addr {
#define DDP_EIGRP 0x58
/*
* Routine to take a DDP address and generate a string.
* Routines to take a DDP address and generate a string.
*/
extern gchar *atalk_addr_to_str(const struct atalk_ddp_addr *addrp);
extern void atalk_addr_to_str_buf(const struct atalk_ddp_addr *addrp,
gchar *buf);
#endif

View File

@ -1,7 +1,7 @@
/* column-utils.c
* Routines for column utilities.
*
* $Id: column-utils.c,v 1.34 2003/04/16 05:55:39 guy Exp $
* $Id: column-utils.c,v 1.35 2003/08/26 01:00:29 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -484,7 +484,6 @@ col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
guint32 ipv4_addr;
struct e_in6_addr ipv6_addr;
struct atalk_ddp_addr ddp_addr;
struct sna_fid_type_4_addr sna_fid_type_4_addr;
guint8 fcid[3];
pinfo->cinfo->col_expr[col][0] = '\0';
@ -546,23 +545,7 @@ col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
break;
case AT_SNA:
switch (addr->len) {
case 1:
snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%04X", addr->data[0]);
break;
case 2:
snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%04X",
pntohs(&addr->data[0]));
break;
case SNA_FID_TYPE_4_ADDR_LEN:
memcpy(&sna_fid_type_4_addr, addr->data, SNA_FID_TYPE_4_ADDR_LEN);
strncpy(pinfo->cinfo->col_buf[col],
sna_fid_type_4_addr_to_str(&sna_fid_type_4_addr), COL_MAX_LEN);
break;
}
strncpy(pinfo->cinfo->col_buf[col], sna_fid_to_str(addr), COL_MAX_LEN);
pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
break;

View File

@ -2,15 +2,14 @@
* Routines for ISO/OSI network and transport protocol packet disassembly
* Main entrance point and common functions
*
* $Id: osi-utils.c,v 1.11 2003/01/26 19:35:29 deniel Exp $
* $Id: osi-utils.c,v 1.12 2003/08/26 01:00:29 guy Exp $
* Laurent Deniel <laurent.deniel@free.fr>
* Ralf Schneider <Ralf.Schneider@t-online.de>
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* By Gerald Combs <gerald@ethereal.com>
* 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
@ -24,7 +23,6 @@
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
@ -32,103 +30,133 @@
#endif
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "osi-utils.h"
gchar *print_nsap_net( const guint8 *buffer, int length)
gchar *
print_nsap_net( const guint8 *ad, int length )
{
/* to do : NSAP / NET decoding */
static gchar str[MAX_NSAP_LEN * 3 + 50]; /* reserve space for nice layout */
gchar *cur;
cur = str;
print_nsap_net_buf( ad, length, cur );
return( cur );
}
void
print_nsap_net_buf( const guint8 *ad, int length, gchar *buf )
{
gchar *cur;
/* to do : NSAP / NET decoding */
if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
sprintf( str, "<Invalid length of NSAP>");
return( str );
sprintf( buf, "<Invalid length of NSAP>");
return;
}
cur = buf;
if ( ( length == RFC1237_NSAP_LEN ) || ( length == RFC1237_NSAP_LEN + 1 ) ) {
cur += sprintf( cur, "%s", print_area( buffer, RFC1237_FULLAREA_LEN ) );
cur += sprintf( cur, "%s", print_system_id( buffer + RFC1237_FULLAREA_LEN,
RFC1237_SYSTEMID_LEN ) );
print_area_buf( ad, RFC1237_FULLAREA_LEN, cur );
cur += strlen( cur );
print_system_id_buf( ad + RFC1237_FULLAREA_LEN, RFC1237_SYSTEMID_LEN, cur );
cur += strlen( cur );
cur += sprintf( cur, "[%02x]",
buffer[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
ad[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
if ( length == RFC1237_NSAP_LEN + 1 ) {
cur += sprintf( cur, "-%02x", buffer[ length -1 ] );
cur += sprintf( cur, "-%02x", ad[ length -1 ] );
}
return ( str );
}
else { /* probably format as standard */
return( print_area( buffer, length ) );
return( print_area_buf( ad, length, buf ) );
}
} /* print_nsap */
gchar *print_system_id( const guint8 *buffer, int length ) {
int tmp;
gchar *cur;
gchar *
print_system_id( const guint8 *ad, int length )
{
static gchar str[MAX_SYSTEMID_LEN * 3 + 5]; /* Don't trust exact matching */
if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
sprintf( str, "<Invalid length of SYSTEM ID>");
return( str );
}
gchar *cur;
cur = str;
print_nsap_net_buf( ad, length, cur );
return( cur );
}
void
print_system_id_buf( const guint8 *ad, int length, gchar *buf )
{
gchar *cur;
int tmp;
if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
sprintf( buf, "<Invalid length of SYSTEM ID>");
return;
}
cur = buf;
if ( ( 6 == length ) || /* System-ID */
( 7 == length ) || /* LAN-ID */
( 8 == length )) { /* LSP-ID */
cur += sprintf(cur, "%02x%02x.%02x%02x.%02x%02x", buffer[0], buffer[1],
buffer[2], buffer[3], buffer[4], buffer[5] );
cur += sprintf(cur, "%02x%02x.%02x%02x.%02x%02x", ad[0], ad[1],
ad[2], ad[3], ad[4], ad[5] );
if ( ( 7 == length ) ||
( 8 == length )) {
cur += sprintf( cur, ".%02x", buffer[6] );
cur += sprintf( cur, ".%02x", ad[6] );
}
if ( 8 == length ) {
cur += sprintf( cur, "-%02x", buffer[7] );
cur += sprintf( cur, "-%02x", ad[7] );
}
}
else {
tmp = 0;
while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */
cur += sprintf( cur, "%02x", buffer[tmp++] );
cur += sprintf( cur, "%02x", buffer[tmp++] );
cur += sprintf( cur, "%02x", buffer[tmp++] );
cur += sprintf( cur, "%02x.", buffer[tmp++] );
cur += sprintf( cur, "%02x", ad[tmp++] );
cur += sprintf( cur, "%02x", ad[tmp++] );
cur += sprintf( cur, "%02x", ad[tmp++] );
cur += sprintf( cur, "%02x.", ad[tmp++] );
}
if ( 1 == tmp ) { /* Special case for Designated IS */
sprintf( --cur, ".%02x", buffer[tmp] );
sprintf( --cur, ".%02x", ad[tmp] );
}
else {
for ( ; tmp < length; ) { /* print the rest without dot */
cur += sprintf( cur, "%02x", buffer[tmp++] );
cur += sprintf( cur, "%02x", ad[tmp++] );
}
}
}
return( str );
}
gchar *print_area(const guint8 *buffer, int length)
gchar *
print_area(const guint8 *ad, int length)
{
/* to do : all real area decoding now: NET is assumed if id len is 1 more byte
* and take away all these stupid resource consuming local statics
*/
static gchar str[MAX_AREA_LEN * 3 + 20]; /* reserve space for nice layout */
gchar *cur;
cur = str;
print_area_buf( ad, length, cur );
return cur;
}
void
print_area_buf(const guint8 *ad, int length, gchar *buf)
{
gchar *cur;
int tmp = 0;
cur = str;
/* to do : all real area decoding now: NET is assumed if id len is 1 more byte
* and take away all these stupid resource consuming local statics
*/
if (length <= 0 || length > MAX_AREA_LEN) {
sprintf( str, "<Invalid length of AREA>");
return( str );
sprintf( buf, "<Invalid length of AREA>");
return;
}
if ( ( ( NSAP_IDI_ISODCC == *buffer )
|| ( NSAP_IDI_GOSIP2 == *buffer )
cur = buf;
if ( ( ( NSAP_IDI_ISODCC == *ad )
|| ( NSAP_IDI_GOSIP2 == *ad )
)
&&
( ( RFC1237_FULLAREA_LEN == length )
@ -137,43 +165,39 @@ gchar *print_area(const guint8 *buffer, int length)
) { /* AFI is good and length is long enough */
if ( length > RFC1237_FULLAREA_LEN + 1 ) { /* Special Case Designated IS */
sprintf( str, "<Invalid length of AREA for DCC / GOSIP AFI>");
return( str );
sprintf( buf, "<Invalid length of AREA for DCC / GOSIP AFI>");
return;
}
cur += sprintf( cur, "[%02x|%02x:%02x][%02x|%02x:%02x:%02x|%02x:%02x]",
buffer[0], buffer[1], buffer[2], buffer[3], buffer[4],
buffer[5], buffer[6], buffer[7], buffer[8] );
ad[0], ad[1], ad[2], ad[3], ad[4],
ad[5], ad[6], ad[7], ad[8] );
cur += sprintf( cur, "[%02x:%02x|%02x:%02x]",
buffer[9], buffer[10], buffer[11], buffer[12] );
if ( RFC1237_FULLAREA_LEN + 1 == length ) {
sprintf( cur, "-[%02x]", buffer[20] );
}
return str;
ad[9], ad[10], ad[11], ad[12] );
if ( RFC1237_FULLAREA_LEN + 1 == length )
sprintf( cur, "-[%02x]", ad[20] );
}
else { /* print standard format */
if ( length == RFC1237_AREA_LEN ) {
sprintf( str, "%02x.%02x%02x", buffer[0], buffer[1],
buffer[2] );
return( str );
}
sprintf( buf, "%02x.%02x%02x", ad[0], ad[1], ad[2] );
return;
}
if ( 4 < length ) {
while ( tmp < length / 4 ) { /* 16/4==4 > four Octets left to print */
cur += sprintf( cur, "%02x", buffer[tmp++] );
cur += sprintf( cur, "%02x", buffer[tmp++] );
cur += sprintf( cur, "%02x", buffer[tmp++] );
cur += sprintf( cur, "%02x.", buffer[tmp++] );
cur += sprintf( cur, "%02x", ad[tmp++] );
cur += sprintf( cur, "%02x", ad[tmp++] );
cur += sprintf( cur, "%02x", ad[tmp++] );
cur += sprintf( cur, "%02x.", ad[tmp++] );
}
if ( 1 == tmp ) { /* Special case for Designated IS */
sprintf( --cur, "-%02x", buffer[tmp] );
sprintf( --cur, "-%02x", ad[tmp] );
}
else {
for ( ; tmp < length; ) { /* print the rest without dot */
cur += sprintf( cur, "%02x", buffer[tmp++] );
cur += sprintf( cur, "%02x", ad[tmp++] );
}
}
}
return( str );
}
} /* print_area */
} /* print_area_buf */

View File

@ -1,12 +1,11 @@
/* osi-utils.h
*
* $Id: osi-utils.h,v 1.4 2002/08/28 20:40:44 jmayer Exp $
* $Id: osi-utils.h,v 1.5 2003/08/26 01:00:29 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* By Gerald Combs <gerald@ethereal.com>
* 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
@ -49,8 +48,10 @@
#define NSAP_IDI_GOSIP2 0x47
gchar* print_nsap_net ( const guint8 *, int );
void print_nsap_net_buf( const guint8 *, int, gchar * );
gchar* print_area ( const guint8 *, int );
void print_area_buf ( const guint8 *, int, gchar * );
gchar* print_system_id( const guint8 *, int );
void print_system_id_buf( const guint8 *, int, gchar * );
#endif /* __OSI_UTILS_H__ */

View File

@ -2,13 +2,12 @@
* Routines for SNA
* Gilbert Ramirez <gram@alumni.rice.edu>
*
* $Id: sna-utils.c,v 1.4 2002/08/28 20:40:45 jmayer Exp $
* $Id: sna-utils.c,v 1.5 2003/08/26 01:00:30 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* By Gerald Combs <gerald@ethereal.com>
* 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
@ -24,17 +23,18 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include "packet_info.h"
#include "pint.h"
#include "sna-utils.h"
/* FID Type 4 */
gchar *
sna_fid_type_4_addr_to_str(const struct sna_fid_type_4_addr *addrp)
sna_fid_to_str(const address *addr)
{
static gchar str[3][14];
static gchar *cur;
@ -46,8 +46,30 @@ sna_fid_type_4_addr_to_str(const struct sna_fid_type_4_addr *addrp)
} else {
cur = &str[0][0];
}
sprintf(cur, "%08X.%04X", addrp->saf, addrp->ef);
sna_fid_to_str_buf(addr, cur);
return cur;
}
void
sna_fid_to_str_buf(const address *addr, gchar *buf)
{
struct sna_fid_type_4_addr sna_fid_type_4_addr;
switch (addr->len) {
case 1:
sprintf(buf, "%04X", addr->data[0]);
break;
case 2:
sprintf(buf, "%04X", pntohs(&addr->data[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);
sprintf(buf, "%08X.%04X", sna_fid_type_4_addr.saf,
sna_fid_type_4_addr.ef);
break;
}
}

View File

@ -1,7 +1,7 @@
/* sna-utils.h
* Definitions for SNA dissection.
*
* $Id: sna-utils.h,v 1.3 2002/08/28 20:40:45 jmayer Exp $
* $Id: sna-utils.h,v 1.4 2003/08/26 01:00:30 guy Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -35,9 +35,7 @@ struct sna_fid_type_4_addr {
guint16 ef;
};
/*
* Routine to take an SNA FID Type 4 address and generate a string.
*/
extern gchar *sna_fid_type_4_addr_to_str(const struct sna_fid_type_4_addr *addrp);
extern gchar *sna_fid_to_str(const address *addr);
extern void sna_fid_to_str_buf(const address *addr, gchar *buf);
#endif

View File

@ -1,7 +1,7 @@
/* to_str.c
* Routines for utilities to convert various other types to strings.
*
* $Id: to_str.c,v 1.35 2003/08/24 20:30:46 guy Exp $
* $Id: to_str.c,v 1.36 2003/08/26 01:00:30 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -60,6 +60,8 @@
#include "to_str.h"
#include "resolv.h"
#include "pint.h"
#include "atalk-utils.h"
#include "sna-utils.h"
#include <stdio.h>
#include <time.h>
@ -296,11 +298,16 @@ vines_addr_to_str(const guint8 *addrp)
} else {
cur = &str[0][0];
}
sprintf(cur, "%08x.%04x", pntohl(&addrp[0]), pntohs(&addrp[4]));
vines_addr_to_str_buf(addrp, cur);
return cur;
}
void
vines_addr_to_str_buf(const guint8 *addrp, gchar *buf)
{
sprintf(buf, "%08x.%04x", pntohl(&addrp[0]), pntohs(&addrp[4]));
}
#define PLURALIZE(n) (((n) > 1) ? "s" : "")
#define COMMA(do_it) ((do_it) ? ", " : "")
@ -757,35 +764,48 @@ address_to_str(address *addr)
}
strp=str[i];
switch(addr->type){
case AT_NONE: /* nothing to print - or should it just return a null string? */
break;
case AT_ETHER:
sprintf(strp, "%02x:%02x:%02x:%02x:%02x:%02x", addr->data[0], addr->data[1], addr->data[2], addr->data[3], addr->data[4], addr->data[5]);
return strp;
case AT_IPv4:
ip_to_str_buf(addr->data, strp);
return strp;
case AT_IPv6:
inet_ntop(AF_INET6, addr->data, strp, INET6_ADDRSTRLEN);
return strp;
case AT_IPX:
sprintf(strp, "%02x%02x%02x%02x.%02x%02x%02x%02x%02x%02x", addr->data[0], addr->data[1], addr->data[2], addr->data[3], addr->data[4], addr->data[5], addr->data[6], addr->data[7], addr->data[8], addr->data[9]);
return strp;
case AT_SNA:
case AT_ATALK:
case AT_VINES:
case AT_OSI:
break; /* XXX - implement me */
case AT_ARCNET:
sprintf(strp, "0x%02X", addr->data[0]);
return strp;
case AT_FC:
sprintf(strp, "%02x.%02x.%02x", addr->data[0], addr->data[1], addr->data[2]);
return strp;
}
/* unknown type of address */
g_assert_not_reached();
return NULL;
address_to_str_buf(addr, strp);
return strp;
}
void
address_to_str_buf(address *addr, gchar *buf)
{
struct atalk_ddp_addr ddp_addr;
switch(addr->type){
case AT_ETHER:
sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", addr->data[0], addr->data[1], addr->data[2], addr->data[3], addr->data[4], addr->data[5]);
break;
case AT_IPv4:
ip_to_str_buf(addr->data, buf);
break;
case AT_IPv6:
inet_ntop(AF_INET6, addr->data, buf, INET6_ADDRSTRLEN);
break;
case AT_IPX:
sprintf(buf, "%02x%02x%02x%02x.%02x%02x%02x%02x%02x%02x", addr->data[0], addr->data[1], addr->data[2], addr->data[3], addr->data[4], addr->data[5], addr->data[6], addr->data[7], addr->data[8], addr->data[9]);
break;
case AT_SNA:
sna_fid_to_str_buf(addr, buf);
break;
case AT_ATALK:
memcpy(&ddp_addr, addr->data, sizeof ddp_addr);
atalk_addr_to_str_buf(&ddp_addr, buf);
break;
case AT_VINES:
vines_addr_to_str_buf(addr->data, buf);
break;
case AT_OSI:
print_nsap_net_buf(addr->data, addr->len, buf);
break;
case AT_ARCNET:
sprintf(buf, "0x%02X", addr->data[0]);
break;
case AT_FC:
sprintf(buf, "%02x.%02x.%02x", addr->data[0], addr->data[1], addr->data[2]);
break;
default:
g_assert_not_reached();
}
}

View File

@ -1,7 +1,7 @@
/* to_str.h
* Definitions for utilities to convert various other types to strings.
*
* $Id: to_str.h,v 1.18 2003/08/24 02:50:31 sahlberg Exp $
* $Id: to_str.h,v 1.19 2003/08/26 01:00:30 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -47,6 +47,7 @@ typedef enum {
struct e_in6_addr;
extern gchar* address_to_str(address *);
extern void address_to_str_buf(address *, gchar *);
extern gchar* ether_to_str(const guint8 *);
extern gchar* ip_to_str(const guint8 *);
extern void ip_to_str_buf(const guint8 *, gchar *);
@ -57,6 +58,7 @@ extern gchar* ipx_addr_to_str(guint32, const guint8 *);
extern gchar* ipxnet_to_string(const guint8 *ad);
extern gchar* ipxnet_to_str_punct(const guint32 ad, char punct);
extern gchar* vines_addr_to_str(const guint8 *addrp);
extern void vines_addr_to_str_buf(const guint8 *addrp, gchar *buf);
extern gchar* time_secs_to_str(guint32);
extern gchar* time_msecs_to_str(guint32);
extern gchar* abs_time_to_str(nstime_t*);

View File

@ -1,7 +1,7 @@
/* packet-sna.h
* Definitions for SNA dissection.
*
* $Id: packet-sna.h,v 1.5 2002/08/28 21:00:34 jmayer Exp $
* $Id: packet-sna.h,v 1.6 2003/08/26 01:00:28 guy Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -32,9 +32,4 @@ struct sna_fid_type_4_addr {
guint16 ef;
};
/*
* Routine to take an SNA FID Type 4 address and generate a string.
*/
extern gchar *sna_fid_type_4_addr_to_str(const struct sna_fid_type_4_addr *addrp);
#endif