2 * Routines for distcc dissection
3 * Copyright 2003, Brad Hards <bradh@frogmouth.net>
4 * Copyright 2003, Ronnie Sahlberg, added TCP desegmentation.
6 * $Id: packet-distcc.c,v 1.2 2003/05/24 20:49:58 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 /* This dissector supports version 1 of the DISTCC protocol */
39 #include <epan/packet.h>
40 #include <epan/strutil.h>
41 #include <epan/conversation.h>
46 static int proto_distcc = -1;
47 static int hf_distcc_version = -1;
48 static int hf_distcc_argc = -1;
49 static int hf_distcc_argv = -1;
50 static int hf_distcc_doti_source = -1;
51 static int hf_distcc_stat = -1;
52 static int hf_distcc_serr = -1;
53 static int hf_distcc_sout = -1;
54 static int hf_distcc_doto_object = -1;
57 static gint ett_distcc = -1;
59 static dissector_handle_t distcc_handle;
60 static dissector_handle_t data_handle;
63 static gboolean distcc_desegment = TRUE;
66 #define TCP_PORT_DISTCC 3632
68 static int glb_distcc_tcp_port = TCP_PORT_DISTCC;
71 #define CHECK_PDU_LEN(x) \
72 if(parameter>tvb_length_remaining(tvb, offset)){\
73 len=tvb_length_remaining(tvb, offset);\
74 if (check_col(pinfo->cinfo, COL_INFO)) {\
75 col_append_fstr(pinfo->cinfo, COL_INFO, "[Short" x " PDU]");\
80 #define DESEGMENT_TCP(x) \
81 if(distcc_desegment && pinfo->can_desegment){\
82 /* only attempt reassembly if whe have the full segment */\
83 if(tvb_length_remaining(tvb, offset)==tvb_reported_length_remaining(tvb, offset)){\
84 if(parameter>tvb_length_remaining(tvb, offset)){\
85 proto_tree_add_text(tree, tvb, offset-12, -1, "[Short " x " PDU]");\
86 pinfo->desegment_offset=offset-12;\
87 pinfo->desegment_len=parameter-tvb_length_remaining(tvb, offset);\
98 dissect_distcc_dist(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint32 parameter)
100 proto_tree_add_uint_format(tree, hf_distcc_version, tvb, offset-12, 12, parameter, "DIST: %d", parameter);
102 if (check_col(pinfo->cinfo, COL_INFO)) {
103 col_append_fstr(pinfo->cinfo, COL_INFO, "DIST:%d ", parameter);
110 dissect_distcc_done(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint32 parameter)
112 proto_tree_add_uint_format(tree, hf_distcc_version, tvb, offset-12, 12, parameter, "DONE: %d", parameter);
114 if (check_col(pinfo->cinfo, COL_INFO)) {
115 col_append_fstr(pinfo->cinfo, COL_INFO, "DONE:%d ", parameter);
122 dissect_distcc_stat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint32 parameter)
124 proto_tree_add_uint_format(tree, hf_distcc_stat, tvb, offset-12, 12, parameter, "STAT: %d", parameter);
126 if (check_col(pinfo->cinfo, COL_INFO)) {
127 col_append_fstr(pinfo->cinfo, COL_INFO, "STAT:%d ", parameter);
134 dissect_distcc_argc(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, guint32 parameter)
136 proto_tree_add_uint_format(tree, hf_distcc_argc, tvb, offset-12, 12, parameter, "ARGC: %d", parameter);
138 if (check_col(pinfo->cinfo, COL_INFO)) {
139 col_append_fstr(pinfo->cinfo, COL_INFO, "ARGC:%d ", parameter);
146 dissect_distcc_argv(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gint parameter)
153 CHECK_PDU_LEN("ARGV");
155 /* see if we need to desegment the PDU */
156 DESEGMENT_TCP("ARGV");
160 argv_len=len>255?255:len;
161 tvb_memcpy(tvb, argv, offset, argv_len);
164 proto_tree_add_item(tree, hf_distcc_argv, tvb, offset, len, FALSE);
166 if (check_col(pinfo->cinfo, COL_INFO)) {
167 col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", argv);
171 proto_tree_add_text(tree, tvb, 0, 0, "[Short ARGV PDU]");
177 dissect_distcc_serr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gint parameter)
184 CHECK_PDU_LEN("SERR");
186 /* see if we need to desegment the PDU */
187 DESEGMENT_TCP("SERR");
191 argv_len=len>255?255:len;
192 tvb_memcpy(tvb, argv, offset, argv_len);
195 proto_tree_add_item(tree, hf_distcc_serr, tvb, offset, len, FALSE);
197 if (check_col(pinfo->cinfo, COL_INFO)) {
198 col_append_fstr(pinfo->cinfo, COL_INFO, "SERR:%s ", argv);
202 proto_tree_add_text(tree, tvb, 0, 0, "[Short SERR PDU]");
208 dissect_distcc_sout(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gint parameter)
215 CHECK_PDU_LEN("SOUT");
217 /* see if we need to desegment the PDU */
218 DESEGMENT_TCP("SOUT");
222 argv_len=len>255?255:len;
223 tvb_memcpy(tvb, argv, offset, argv_len);
226 proto_tree_add_item(tree, hf_distcc_sout, tvb, offset, len, FALSE);
228 if (check_col(pinfo->cinfo, COL_INFO)) {
229 col_append_fstr(pinfo->cinfo, COL_INFO, "SOUT:%s ", argv);
233 proto_tree_add_text(tree, tvb, 0, 0, "[Short SOUT PDU]");
240 dissect_distcc_doti(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gint parameter)
245 CHECK_PDU_LEN("DOTI");
247 /* see if we need to desegment the PDU */
248 DESEGMENT_TCP("DOTI");
250 if (check_col(pinfo->cinfo, COL_INFO)) {
251 col_append_fstr(pinfo->cinfo, COL_INFO, "DOTI source ");
254 proto_tree_add_item(tree, hf_distcc_doti_source, tvb, offset, len, FALSE);
256 proto_tree_add_text(tree, tvb, 0, 0, "[Short DOTI PDU]");
262 dissect_distcc_doto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gint parameter)
267 CHECK_PDU_LEN("DOTO");
269 /* see if we need to desegment the PDU */
270 DESEGMENT_TCP("DOTO");
272 if (check_col(pinfo->cinfo, COL_INFO)) {
273 col_append_fstr(pinfo->cinfo, COL_INFO, "DOTO object ");
276 proto_tree_add_item(tree, hf_distcc_doto_object, tvb, offset, len, FALSE);
278 proto_tree_add_text(tree, tvb, 0, 0, "[Short DOTO PDU]");
285 /* Packet dissection routine called by tcp (& udp) when port 3632 detected */
287 dissect_distcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
290 proto_tree *tree=NULL;
291 proto_item *item=NULL;
296 if (check_col(pinfo->cinfo, COL_PROTOCOL))
297 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DISTCC ");
299 if (check_col(pinfo->cinfo, COL_INFO))
300 col_clear(pinfo->cinfo, COL_INFO);
303 item = proto_tree_add_item(parent_tree, proto_distcc, tvb, offset,
305 tree = proto_item_add_subtree(item, ett_distcc);
309 /* we must have at least 12 bytes so we can read the
310 token and the parameter */
311 if(tvb_length_remaining(tvb, offset)<12){
316 tvb_memcpy(tvb, token, offset, 4);
319 /* read the parameter */
320 sscanf(tvb_get_ptr(tvb, offset, 8), "%08x", ¶meter);
323 if(!strncmp(token, "DIST", 4)){
324 offset=dissect_distcc_dist(tvb, pinfo, tree, offset, parameter);
325 } else if(!strncmp(token, "ARGC", 4)){
326 offset=dissect_distcc_argc(tvb, pinfo, tree, offset, parameter);
327 } else if(!strncmp(token, "ARGV", 4)){
328 offset=dissect_distcc_argv(tvb, pinfo, tree, offset, parameter);
329 } else if(!strncmp(token, "DOTI", 4)){
330 offset=dissect_distcc_doti(tvb, pinfo, tree, offset, parameter);
331 } else if(!strncmp(token, "DONE", 4)){
332 offset=dissect_distcc_done(tvb, pinfo, tree, offset, parameter);
333 } else if(!strncmp(token, "STAT", 4)){
334 offset=dissect_distcc_stat(tvb, pinfo, tree, offset, parameter);
335 } else if(!strncmp(token, "SERR", 4)){
336 offset=dissect_distcc_serr(tvb, pinfo, tree, offset, parameter);
337 } else if(!strncmp(token, "SOUT", 4)){
338 offset=dissect_distcc_sout(tvb, pinfo, tree, offset, parameter);
339 } else if(!strncmp(token, "DOTO", 4)){
340 offset=dissect_distcc_doto(tvb, pinfo, tree, offset, parameter);
342 call_dissector(data_handle, tvb, pinfo, tree);
350 /* Register protocol with Ethereal. */
352 proto_register_distcc(void)
354 static hf_register_info hf[] = {
356 {"DISTCC Version", "distcc.version",
357 FT_UINT32, BASE_DEC, NULL, 0x0, "DISTCC Version", HFILL }
360 {"ARGC", "distcc.argc",
361 FT_UINT32, BASE_DEC, NULL, 0x0, "Number of arguments", HFILL }
364 {"ARGV", "distcc.argv",
365 FT_STRING, BASE_NONE, NULL, 0x0, "ARGV argument", HFILL }
367 {&hf_distcc_doti_source,
368 {"Source", "distcc.doti_source",
369 FT_STRING, BASE_NONE, NULL, 0x0, "DOTI Preprocessed Source File (.i)", HFILL }
372 {"Status", "distcc.status",
373 FT_UINT32, BASE_DEC, NULL, 0x0, "Unix wait status for command completion", HFILL }
376 {"SERR", "distcc.serr",
377 FT_STRING, BASE_NONE, NULL, 0x0, "STDERR output", HFILL }
380 {"SOUT", "distcc.sout",
381 FT_STRING, BASE_NONE, NULL, 0x0, "STDOUT output", HFILL }
383 {&hf_distcc_doto_object,
384 {"Object", "distcc.doto_object",
385 FT_BYTES, BASE_HEX, NULL, 0x0, "DOTO Compiled object file (.o)", HFILL }
390 static gint *ett[] = {
394 module_t *distcc_module;
396 proto_distcc = proto_register_protocol("Distcc Distributed Compiler",
398 proto_register_field_array(proto_distcc, hf, array_length(hf));
399 proto_register_subtree_array(ett, array_length(ett));
401 distcc_module = prefs_register_protocol(proto_distcc, NULL);
402 prefs_register_uint_preference(distcc_module, "tcp.port",
404 "Set the TCP port for DISTCC messages",
406 &glb_distcc_tcp_port);
407 prefs_register_bool_preference(distcc_module, "desegment_distcc_over_tcp",
408 "Desegment all DISTCC-over-TCP messages",
409 "Whether the DISTCC dissector should desegment all DISTCC-over-TCP messages",
413 proto_reg_handoff_distcc(void)
415 data_handle = find_dissector("data");
416 distcc_handle = create_dissector_handle(dissect_distcc, proto_distcc);
417 dissector_add("tcp.port", glb_distcc_tcp_port, distcc_handle);