Switch a bunch of dissectors over to using tvb_new_subset_remaining()
[obnox/wireshark/wip.git] / epan / dissectors / packet-pcli.c
1 /* packet-pcli.c
2  * Routines for Packet Cable Lawful Intercept packet disassembly
3  * Packet Cable Lawful Intercept is detailed at
4  * http://www.packetcable.com/downloads/specs/pkt-sp-esp-I01-991229.pdf
5  * Chapter 4 ( Call Content Connection Interface )
6  *
7  * $Id$
8  *
9  * Copyright (c) 2000 by Ed Warnicke <hagbard@physics.rutgers.edu>
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1999 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 /* Include files */
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <ctype.h>
39 #include <time.h>
40 #include <string.h>
41
42 #include <glib.h>
43 #include <epan/packet.h>
44 #include <epan/addr_resolv.h>
45 #include <epan/prefs.h>
46 #include <epan/strutil.h>
47
48 /* Define udp_port for lawful intercept */
49
50 #define UDP_PORT_PCLI 9000
51
52 void proto_reg_handoff_pcli(void);
53
54 /* Define the pcli proto */
55
56 static int proto_pcli = -1;
57
58 /* Define headers for pcli */
59
60 static int hf_pcli_cccid = -1;
61
62 /* Define the tree for pcli */
63
64 static int ett_pcli = -1;
65
66 /* 
67  * Here are the global variables associated with the preferences
68  * for pcli
69  */
70
71 static guint global_udp_port_pcli = UDP_PORT_PCLI;
72
73 /* A static handle for the ip dissector */
74 static dissector_handle_t ip_handle;
75
76 static void 
77 dissect_pcli(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
78   
79   guint32 cccid;
80   proto_tree *ti,*pcli_tree;
81   tvbuff_t * next_tvb;
82
83   /* Set the protocol column */
84   if(check_col(pinfo->cinfo,COL_PROTOCOL)){
85     col_add_str(pinfo->cinfo,COL_PROTOCOL,"PCLI");
86   }
87
88   /* Get the CCCID */
89   cccid = tvb_get_ntohl(tvb,0);
90
91   /* Set the info column */
92   if(check_col(pinfo->cinfo,COL_INFO)){
93     col_add_fstr(pinfo->cinfo, COL_INFO, "CCCID: %u",cccid);
94   }
95
96   /* 
97    *If we have a non-null tree (ie we are building the proto_tree
98    * instead of just filling out the columns ), then add a PLCI
99    * tree node and put a CCCID header element under it.
100    */
101   if(tree) {
102     ti = proto_tree_add_item(tree,proto_pcli,tvb,0,0,FALSE);
103     pcli_tree = proto_item_add_subtree(ti,ett_pcli);
104     proto_tree_add_uint(pcli_tree,hf_pcli_cccid,tvb,
105                         0,4,cccid);
106   }
107
108   /*
109    * Hand off to the IP dissector.
110    */
111   next_tvb = tvb_new_subset_remaining(tvb,4);
112   call_dissector(ip_handle,next_tvb,pinfo,tree);
113 }
114
115 void 
116 proto_register_pcli(void) {
117   static hf_register_info hf[] = {
118     { &hf_pcli_cccid,
119       { "CCCID", "pcli.cccid", FT_UINT32, BASE_DEC, NULL, 0x0,
120         "Call Content Connection Identifier", HFILL }},
121   };
122
123   static gint *ett[] = {
124     &ett_pcli,
125   };
126
127   module_t *pcli_module;
128
129   proto_pcli = proto_register_protocol("Packet Cable Lawful Intercept",
130                                        "PCLI","pcli");
131   proto_register_field_array(proto_pcli,hf,array_length(hf));
132   proto_register_subtree_array(ett,array_length(ett));
133
134   pcli_module = prefs_register_protocol(proto_pcli,
135                                         proto_reg_handoff_pcli);
136   prefs_register_uint_preference(pcli_module, "udp_port",
137                                  "PCLI UDP Port",
138                                  "The UDP port on which "
139                                  "Packet Cable Lawful Intercept "
140                                  "packets will be sent",
141                                  10,&global_udp_port_pcli);
142
143 }
144
145 /* The registration hand-off routing */
146
147 void
148 proto_reg_handoff_pcli(void) {
149   static gboolean pcli_initialized = FALSE;
150   static dissector_handle_t pcli_handle;
151   static guint udp_port_pcli;
152
153   if(!pcli_initialized) {
154     pcli_handle = create_dissector_handle(dissect_pcli,proto_pcli);
155     ip_handle = find_dissector("ip");
156     pcli_initialized = TRUE;
157   } else {
158     dissector_delete("udp.port",udp_port_pcli,pcli_handle);
159   }
160
161   udp_port_pcli = global_udp_port_pcli;
162   
163   dissector_add("udp.port",global_udp_port_pcli,pcli_handle);
164 }