A lengthy patch to add the wiretap library. Wiretap is not used by default
[obnox/wireshark/wip.git] / packet-null.c
1 /* packet-null.c
2  * Routines for null packet disassembly
3  *
4  * $Id: packet-null.c,v 1.4 1998/11/12 00:06:34 gram Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  *
9  * This file created and by Mike Hall <mlh@io.com>
10  * Copyright 1998
11  * 
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.
16  * 
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.
21  * 
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
33 #endif
34
35 #include <gtk/gtk.h>
36 #include <stdio.h>
37 #include <sys/socket.h>
38
39 #include "ethereal.h"
40 #include "packet.h"
41
42 void
43 dissect_null( const u_char *pd, frame_data *fd, GtkTree *tree ) {
44   e_nullhdr  nh;
45   GtkWidget *ti, *fh_tree;
46
47   nh.null_next   = pd[0];
48   nh.null_len    = pd[1];
49   memcpy((char *)&nh.null_family, (char *)&pd[2], sizeof(nh.null_family));
50
51   /* load the top pane info. This should be overwritten by
52      the next protocol in the stack */
53   if(fd->win_info[COL_NUM]) {
54     strcpy(fd->win_info[COL_SOURCE], "N/A" );
55     strcpy(fd->win_info[COL_DESTINATION], "N/A" );
56     strcpy(fd->win_info[COL_PROTOCOL], "N/A" );
57     strcpy(fd->win_info[COL_INFO], "Null/Loopback" );
58   }
59
60   /* populate a tree in the second pane with the status of the link
61      layer (ie none) */
62   if(tree) {
63     ti = add_item_to_tree( GTK_WIDGET(tree), 0, 4,
64       "Null/Loopback" );
65     fh_tree = gtk_tree_new();
66     add_subtree(ti, fh_tree, ETT_NULL);
67     add_item_to_tree(fh_tree, 0, 1, "Next: %02x", nh.null_next);
68     add_item_to_tree(fh_tree, 1, 1, "Length: %02x", nh.null_len);
69     add_item_to_tree(fh_tree, 2, 2, "Family: %04x", nh.null_family);
70   }
71
72   /* 
73   From what I've read in various sources, this is supposed to be an
74   address family, e.g. AF_INET.  However, a FreeBSD ISDN PPP dump that
75   Andreas Klemm sent to ethereal-dev has a packet type of DLT_NULL, and
76   the family bits look like PPP's protocol field.  A dump of the loopback
77   interface on my Linux box also has a link type of DLT_NULL (as it should
78   be), but the family bits look like ethernet's protocol type.  To
79   further  confuse matters, nobody seems to be paying attention to byte
80   order.
81   - gcc
82   */  
83    
84   switch (nh.null_family) {
85     case 0x0008:
86     case 0x0800:
87     case 0x0021:
88     case 0x2100:
89       dissect_ip(pd, 4, fd, tree);
90       break;
91     default:
92       dissect_data(pd, 4, fd, tree);
93       break;
94   }
95 }