aboutsummaryrefslogtreecommitdiffstats
path: root/packet-llc.c
blob: c5a7cff8595580480e7ce88c53cc14d5760cd340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* packet-llc.c
 * Routines for IEEE 802.2 LLC layer
 * Gilbert Ramirez <gram@verdict.uthscsa.edu>
 *
 * $Id: packet-llc.c,v 1.3 1998/09/17 02:01:47 gerald Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@unicom.net>
 * 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

#include <pcap.h>

#include <gtk/gtk.h>

#include <stdio.h>

#include "packet.h"
#include "ethereal.h"
#include "etypes.h"

struct sap_info {
	u_char	sap;
	char	*text;
};

static char*
sap_text(u_char sap) {
	int i=0;

	static struct sap_info	saps[] = {
		{ 0x00, "NULL LSAP" },
		{ 0x02, "LLC Sub-Layer Management Individual" },
		{ 0x03, "LLC Sub-Layer Management Group" },
		{ 0x04, "SNA Path Control Individual" },
		{ 0x05, "SNA Path Control Group" },
		{ 0x06, "TCP/IP" },
		{ 0x08, "SNA" },
		{ 0x0C, "SNA" },
		{ 0x42, "Spanning Tree BPDU" },
		{ 0x7F, "ISO 802.2" },
		{ 0x80, "XNS" },
		{ 0xAA, "SNAP" },
		{ 0xBA, "Banyan Vines" },
		{ 0xBC, "Banyan Vines" },
		{ 0xE0, "NetWare" },
		{ 0xF0, "NetBIOS" },
		{ 0xF4, "IBM Net Management Individual" },
		{ 0xF5, "IBM Net Management Group" },
		{ 0xF8, "Remote Program Load" },
		{ 0xFC, "Remote Program Load" },
		{ 0xFE, "ISO Network Layer" },
		{ 0xFF, "Global LSAP" },
		{ 0x00, NULL }
	};

	while (saps[i].text != NULL) {
		if (saps[i].sap == sap) {
			return saps[i].text;
		}
		i++;
	}
	return "Unknown";
}

static char*
llc_org(const u_char *ptr) {

	unsigned long org = (ptr[0] << 16) | (ptr[1] << 8) | ptr[2];
	char *llc_org[1] = {
		"Encapsulated Ethernet"};

	if (org > 0) {
		return "Unknown";
	}
	else {
		return llc_org[org];
	}
}

void
dissect_llc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {

	GtkWidget	*llc_tree, *ti;
	guint16		etype;
	int			is_snap;

	/* LLC Strings */
	char *llc_ctrl[4] = {
		"Information Transfer", "Supervisory",
		"", "Unnumbered Information" };

	is_snap = (pd[offset] == 0xAA) && (pd[offset+1] == 0xAA);

	if (fd->win_info[0]) {
		strcpy(fd->win_info[3], "LLC");
	}
  
	if (tree) {
		ti = add_item_to_tree(GTK_WIDGET(tree), offset, (is_snap ? 8 : 3),
			"Logical-Link Control");
		llc_tree = gtk_tree_new();
		add_subtree(ti, llc_tree, ETT_LLC);
		add_item_to_tree(llc_tree, offset,      1, "DSAP: %s (0x%02X)",
			sap_text(pd[offset]), pd[offset]);
		add_item_to_tree(llc_tree, offset+1,    1, "SSAP: %s (0x%02X)",
			sap_text(pd[offset+1]), pd[offset+1]);
		add_item_to_tree(llc_tree, offset+2,    1, "Control: %s",
			llc_ctrl[pd[offset+2] & 3]);
	}

	if (is_snap) {
		if (fd->win_info[0]) {
			strcpy(fd->win_info[4], "802.2 LLC (SNAP)");
		}
		if (tree) {
			add_item_to_tree(llc_tree, offset+3,    3,
				"Organization Code: %s (%02X-%02X-%02X)",
				llc_org(&pd[offset+3]), 
				pd[offset+3], pd[offset+4], pd[offset+5]);
		}
		etype  = (pd[offset+6] << 8) | pd[offset+7];
		offset += 8;
		ethertype(etype, offset, pd, fd, tree, llc_tree);
	}		
	else {
		if (fd->win_info[0]) {
			sprintf(fd->win_info[4], "802.2 LLC (%s)", sap_text(pd[offset]));
		}

		/* non-SNAP */
		offset += 3;

		switch (pd[offset-3]) {
			case 0x06:	/* TCP/IP */
				dissect_ip(pd, offset, fd, tree);
				break;
			case 0xe0:	/* NetWare (IPX) */
				dissect_ipx(pd, offset, fd, tree);
				break;
			case 0xfe:      /* ISO Network Layer */
				dissect_osi(pd, offset, fd, tree);
				break;
			default:
				dissect_data(pd, offset, fd, tree);
				break;
		  }
	}
}