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"
36 #include "address_types.h"
39 * XXX - shouldn't there be a centralized routine for dissecting NSAPs?
40 * See also "dissect_atm_nsap()" in epan/dissectors/packet-arp.c and
41 * "dissect_nsap()" in epan/dissectors/packet-isup.c.
44 print_nsap_net( tvbuff_t *tvb, const gint offset, int length )
48 cur = (gchar *)wmem_alloc(wmem_packet_scope(), MAX_NSAP_LEN * 3 + 50);
49 print_nsap_net_buf( tvb_get_ptr(tvb, offset, length), length, cur, MAX_NSAP_LEN * 3 + 50);
53 /* XXX - Should these be converted to string buffers? */
55 print_nsap_net_buf( const guint8 *ad, int length, gchar *buf, int buf_len)
59 /* to do : NSAP / NET decoding */
61 if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
62 g_strlcpy(buf, "<Invalid length of NSAP>", buf_len);
66 if ( ( length == RFC1237_NSAP_LEN ) || ( length == RFC1237_NSAP_LEN + 1 ) ) {
67 print_area_buf(ad, RFC1237_FULLAREA_LEN, cur, buf_len);
69 print_system_id_buf( ad + RFC1237_FULLAREA_LEN, RFC1237_SYSTEMID_LEN, cur, (int) (buf_len-(cur-buf)));
71 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x]",
72 ad[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
73 if ( length == RFC1237_NSAP_LEN + 1 ) {
74 g_snprintf(cur, (int) (buf_len-(cur-buf)), "-%02x", ad[ length -1 ] );
77 else { /* probably format as standard */
78 print_area_buf( ad, length, buf, buf_len);
83 print_system_id(wmem_allocator_t* scope, const guint8 *ad, int length )
87 cur = (gchar *)wmem_alloc(scope, MAX_SYSTEMID_LEN * 3 + 5);
88 print_system_id_buf(ad, length, cur, MAX_SYSTEMID_LEN * 3 + 5);
93 tvb_print_system_id( tvbuff_t *tvb, const gint offset, int length )
95 return( print_system_id(wmem_packet_scope(), tvb_get_ptr(tvb, offset, length), length) );
99 print_system_id_buf( const guint8 *ad, int length, gchar *buf, int buf_len)
104 if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
105 g_strlcpy(buf, "<Invalid length of SYSTEM ID>", buf_len);
110 if ( ( 6 == length ) || /* System-ID */
111 ( 7 == length ) || /* LAN-ID */
112 ( 8 == length )) { /* LSP-ID */
113 cur += g_snprintf(cur, buf_len, "%02x%02x.%02x%02x.%02x%02x", ad[0], ad[1],
114 ad[2], ad[3], ad[4], ad[5] );
115 if ( ( 7 == length ) ||
117 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), ".%02x", ad[6] );
120 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-%02x", ad[7] );
125 while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */
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++] );
129 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x.", ad[tmp++] );
131 if ( 1 == tmp ) { /* Special case for Designated IS */
133 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), ".%02x", ad[tmp] );
136 for ( ; tmp < length; ) { /* print the rest without dot */
137 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
144 print_area(tvbuff_t *tvb, const gint offset, int length)
148 cur = (gchar *)wmem_alloc(wmem_packet_scope(), MAX_AREA_LEN * 3 + 20);
149 print_area_buf(tvb_get_ptr(tvb, offset, length), length, cur, MAX_AREA_LEN * 3 + 20);
154 print_area_buf(const guint8 *ad, int length, gchar *buf, int buf_len)
159 /* to do : all real area decoding now: NET is assumed if id len is 1 more byte
160 * and take away all these stupid resource consuming local statics
162 if (length <= 0 || length > MAX_AREA_LEN) {
163 g_strlcpy(buf, "<Invalid length of AREA>", buf_len);
168 if ( ( ( NSAP_IDI_ISODCC == *ad )
169 || ( NSAP_IDI_GOSIP2 == *ad )
172 ( ( RFC1237_FULLAREA_LEN == length )
173 || ( RFC1237_FULLAREA_LEN + 1 == length )
175 ) { /* AFI is good and length is long enough */
177 /* there used to be a check for (length > RFC1237_FULLAREA_LEN + 1) here,
178 * in order to report an invalied length of AREA for DCC / GOSIP AFI,
179 * but that can *never* be the case because the if() test above explicitly
180 * tests for (length == RFC1237_FULLAREA_LEN) or (length == RFC1237_FULLAREA_LEN + 1)
183 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x|%02x:%02x][%02x|%02x:%02x:%02x|%02x:%02x]",
184 ad[0], ad[1], ad[2], ad[3], ad[4],
185 ad[5], ad[6], ad[7], ad[8] );
186 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x:%02x|%02x:%02x]",
187 ad[9], ad[10], ad[11], ad[12] );
188 if ( RFC1237_FULLAREA_LEN + 1 == length )
189 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-[%02x]", ad[20] );
191 else { /* print standard format */
192 if ( length == RFC1237_AREA_LEN ) {
193 g_snprintf(buf, buf_len, "%02x.%02x%02x", ad[0], ad[1], ad[2] );
197 g_snprintf(buf, buf_len, "%02x%02x%02x%02x", ad[0], ad[1], ad[2], ad[3] );
200 while ( tmp < length / 4 ) { /* 16/4==4 > four Octets left to print */
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++] );
204 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x.", ad[tmp++] );
206 if ( 1 == tmp ) { /* Special case for Designated IS */
208 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-%02x", ad[tmp] );
211 for ( ; tmp < length; ) { /* print the rest without dot or dash */
212 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
216 } /* print_area_buf */
218 /******************************************************************************
220 ******************************************************************************/
221 static int osi_address_type = -1;
223 static int osi_address_to_str(const address* addr, gchar *buf, int buf_len)
225 print_nsap_net_buf((const guint8 *)addr->data, addr->len, buf, buf_len);
226 return (int)strlen(buf)+1;
229 static int osi_address_str_len(const address* addr _U_)
231 return MAX_NSAP_LEN * 3 + 50;
234 int get_osi_address_type(void)
236 return osi_address_type;
239 void register_osi_address_type(void)
241 if (osi_address_type != -1)
244 osi_address_type = address_type_dissector_register("AT_OSI", "OSI Address", osi_address_to_str, osi_address_str_len, NULL, NULL, NULL, NULL);
254 * indent-tabs-mode: nil
257 * ex: set shiftwidth=2 tabstop=8 expandtab:
258 * :indentSize=2:tabSize=8:noTabs=true: