Removed all references to gtk objects from packet*.[ch] files. They now
[obnox/wireshark/wip.git] / packet-ppp.c
1 /* packet-ppp.c
2  * Routines for ppp packet disassembly
3  *
4  * $Id: packet-ppp.c,v 1.10 1999/03/23 03:14:43 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 <glib.h>
36 #include "packet.h"
37
38 /* PPP structs and definitions */
39
40 typedef struct _e_ppphdr {
41   guint8  ppp_addr;
42   guint8  ppp_ctl;
43   guint16 ppp_prot;
44 } e_ppphdr;
45
46
47 /* Protocol types, from Linux "ppp_defs.h" and
48
49         http://www.isi.edu/in-notes/iana/assignments/ppp-numbers
50
51  */
52 #define PPP_IP          0x21    /* Internet Protocol */
53 #define PPP_AT          0x29    /* AppleTalk Protocol */
54 #define PPP_IPX         0x2b    /* IPX protocol */
55 #define PPP_VJC_COMP    0x2d    /* VJ compressed TCP */
56 #define PPP_VJC_UNCOMP  0x2f    /* VJ uncompressed TCP */
57 #define PPP_VINES       0x35    /* Banyan Vines */
58 #define PPP_IPV6        0x57    /* Internet Protocol Version 6 */
59 #define PPP_COMP        0xfd    /* compressed packet */
60 #define PPP_IPCP        0x8021  /* IP Control Protocol */
61 #define PPP_ATCP        0x8029  /* AppleTalk Control Protocol */
62 #define PPP_IPXCP       0x802b  /* IPX Control Protocol */
63 #define PPP_CCP         0x80fd  /* Compression Control Protocol */
64 #define PPP_LCP         0xc021  /* Link Control Protocol */
65 #define PPP_PAP         0xc023  /* Password Authentication Protocol */
66 #define PPP_LQR         0xc025  /* Link Quality Report protocol */
67 #define PPP_CHAP        0xc223  /* Cryptographic Handshake Auth. Protocol */
68 #define PPP_CBCP        0xc029  /* Callback Control Protocol */
69
70 void
71 capture_ppp( const u_char *pd, guint32 cap_len, packet_counts *ld ) {
72   switch (pntohs(&pd[2])) {
73     case PPP_IP:
74       capture_ip(pd, 4, cap_len, ld);
75       break;
76     default:
77       ld->other++;
78       break;
79   }
80 }
81
82 void
83 dissect_ppp( const u_char *pd, frame_data *fd, proto_tree *tree ) {
84   e_ppphdr   ph;
85   proto_tree *fh_tree;
86   proto_item *ti;
87
88   static const value_string ppp_vals[] = {
89     {PPP_IP,     "IP"             },
90     {PPP_AT,     "Appletalk"      },
91     {PPP_IPX,    "Netware IPX/SPX"},
92     {PPP_VINES,  "Vines"          },
93     {PPP_IPV6,   "IPv6"           },
94     {0,           NULL            } };
95
96   ph.ppp_addr = pd[0];
97   ph.ppp_ctl  = pd[1];
98   ph.ppp_prot = pntohs(&pd[2]);
99
100   /* load the top pane info. This should be overwritten by
101      the next protocol in the stack */
102   if(check_col(fd, COL_RES_DL_SRC))
103     col_add_str(fd, COL_RES_DL_SRC, "N/A" );
104   if(check_col(fd, COL_RES_DL_DST))
105     col_add_str(fd, COL_RES_DL_DST, "N/A" );
106   if(check_col(fd, COL_PROTOCOL))
107     col_add_str(fd, COL_PROTOCOL, "N/A" );
108   if(check_col(fd, COL_INFO))
109     col_add_str(fd, COL_INFO, "PPP" );
110
111   /* populate a tree in the second pane with the status of the link
112      layer (ie none) */
113   if(tree) {
114     ti = proto_tree_add_item(tree, 0, 4, "Point-to-Point Protocol" );
115     fh_tree = proto_tree_new();
116     proto_item_add_subtree(ti, fh_tree, ETT_PPP);
117     proto_tree_add_item(fh_tree, 0, 1, "Address: %02x", ph.ppp_addr);
118     proto_tree_add_item(fh_tree, 1, 1, "Control: %02x", ph.ppp_ctl);
119     proto_tree_add_item(fh_tree, 2, 2, "Protocol: %s (0x%04x)",
120       val_to_str(ph.ppp_prot, ppp_vals, "Unknown"), ph.ppp_prot);
121   }
122
123   switch (ph.ppp_prot) {
124     case PPP_IP:
125       dissect_ip(pd, 4, fd, tree);
126       break;
127     case PPP_AT:
128       dissect_ddp(pd, 4, fd, tree);
129       break;
130     case PPP_IPX:
131       dissect_ipx(pd, 4, fd, tree);
132       break;
133     case PPP_VINES:
134       dissect_vines(pd, 4, fd, tree);
135       break;
136     case PPP_IPV6:
137       dissect_ipv6(pd, 4, fd, tree);
138       break;
139     default:
140       dissect_data(pd, 4, fd, tree);
141       if (check_col(fd, COL_PROTOCOL))
142         col_add_fstr(fd, COL_PROTOCOL, "0x%04x", ph.ppp_prot);
143       break;
144   }
145 }