From 90f7f6184df0222e9159e6ae340958ea0dce8e52 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Sun, 1 Apr 2001 05:48:15 +0000 Subject: [PATCH] Moved some definitions and functions from packet-osi.{c,h} to epan/osi-utils.{c,h} to bring all of the epan dependencies into epan. svn path=/trunk/; revision=3226 --- epan/Makefile.am | 4 +- epan/osi-utils.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++ epan/osi-utils.h | 56 +++++++++++++++ epan/packet.c | 4 +- packet-osi.c | 129 +---------------------------------- packet-osi.h | 29 +------- 6 files changed, 236 insertions(+), 158 deletions(-) create mode 100644 epan/osi-utils.c create mode 100644 epan/osi-utils.h diff --git a/epan/Makefile.am b/epan/Makefile.am index 578862644f2..9d747318779 100644 --- a/epan/Makefile.am +++ b/epan/Makefile.am @@ -2,7 +2,7 @@ # Automake file for the EPAN library # (Ethereal Protocol ANalyzer Library) # -# $Id: Makefile.am,v 1.22 2001/04/01 04:50:42 hagbard Exp $ +# $Id: Makefile.am,v 1.23 2001/04/01 05:48:15 hagbard Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs @@ -54,6 +54,8 @@ libethereal_a_SOURCES = \ gdebug.h \ ipv4.c \ ipv4.h \ + osi-utils.c \ + osi-utils.h \ packet.c \ packet.h \ packet_info.c \ diff --git a/epan/osi-utils.c b/epan/osi-utils.c new file mode 100644 index 00000000000..95a7589d786 --- /dev/null +++ b/epan/osi-utils.c @@ -0,0 +1,172 @@ +/* osi-utils.c + * Routines for ISO/OSI network and transport protocol packet disassembly + * Main entrance point and common functions + * + * $Id: osi-utils.c,v 1.1 2001/04/01 05:48:15 hagbard Exp $ + * Laurent Deniel + * Ralf Schneider + * + * Ethereal - Network traffic analyzer + * By Gerald Combs + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#ifdef NEED_SNPRINTF_H +# include "snprintf.h" +#endif + +#include +#include + +#include "osi-utils.h" + +gchar *print_nsap_net( const u_char *buffer, int length) +{ + /* to do : NSAP / NET decoding */ + + static gchar str[MAX_NSAP_LEN * 3 + 50]; /* reserve space for nice layout */ + gchar *cur; + + cur = str; + + if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) { + sprintf( str, ""); + return( str ); + } + 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 ) ); + cur += sprintf( cur, "[%02x]", + buffer[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] ); + if ( length == RFC1237_NSAP_LEN + 1 ) { + cur += sprintf( cur, "-%02x", buffer[ length -1 ] ); + } + return ( str ); + } + else { /* probably format as standard */ + return( print_area( buffer, length ) ); + } +} /* print_nsap */ + + +gchar *print_system_id( const u_char *buffer, int length ) { + int tmp; + u_char *cur; + static gchar str[MAX_SYSTEMID_LEN * 3 + 5]; /* Don't trust exact matching */ + + if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) { + sprintf( str, ""); + return( str ); + } + + cur = str; + if ( ( 6 == length ) || ( 7 == length ) ) { /* Special case, print as MAC */ + cur += sprintf(str, "[%02x:%02x:%02x_%02x:%02x:%02x]", buffer[0], buffer[1], + buffer[2], buffer[3], buffer[4], buffer[5] ); + if ( 7 == length ) { + sprintf( cur, "-%02x", buffer[6] ); + } + } + else { + tmp = 0; + while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */ + cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++], + buffer[tmp++], buffer[tmp++] ); + } + if ( 1 == tmp ) { /* Special case for Designated IS */ + sprintf( --cur, "-%02x", buffer[tmp] ); + } + else { + for ( ; tmp < length; ) { /* print the rest without dot */ + cur += sprintf( cur, "%02x", buffer[tmp++] ); + } + } + } + return( str ); +} + +gchar *print_area(const u_char *buffer, 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; + u_int tmp = 0; + + cur = str; + + if (length <= 0 || length > MAX_AREA_LEN) { + sprintf( str, ""); + return( str ); + } + + if ( ( ( NSAP_IDI_ISODCC == *buffer ) + || ( NSAP_IDI_GOSIP2 == *buffer ) + ) + && + ( ( RFC1237_FULLAREA_LEN == length ) + || ( RFC1237_FULLAREA_LEN + 1 == length ) + ) + ) { /* AFI is good and length is long enough */ + + if ( length > RFC1237_FULLAREA_LEN + 1 ) { /* Special Case Designated IS */ + sprintf( str, ""); + return( str ); + } + + 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] ); + 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; + } + else { /* print standard format */ + if ( 4 < length ) { + while ( tmp < length / 4 ) { /* 16/4==4 four Octets left to print */ + cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++], + buffer[tmp++], buffer[tmp++] ); + } + if ( 1 == tmp ) { /* Special case for Designated IS */ + sprintf( --cur, "-%02x", buffer[tmp] ); + } + else { + for ( ; tmp < length; ) { /* print the rest without dot */ + cur += sprintf( cur, "%02x", buffer[tmp++] ); + } + } + } + return( str ); + } +} /* print_area */ + diff --git a/epan/osi-utils.h b/epan/osi-utils.h new file mode 100644 index 00000000000..e322b54d21f --- /dev/null +++ b/epan/osi-utils.h @@ -0,0 +1,56 @@ +/* packet-osi.h + * + * $Id: osi-utils.h,v 1.1 2001/04/01 05:48:15 hagbard Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __OSI_UTILS_H__ +#define __OSI_UTILS_H__ + +/* OSI Global defines, common for all OSI protocols */ + +#define MAX_NSAP_LEN 30 +#define MAX_SYSTEMID_LEN 15 +#define MAX_AREA_LEN 30 + +#define RFC1237_NSAP_LEN 20 +#define RFC1237_FULLAREA_LEN 13 +#define RFC1237_SYSTEMID_LEN 6 +#define RFC1237_SELECTOR_LEN 1 + +#define RFC1237_IDI_LEN 2 +#define RFC1237_AFI_LEN 1 +#define RFC1237_DFI_LEN 1 +#define RFC1237_ORG_LEN 3 +#define RFC1237_AA_LEN 3 +#define RFC1237_RSVD_LEN 2 +#define RFC1237_RD_LEN 2 +#define RFC1237_AREA_LEN 3 + +#define NSAP_IDI_ISODCC 0x39 +#define NSAP_IDI_GOSIP2 0x47 + +gchar* print_nsap_net ( const u_char *, int ); +gchar* print_area ( const u_char *, int ); +gchar* print_system_id( const u_char *, int ); + + +#endif /* __OSI_UTILS_H__ */ diff --git a/epan/packet.c b/epan/packet.c index cf678871e29..644f04898a5 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -1,7 +1,7 @@ /* packet.c * Routines for packet disassembly * - * $Id: packet.c,v 1.28 2001/04/01 04:50:42 hagbard Exp $ + * $Id: packet.c,v 1.29 2001/04/01 05:48:15 hagbard Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -76,7 +76,7 @@ #include "packet-ipv6.h" #include "sna-utils.h" #include "packet-vines.h" -#include "packet-osi.h" +#include "osi-utils.h" #include "to_str.h" #include "resolv.h" diff --git a/packet-osi.c b/packet-osi.c index e3588acb288..b24f1dcccb3 100644 --- a/packet-osi.c +++ b/packet-osi.c @@ -2,7 +2,7 @@ * Routines for ISO/OSI network and transport protocol packet disassembly * Main entrance point and common functions * - * $Id: packet-osi.c,v 1.41 2001/03/30 10:51:50 guy Exp $ + * $Id: packet-osi.c,v 1.42 2001/04/01 05:48:14 hagbard Exp $ * Laurent Deniel * Ralf Schneider * @@ -48,133 +48,6 @@ #include "packet-esis.h" -gchar *print_system_id( const u_char *buffer, int length ) { - int tmp; - u_char *cur; - static gchar str[MAX_SYSTEMID_LEN * 3 + 5]; /* Don't trust exact matching */ - - if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) { - sprintf( str, ""); - return( str ); - } - - cur = str; - if ( ( 6 == length ) || ( 7 == length ) ) { /* Special case, print as MAC */ - cur += sprintf(str, "[%02x:%02x:%02x_%02x:%02x:%02x]", buffer[0], buffer[1], - buffer[2], buffer[3], buffer[4], buffer[5] ); - if ( 7 == length ) { - sprintf( cur, "-%02x", buffer[6] ); - } - } - else { - tmp = 0; - while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */ - cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++], - buffer[tmp++], buffer[tmp++] ); - } - if ( 1 == tmp ) { /* Special case for Designated IS */ - sprintf( --cur, "-%02x", buffer[tmp] ); - } - else { - for ( ; tmp < length; ) { /* print the rest without dot */ - cur += sprintf( cur, "%02x", buffer[tmp++] ); - } - } - } - return( str ); -} - -gchar *print_area(const u_char *buffer, 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; - u_int tmp = 0; - - cur = str; - - if (length <= 0 || length > MAX_AREA_LEN) { - sprintf( str, ""); - return( str ); - } - - if ( ( ( NSAP_IDI_ISODCC == *buffer ) - || ( NSAP_IDI_GOSIP2 == *buffer ) - ) - && - ( ( RFC1237_FULLAREA_LEN == length ) - || ( RFC1237_FULLAREA_LEN + 1 == length ) - ) - ) { /* AFI is good and length is long enough */ - - if ( length > RFC1237_FULLAREA_LEN + 1 ) { /* Special Case Designated IS */ - sprintf( str, ""); - return( str ); - } - - 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] ); - 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; - } - else { /* print standard format */ - if ( 4 < length ) { - while ( tmp < length / 4 ) { /* 16/4==4 four Octets left to print */ - cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++], - buffer[tmp++], buffer[tmp++] ); - } - if ( 1 == tmp ) { /* Special case for Designated IS */ - sprintf( --cur, "-%02x", buffer[tmp] ); - } - else { - for ( ; tmp < length; ) { /* print the rest without dot */ - cur += sprintf( cur, "%02x", buffer[tmp++] ); - } - } - } - return( str ); - } -} /* print_area */ - - -gchar *print_nsap_net( const u_char *buffer, int length) -{ - /* to do : NSAP / NET decoding */ - - static gchar str[MAX_NSAP_LEN * 3 + 50]; /* reserve space for nice layout */ - gchar *cur; - - cur = str; - - if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) { - sprintf( str, ""); - return( str ); - } - 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 ) ); - cur += sprintf( cur, "[%02x]", - buffer[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] ); - if ( length == RFC1237_NSAP_LEN + 1 ) { - cur += sprintf( cur, "-%02x", buffer[ length -1 ] ); - } - return ( str ); - } - else { /* probably format as standard */ - return( print_area( buffer, length ) ); - } -} /* print_nsap */ - - gchar *calc_checksum( tvbuff_t *tvb, int offset, u_int len, u_int checksum) { u_int calc_sum = 0; u_int count = 0; diff --git a/packet-osi.h b/packet-osi.h index c7d1bbeed0f..6694ef1ef5f 100644 --- a/packet-osi.h +++ b/packet-osi.h @@ -1,6 +1,6 @@ /* packet-osi.h * - * $Id: packet-osi.h,v 1.6 2001/03/30 10:51:50 guy Exp $ + * $Id: packet-osi.h,v 1.7 2001/04/01 05:48:14 hagbard Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -25,29 +25,7 @@ #ifndef _PACKET_OSI_H #define _PACKET_OSI_H -/* OSI Global defines, common for all OSI protocols */ - -#define MAX_NSAP_LEN 30 -#define MAX_SYSTEMID_LEN 15 -#define MAX_AREA_LEN 30 - -#define RFC1237_NSAP_LEN 20 -#define RFC1237_FULLAREA_LEN 13 -#define RFC1237_SYSTEMID_LEN 6 -#define RFC1237_SELECTOR_LEN 1 - -#define RFC1237_IDI_LEN 2 -#define RFC1237_AFI_LEN 1 -#define RFC1237_DFI_LEN 1 -#define RFC1237_ORG_LEN 3 -#define RFC1237_AA_LEN 3 -#define RFC1237_RSVD_LEN 2 -#define RFC1237_RD_LEN 2 -#define RFC1237_AREA_LEN 3 - - -#define NSAP_IDI_ISODCC 0x39 -#define NSAP_IDI_GOSIP2 0x47 +#include "osi-utils.h" #define PDU_TYPE_ESIS_ESH 100 #define PDU_TYPE_ESIS_ISH 101 @@ -107,9 +85,6 @@ dissector_table_t osinl_subdissector_table; * published API functions */ -extern gchar *print_nsap_net ( const u_char *, int ); -extern gchar *print_area ( const u_char *, int ); -extern gchar *print_system_id( const u_char *, int ); extern gchar *calc_checksum ( tvbuff_t *, int, u_int, u_int ); #endif /* _PACKET_OSI_H */