2 * Routines for ISO/OSI network and transport protocol packet disassembly
3 * Main entrance point and common functions
5 * Laurent Deniel <laurent.deniel@free.fr>
6 * Ralf Schneider <Ralf.Schneider@t-online.de>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #include "osi-utils.h"
38 * XXX - shouldn't there be a centralized routine for dissecting NSAPs?
39 * See also "dissect_atm_nsap()" in epan/dissectors/packet-arp.c and
40 * "dissect_nsap()" in epan/dissectors/packet-isup.c.
43 print_nsap_net( const guint8 *ad, int length )
47 cur = (gchar *)ep_alloc(MAX_NSAP_LEN * 3 + 50);
48 print_nsap_net_buf( ad, length, cur, MAX_NSAP_LEN * 3 + 50);
52 /* XXX - Should these be converted to string buffers? */
54 print_nsap_net_buf( const guint8 *ad, int length, gchar *buf, int buf_len)
58 /* to do : NSAP / NET decoding */
60 if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
61 g_snprintf(buf, buf_len, "<Invalid length of NSAP>");
65 if ( ( length == RFC1237_NSAP_LEN ) || ( length == RFC1237_NSAP_LEN + 1 ) ) {
66 print_area_buf(ad, RFC1237_FULLAREA_LEN, cur, buf_len);
68 print_system_id_buf( ad + RFC1237_FULLAREA_LEN, RFC1237_SYSTEMID_LEN, cur, (int) (buf_len-(cur-buf)));
70 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x]",
71 ad[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
72 if ( length == RFC1237_NSAP_LEN + 1 ) {
73 g_snprintf(cur, (int) (buf_len-(cur-buf)), "-%02x", ad[ length -1 ] );
76 else { /* probably format as standard */
77 print_area_buf( ad, length, buf, buf_len);
82 print_system_id( const guint8 *ad, int length )
86 cur = (gchar *)ep_alloc(MAX_SYSTEMID_LEN * 3 + 5);
87 print_system_id_buf(ad, length, cur, MAX_SYSTEMID_LEN * 3 + 5);
92 tvb_print_system_id( tvbuff_t *tvb, const gint offset, int length )
94 return( print_system_id(tvb_get_ptr(tvb, offset, length), length) );
98 print_system_id_buf( const guint8 *ad, int length, gchar *buf, int buf_len)
103 if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
104 g_snprintf(buf, buf_len, "<Invalid length of SYSTEM ID>");
109 if ( ( 6 == length ) || /* System-ID */
110 ( 7 == length ) || /* LAN-ID */
111 ( 8 == length )) { /* LSP-ID */
112 cur += g_snprintf(cur, buf_len, "%02x%02x.%02x%02x.%02x%02x", ad[0], ad[1],
113 ad[2], ad[3], ad[4], ad[5] );
114 if ( ( 7 == length ) ||
116 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), ".%02x", ad[6] );
119 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-%02x", ad[7] );
124 while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */
125 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
126 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
127 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
128 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x.", ad[tmp++] );
130 if ( 1 == tmp ) { /* Special case for Designated IS */
132 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), ".%02x", ad[tmp] );
135 for ( ; tmp < length; ) { /* print the rest without dot */
136 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
143 print_area(const guint8 *ad, int length)
147 cur = (gchar *)ep_alloc(MAX_AREA_LEN * 3 + 20);
148 print_area_buf(ad, length, cur, MAX_AREA_LEN * 3 + 20);
153 print_area_buf(const guint8 *ad, int length, gchar *buf, int buf_len)
158 /* to do : all real area decoding now: NET is assumed if id len is 1 more byte
159 * and take away all these stupid resource consuming local statics
161 if (length <= 0 || length > MAX_AREA_LEN) {
162 g_snprintf(buf, buf_len, "<Invalid length of AREA>");
167 if ( ( ( NSAP_IDI_ISODCC == *ad )
168 || ( NSAP_IDI_GOSIP2 == *ad )
171 ( ( RFC1237_FULLAREA_LEN == length )
172 || ( RFC1237_FULLAREA_LEN + 1 == length )
174 ) { /* AFI is good and length is long enough */
176 /* there used to be a check for (length > RFC1237_FULLAREA_LEN + 1) here,
177 * in order to report an invalied length of AREA for DCC / GOSIP AFI,
178 * but that can *never* be the case because the if() test above explicitly
179 * tests for (length == RFC1237_FULLAREA_LEN) or (length == RFC1237_FULLAREA_LEN + 1)
182 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x|%02x:%02x][%02x|%02x:%02x:%02x|%02x:%02x]",
183 ad[0], ad[1], ad[2], ad[3], ad[4],
184 ad[5], ad[6], ad[7], ad[8] );
185 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x:%02x|%02x:%02x]",
186 ad[9], ad[10], ad[11], ad[12] );
187 if ( RFC1237_FULLAREA_LEN + 1 == length )
188 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-[%02x]", ad[20] );
190 else { /* print standard format */
191 if ( length == RFC1237_AREA_LEN ) {
192 g_snprintf(buf, buf_len, "%02x.%02x%02x", ad[0], ad[1], ad[2] );
196 g_snprintf(buf, buf_len, "%02x%02x%02x%02x", ad[0], ad[1], ad[2], ad[3] );
199 while ( tmp < length / 4 ) { /* 16/4==4 > four Octets left to print */
200 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
201 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
202 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
203 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x.", ad[tmp++] );
205 if ( 1 == tmp ) { /* Special case for Designated IS */
207 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-%02x", ad[tmp] );
210 for ( ; tmp < length; ) { /* print the rest without dot or dash */
211 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
215 } /* print_area_buf */