1 diff -Naur -X ethereal-dontdiff clean/ethereal-0.9.9/Makefile.am ethereal-0.9.9-distcc/Makefile.am
2 --- clean/ethereal-0.9.9/Makefile.am 2003-01-24 10:50:12.000000000 +1100
3 +++ ethereal-0.9.9-distcc/Makefile.am 2003-03-06 21:06:50.000000000 +1100
12 diff -Naur -X ethereal-dontdiff clean/ethereal-0.9.9/Makefile.nmake ethereal-0.9.9-distcc/Makefile.nmake
13 --- clean/ethereal-0.9.9/Makefile.nmake 2003-01-23 13:45:42.000000000 +1100
14 +++ ethereal-0.9.9-distcc/Makefile.nmake 2003-03-06 21:06:50.000000000 +1100
23 diff -Naur -X ethereal-dontdiff clean/ethereal-0.9.9/packet-distcc.c ethereal-0.9.9-distcc/packet-distcc.c
24 --- clean/ethereal-0.9.9/packet-distcc.c 1970-01-01 10:00:00.000000000 +1000
25 +++ ethereal-0.9.9-distcc/packet-distcc.c 2003-03-09 20:22:26.000000000 +1100
28 + * Routines for distcc dissection
29 + * Copyright 2003, Brad Hards <bradh@xxxxxxxxxxxxx>
33 + * Ethereal - Network traffic analyzer
34 + * By Gerald Combs <gerald@xxxxxxxxxxxx>
35 + * Copyright 1998 Gerald Combs
37 + * This program is free software; you can redistribute it and/or
38 + * modify it under the terms of the GNU General Public License
39 + * as published by the Free Software Foundation; either version 2
40 + * of the License, or (at your option) any later version.
42 + * This program is distributed in the hope that it will be useful,
43 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 + * GNU General Public License for more details.
47 + * You should have received a copy of the GNU General Public License
48 + * along with this program; if not, write to the Free Software
49 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
63 +#include <epan/packet.h>
64 +#include <epan/strutil.h>
65 +#include <epan/conversation.h>
69 +typedef enum _distcc_state {
73 + DISTCC_DOTI_CONT = 3,
79 + DISTCC_DOTO_CONT = 9
82 +/* this is used to represent the _initial_ state of the frame */
83 +/* each frame can contain multiple protocol elements */
84 +struct distcc_frame_state_t {
85 + distcc_state_t state;
87 + guint len_remaining;
90 +/* this is a guide to the current conversation state */
91 +/* we need the length remaining because source and object elements can
92 + easily span multiple frames, and we need to track the
93 + internal"sub-state" in DOTI and DOTO */
94 +struct distcc_conversation_state_t {
95 + distcc_state_t state;
96 + guint len_remaining;
99 +static int proto_distcc = -1;
101 +static int hf_distcc_hdr_magic = -1;
102 +static int hf_distcc_hdr_version = -1;
103 +static int hf_distcc_hdr_argc = -1;
104 +static int hf_distcc_hdr_argv = -1;
105 +static int hf_distcc_doti_magic = -1;
106 +static int hf_distcc_done_magic = -1;
107 +static int hf_distcc_done_version = -1;
108 +static int hf_distcc_stat_magic = -1;
109 +static int hf_distcc_stat_result = -1;
110 +static int hf_distcc_serr_magic = -1;
111 +static int hf_distcc_sout_magic = -1;
112 +static int hf_distcc_doto_magic = -1;
114 +static gint ett_distcc = -1;
116 +dissector_handle_t distcc_handle;
119 +#define TCP_PORT_DISTCC 3632
121 +static int glb_distcc_tcp_port = TCP_PORT_DISTCC;
123 +/* Packet dissection routine called by tcp (& udp) when port 3632 detected */
125 +dissect_distcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
129 + proto_tree *distcc_tree;
130 + conversation_t *conversation;
131 + struct distcc_conversation_state_t *conversation_data;
132 + struct distcc_frame_state_t *frame_data;
133 + gchar cmd_line_argc_string[9];
136 + gchar cmd_line_argv_len_string[9];
137 + int cmd_line_argv_len;
138 + gchar doti_length_string[9];
139 + gchar doti_magic[9];
141 + guint actual_bytes_remaining;
142 + gchar sout_length_string[9];
144 + gchar serr_length_string[9];
146 + gchar doto_length_string[9];
149 + if (check_col(pinfo->cinfo, COL_PROTOCOL))
150 + col_set_str(pinfo->cinfo, COL_PROTOCOL, "DISTCC");
152 + if (check_col(pinfo->cinfo, COL_INFO))
153 + col_clear(pinfo->cinfo, COL_INFO);
155 + conversation = find_conversation(&pinfo->src, &pinfo->dst, pinfo->ptype,
156 + pinfo->srcport, pinfo->destport, 0);
157 + if (conversation == NULL) {
158 + conversation = conversation_new(&pinfo->src, &pinfo->dst,
159 + pinfo->ptype, pinfo->srcport,
160 + pinfo->destport, 0);
161 + conversation_data = malloc(sizeof(struct distcc_conversation_state_t));
162 + conversation_data->state = DISTCC_DIST;
163 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
166 + conversation_set_dissector(conversation, distcc_handle);
168 + ti = proto_tree_add_item(tree, proto_distcc, tvb, 0, -1, FALSE);
170 + distcc_tree = proto_item_add_subtree(ti, ett_distcc);
172 + conversation_data = conversation_get_proto_data(conversation, proto_distcc);
174 + frame_data = p_get_proto_data(pinfo->fd, proto_distcc);
176 + /* then we haven't seen this frame before */
177 + frame_data = malloc(sizeof(struct distcc_frame_state_t));
178 + frame_data->state = conversation_data->state;
179 + frame_data->len_remaining = conversation_data->len_remaining;
180 + p_add_proto_data(pinfo->fd, proto_distcc, frame_data);
183 + switch (frame_data->state) {
185 + proto_tree_add_item(distcc_tree, hf_distcc_hdr_magic, tvb, offset, 4, TRUE);
188 + proto_tree_add_item(distcc_tree, hf_distcc_hdr_version, tvb, offset, 8, TRUE);
191 + conversation_data->state = DISTCC_ARGS;
192 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
193 + if (tvb_length_remaining(tvb, offset) == 0)
197 + proto_tree_add_item(distcc_tree, hf_distcc_hdr_argc, tvb, offset, 12, TRUE);
200 + tvb_get_nstringz0(tvb, offset, 8, cmd_line_argc_string);
201 + cmd_line_argc = strtoul(cmd_line_argc_string, NULL, 16);
202 + proto_tree_add_text(distcc_tree, tvb, offset, 8,
203 + "Number of arguments: %i (0x%x)",
204 + cmd_line_argc, cmd_line_argc);
206 + for (yalv = 0; yalv<cmd_line_argc; yalv++) {
207 + proto_tree_add_item(distcc_tree, hf_distcc_hdr_argv, tvb, offset, 12, TRUE);
209 + tvb_get_nstringz0(tvb, offset, 8, cmd_line_argv_len_string);
210 + cmd_line_argv_len = strtoul(cmd_line_argv_len_string, NULL, 16);
211 + proto_tree_add_text(distcc_tree, tvb, offset, 8,
212 + "Length of argument %i: %i (0x%x)",
214 + cmd_line_argv_len, cmd_line_argv_len);
216 + proto_tree_add_text(distcc_tree, tvb, offset, cmd_line_argv_len,
219 + tvb_format_text(tvb, offset, cmd_line_argv_len));
220 + if (check_col(pinfo->cinfo, COL_INFO)) {
221 + col_append_fstr(pinfo->cinfo,
224 + tvb_format_text(tvb, offset, cmd_line_argv_len));
226 + offset += cmd_line_argv_len;
228 + conversation_data->state = DISTCC_DOTI;
229 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
230 + if (tvb_length_remaining(tvb, offset) == 0)
234 + if (check_col(pinfo->cinfo, COL_INFO)) {
235 + col_append_str(pinfo->cinfo, COL_INFO, "DOTI");
237 + proto_tree_add_item(distcc_tree, hf_distcc_doti_magic, tvb, offset, 4, TRUE);
240 + tvb_get_nstringz0(tvb, offset, 8, doti_length_string);
241 + doti_length = strtoul(doti_length_string, NULL, 16);
242 + proto_tree_add_text(distcc_tree, tvb, offset, 8,
243 + "DOTI Length: %i (0x%x)",
244 + doti_length, doti_length);
246 + actual_bytes_remaining = tvb_length_remaining(tvb, offset);
247 + if (check_col(pinfo->cinfo, COL_INFO)) {
248 + col_append_fstr(pinfo->cinfo, COL_INFO,
249 + " (%i of %i bytes)", actual_bytes_remaining,
252 + if (actual_bytes_remaining >= doti_length) {
253 + /* this is the case where we have all the data */
254 + proto_tree_add_text(distcc_tree, tvb, offset, doti_length,
256 + tvb_format_text(tvb, offset, doti_length));
257 + offset += doti_length;
258 + conversation_data->state = DISTCC_DONE;
260 + /* this is where we have only the start of the data, and
261 + it continues in a later frame */
262 + proto_tree_add_text(distcc_tree, tvb, offset, actual_bytes_remaining,
264 + tvb_format_text(tvb, offset, actual_bytes_remaining));
265 + offset += actual_bytes_remaining;
266 + conversation_data->state = DISTCC_DOTI_CONT;
267 + conversation_data->len_remaining = doti_length - actual_bytes_remaining;
269 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
270 + /* we always need to break out at this point */
273 + case DISTCC_DOTI_CONT:
274 + /* do a sanity check, against dropped frames */
275 + tvb_get_nstringz0(tvb, offset, 8, doti_magic);
276 + if (0 == strncmp(doti_magic, "DONE0000", 8)) {
278 + printf("failed sanity checking - bailing out to DISTCC_DONE\n");
280 + conversation_data->state = DISTCC_DONE;
281 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
283 + actual_bytes_remaining = tvb_length(tvb);
284 + if (actual_bytes_remaining >= frame_data->len_remaining) {
285 + /* this is the case where we have all the data */
286 + if (check_col(pinfo->cinfo, COL_INFO)) {
287 + col_append_fstr(pinfo->cinfo, COL_INFO,
288 + "DOTI Finalisation (%i bytes)", actual_bytes_remaining);
290 + proto_tree_add_text(distcc_tree, tvb, offset,
291 + conversation_data->len_remaining,
292 + "DOTI data: ...%s",
293 + tvb_format_text(tvb, offset,
294 + frame_data->len_remaining));
295 + offset += conversation_data->len_remaining;
296 + conversation_data->state = DISTCC_DONE;
298 + /* this is where we have only the start of the data, and
299 + it continues in a later frame */
300 + if (check_col(pinfo->cinfo, COL_INFO)) {
301 + col_append_fstr(pinfo->cinfo, COL_INFO,
302 + "DOTI Continuation (%i bytes)", actual_bytes_remaining);
304 + proto_tree_add_text(distcc_tree, tvb, offset, actual_bytes_remaining,
305 + "DOTI data: ...%s...",
306 + tvb_format_text(tvb, offset, actual_bytes_remaining));
307 + offset += actual_bytes_remaining;
308 + conversation_data->state = DISTCC_DOTI_CONT;
309 + /* this routine runs on display, not just on initial pass */
310 + /* so we use a flag to ensure we only subtract length once */
311 + if (frame_data->done_sub_len == 0) {
312 + conversation_data->len_remaining -= actual_bytes_remaining;
313 + frame_data->done_sub_len = 1;
314 + p_add_proto_data(pinfo->fd, proto_distcc, frame_data);
317 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
320 + } /* note that we fall through if we failed the sanity check */
322 + if (check_col(pinfo->cinfo, COL_INFO)) {
323 + col_append_str(pinfo->cinfo, COL_INFO, "DONE ");
325 + proto_tree_add_item(distcc_tree, hf_distcc_done_magic, tvb, offset, 4, TRUE);
327 + proto_tree_add_item(distcc_tree, hf_distcc_done_version, tvb, offset, 8, TRUE);
330 + conversation_data->state = DISTCC_STAT;
331 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
332 + if (tvb_length_remaining(tvb, offset) == 0)
333 + break; /* else fall through, since we have more data */
336 + if (check_col(pinfo->cinfo, COL_INFO)) {
337 + col_append_str(pinfo->cinfo, COL_INFO, "STAT ");
339 + proto_tree_add_item(distcc_tree, hf_distcc_stat_magic, tvb, offset, 4, TRUE);
341 + proto_tree_add_item(distcc_tree, hf_distcc_stat_result, tvb, offset, 8, TRUE);
344 + conversation_data->state = DISTCC_SERR;
345 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
346 + if (tvb_length_remaining(tvb, offset) == 0)
350 + if (check_col(pinfo->cinfo, COL_INFO)) {
351 + col_append_str(pinfo->cinfo, COL_INFO, "SERR ");
353 + proto_tree_add_item(distcc_tree, hf_distcc_serr_magic, tvb, offset, 4, TRUE);
355 + tvb_get_nstringz0(tvb, offset, 8, serr_length_string);
356 + serr_length = strtoul(serr_length_string, NULL, 16);
357 + proto_tree_add_text(distcc_tree, tvb, offset, 8,
358 + "SERR Length: %i (0x%x)",
359 + serr_length, serr_length);
361 + if (serr_length > 0) {
362 + proto_tree_add_text(distcc_tree, tvb, offset,
365 + tvb_format_text(tvb, offset, serr_length));
366 + offset += serr_length;
368 + conversation_data->state = DISTCC_SOUT;
369 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
370 + if (tvb_length_remaining(tvb, offset) == 0)
374 + if (check_col(pinfo->cinfo, COL_INFO)) {
375 + col_append_str(pinfo->cinfo, COL_INFO, "SOUT ");
377 + proto_tree_add_item(distcc_tree, hf_distcc_sout_magic, tvb, offset, 4, TRUE);
379 + tvb_get_nstringz0(tvb, offset, 8, sout_length_string);
380 + sout_length = strtoul(sout_length_string, NULL, 16);
381 + proto_tree_add_text(distcc_tree, tvb, offset, 8,
382 + "SOUT Length: %i (0x%x)",
383 + sout_length, sout_length);
385 + if (sout_length > 0) {
386 + proto_tree_add_text(distcc_tree, tvb, offset,
389 + tvb_format_text(tvb, offset, sout_length));
390 + offset += sout_length;
392 + conversation_data->state = DISTCC_DOTO;
393 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
394 + if (tvb_length_remaining(tvb, offset) == 0)
398 + if (check_col(pinfo->cinfo, COL_INFO)) {
399 + col_append_str(pinfo->cinfo, COL_INFO, "DOTO ");
401 + proto_tree_add_item(distcc_tree, hf_distcc_doto_magic, tvb, offset, 4, TRUE);
403 + tvb_get_nstringz0(tvb, offset, 8, doto_length_string);
404 + doto_length = strtoul(doto_length_string, NULL, 16);
405 + proto_tree_add_text(distcc_tree, tvb, offset, 8,
406 + "DOTO Length: %i (0x%x)",
407 + doto_length, doto_length);
409 + actual_bytes_remaining = tvb_length_remaining(tvb, offset);
410 + proto_tree_add_text(distcc_tree, tvb, offset, 0,
411 + "Bytes in this packet: %i (0x%x)",
412 + actual_bytes_remaining, actual_bytes_remaining);
413 + if (check_col(pinfo->cinfo, COL_INFO)) {
414 + col_append_fstr(pinfo->cinfo, COL_INFO, "(%i of %i bytes)",
415 + actual_bytes_remaining, doto_length);
418 + if (actual_bytes_remaining >= doto_length) {
419 + /* this is the case where we have all the data */
420 + proto_tree_add_text(distcc_tree, tvb, offset, doto_length,
422 + tvb_format_text(tvb, offset, doto_length));
423 + offset += doto_length;
425 + /* this is where we have only the start of the data, and
426 + it continues in a later frame */
427 + proto_tree_add_text(distcc_tree, tvb, offset, actual_bytes_remaining,
429 + tvb_format_text(tvb, offset, actual_bytes_remaining));
430 + offset += actual_bytes_remaining;
431 + conversation_data->state = DISTCC_DOTO_CONT;
432 + conversation_data->len_remaining = doto_length - actual_bytes_remaining;
433 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
435 + /* we always need to break out at this point */
438 + case DISTCC_DOTO_CONT:
439 + actual_bytes_remaining = tvb_length(tvb);
440 + if (actual_bytes_remaining >= frame_data->len_remaining) {
441 + /* this is the case where we have all the data */
442 + if (check_col(pinfo->cinfo, COL_INFO)) {
443 + col_append_fstr(pinfo->cinfo, COL_INFO,
444 + "DOTO Finalisation (%i bytes)", actual_bytes_remaining);
446 + proto_tree_add_text(distcc_tree, tvb, offset,
447 + frame_data->len_remaining,
448 + "DOTO data: ...%s",
449 + tvb_format_text(tvb, offset,
450 + frame_data->len_remaining));
451 + offset += frame_data->len_remaining;
453 + /* this is where we have only some of the data, and
454 + it continues in a later frame */
455 + if (check_col(pinfo->cinfo, COL_INFO)) {
456 + col_append_fstr(pinfo->cinfo, COL_INFO,
457 + "DOTO Continuation (%i bytes)", actual_bytes_remaining);
459 + proto_tree_add_text(distcc_tree, tvb, offset, actual_bytes_remaining,
460 + "DOTO data: ...%s...",
461 + tvb_format_text(tvb, offset, actual_bytes_remaining));
462 + offset += actual_bytes_remaining;
463 + conversation_data->state = DISTCC_DOTO_CONT;
464 + /* this routine runs on display, not just on initial pass */
465 + /* so we use a flag to ensure we only subtract length once */
466 + /* we will never get DOTI and DOTO in the same frame, since
467 + they go in opposing directions, so we can reuse the flag */
468 + if (frame_data->done_sub_len == 0) {
469 + conversation_data->len_remaining -= actual_bytes_remaining;
470 + frame_data->done_sub_len = 1;
471 + p_add_proto_data(pinfo->fd, proto_distcc, frame_data);
473 + conversation_add_proto_data(conversation, proto_distcc, conversation_data);
480 +/* Register protocol with Ethereal. */
482 +proto_register_distcc(void)
484 + static hf_register_info hf[] = {
485 + {&hf_distcc_hdr_magic,
486 + {"Magic Header", "distcc.hdr_magic",
487 + FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
489 + {&hf_distcc_hdr_version,
490 + {"Header Version", "distcc.hdr_version",
491 + FT_STRING, BASE_NONE, NULL, 0x0, "DISTCC Version", HFILL }
493 + {&hf_distcc_hdr_argc,
494 + {"ARGC", "distcc.hdr_argc",
495 + FT_STRING, BASE_NONE, NULL, 0x0, "Argument Count Entry", HFILL }
497 + {&hf_distcc_hdr_argv,
498 + {"ARGV label", "distcc.hdr_argv",
499 + FT_STRING, BASE_NONE, NULL, 0x0, "Argument Vector Entry", HFILL }
501 + {&hf_distcc_doti_magic,
502 + {"DOTI Magic Header", "distcc.doti_magic",
503 + FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
505 + {&hf_distcc_done_magic,
506 + {"DONE Magic Header", "distcc.done_magic",
507 + FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
509 + {&hf_distcc_done_version,
510 + {"Done Version", "distcc.done_version",
511 + FT_STRING, BASE_NONE, NULL, 0x0, "DISTCC Daemon Version", HFILL }
513 + {&hf_distcc_stat_result,
514 + {"STAT result", "distcc.stat_result",
515 + FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
517 + {&hf_distcc_doto_magic,
518 + {"DOTO Magic Header", "distcc.doto_magic",
519 + FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
521 + {&hf_distcc_stat_magic,
522 + {"STAT Magic Header", "distcc.stat_magic",
523 + FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
525 + {&hf_distcc_serr_magic,
526 + {"SERR Magic Header", "distcc.serr_magic",
527 + FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
529 + {&hf_distcc_sout_magic,
530 + {"SOUT Magic Header", "distcc.sout_magic",
531 + FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
535 + static gint *ett[] = {
539 + module_t *distcc_module;
541 + proto_distcc = proto_register_protocol("Distributed Compiler System",
542 + "DISTCC", "distcc");
543 + proto_register_field_array(proto_distcc, hf, array_length(hf));
544 + proto_register_subtree_array(ett, array_length(ett));
546 + distcc_module = prefs_register_protocol(proto_distcc, NULL);
547 + prefs_register_uint_preference(distcc_module, "tcp.port",
549 + "Set the TCP port for DISTCC messages",
551 + &glb_distcc_tcp_port);
554 +proto_reg_handoff_distcc(void)
556 + distcc_handle = create_dissector_handle(dissect_distcc, proto_distcc);
557 + dissector_add("tcp.port", glb_distcc_tcp_port, distcc_handle);