2 * Routines for ISO/OSI network and transport protocol packet disassembly
3 * Main entrance point and common functions
5 * $Id: osi-utils.c,v 1.14 2003/11/20 19:05:40 guy Exp $
6 * Laurent Deniel <laurent.deniel@free.fr>
7 * Ralf Schneider <Ralf.Schneider@t-online.de>
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include "osi-utils.h"
39 print_nsap_net( const guint8 *ad, int length )
41 static gchar str[MAX_NSAP_LEN * 3 + 50]; /* reserve space for nice layout */
45 print_nsap_net_buf( ad, length, cur );
50 print_nsap_net_buf( const guint8 *ad, int length, gchar *buf )
54 /* to do : NSAP / NET decoding */
56 if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
57 sprintf( buf, "<Invalid length of NSAP>");
61 if ( ( length == RFC1237_NSAP_LEN ) || ( length == RFC1237_NSAP_LEN + 1 ) ) {
62 print_area_buf( ad, RFC1237_FULLAREA_LEN, cur );
64 print_system_id_buf( ad + RFC1237_FULLAREA_LEN, RFC1237_SYSTEMID_LEN, cur );
66 cur += sprintf( cur, "[%02x]",
67 ad[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
68 if ( length == RFC1237_NSAP_LEN + 1 ) {
69 cur += sprintf( cur, "-%02x", ad[ length -1 ] );
72 else { /* probably format as standard */
73 print_area_buf( ad, length, buf );
78 print_system_id( const guint8 *ad, int length )
80 static gchar str[MAX_SYSTEMID_LEN * 3 + 5]; /* Don't trust exact matching */
84 print_system_id_buf(ad, length, cur );
89 print_system_id_buf( const guint8 *ad, int length, gchar *buf )
94 if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
95 sprintf( buf, "<Invalid length of SYSTEM ID>");
100 if ( ( 6 == length ) || /* System-ID */
101 ( 7 == length ) || /* LAN-ID */
102 ( 8 == length )) { /* LSP-ID */
103 cur += sprintf(cur, "%02x%02x.%02x%02x.%02x%02x", ad[0], ad[1],
104 ad[2], ad[3], ad[4], ad[5] );
105 if ( ( 7 == length ) ||
107 cur += sprintf( cur, ".%02x", ad[6] );
110 cur += sprintf( cur, "-%02x", ad[7] );
115 while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */
116 cur += sprintf( cur, "%02x", ad[tmp++] );
117 cur += sprintf( cur, "%02x", ad[tmp++] );
118 cur += sprintf( cur, "%02x", ad[tmp++] );
119 cur += sprintf( cur, "%02x.", ad[tmp++] );
121 if ( 1 == tmp ) { /* Special case for Designated IS */
122 sprintf( --cur, ".%02x", ad[tmp] );
125 for ( ; tmp < length; ) { /* print the rest without dot */
126 cur += sprintf( cur, "%02x", ad[tmp++] );
133 print_area(const guint8 *ad, int length)
135 static gchar str[MAX_AREA_LEN * 3 + 20]; /* reserve space for nice layout */
139 print_area_buf( ad, length, cur );
144 print_area_buf(const guint8 *ad, int length, gchar *buf)
149 /* to do : all real area decoding now: NET is assumed if id len is 1 more byte
150 * and take away all these stupid resource consuming local statics
152 if (length <= 0 || length > MAX_AREA_LEN) {
153 sprintf( buf, "<Invalid length of AREA>");
158 if ( ( ( NSAP_IDI_ISODCC == *ad )
159 || ( NSAP_IDI_GOSIP2 == *ad )
162 ( ( RFC1237_FULLAREA_LEN == length )
163 || ( RFC1237_FULLAREA_LEN + 1 == length )
165 ) { /* AFI is good and length is long enough */
167 if ( length > RFC1237_FULLAREA_LEN + 1 ) { /* Special Case Designated IS */
168 sprintf( buf, "<Invalid length of AREA for DCC / GOSIP AFI>");
172 cur += sprintf( cur, "[%02x|%02x:%02x][%02x|%02x:%02x:%02x|%02x:%02x]",
173 ad[0], ad[1], ad[2], ad[3], ad[4],
174 ad[5], ad[6], ad[7], ad[8] );
175 cur += sprintf( cur, "[%02x:%02x|%02x:%02x]",
176 ad[9], ad[10], ad[11], ad[12] );
177 if ( RFC1237_FULLAREA_LEN + 1 == length )
178 sprintf( cur, "-[%02x]", ad[20] );
180 else { /* print standard format */
181 if ( length == RFC1237_AREA_LEN ) {
182 sprintf( buf, "%02x.%02x%02x", ad[0], ad[1], ad[2] );
186 while ( tmp < length / 4 ) { /* 16/4==4 > four Octets left to print */
187 cur += sprintf( cur, "%02x", ad[tmp++] );
188 cur += sprintf( cur, "%02x", ad[tmp++] );
189 cur += sprintf( cur, "%02x", ad[tmp++] );
190 cur += sprintf( cur, "%02x.", ad[tmp++] );
192 if ( 1 == tmp ) { /* Special case for Designated IS */
193 sprintf( --cur, "-%02x", ad[tmp] );
196 for ( ; tmp < length; ) { /* print the rest without dot */
197 cur += sprintf( cur, "%02x", ad[tmp++] );
202 } /* print_area_buf */