Created a new protocol tree implementation and a new display filter
[obnox/wireshark/wip.git] / packet-pop.c
1 /* packet-pop.c
2  * Routines for pop packet dissection
3  * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
4  *
5  * $Id: packet-pop.c,v 1.4 1999/07/07 22:51:50 gram Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@unicom.net>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-tftp.c
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
40 #endif
41
42 #include <string.h>
43 #include <glib.h>
44 #include "packet.h"
45 #include "etypes.h"
46
47 extern packet_info pi;
48
49 void
50 dissect_pop(const u_char *pd, int offset, frame_data *fd, proto_tree *tree, int max_data)
51 {
52         proto_tree      *pop_tree, *ti;
53         gchar          rr[50], rd[1500];
54         int i1 = (u_char *)strchr(pd + offset, ' ') - (pd + offset); /* Where is that space */
55         int i2;
56
57         memset(rr, '\0', sizeof(rr));
58         memset(rd, '\0', sizeof(rd));
59
60         if ((i1 > max_data) || (i1 <= 0)) {
61           
62           i1 = max_data;
63           strncpy(rr, pd + offset, MIN(max_data - 2, sizeof(rr) - 1));
64
65         }
66         else {
67
68           strncpy(rr, pd + offset, MIN(i1, sizeof(rr) - 1));
69           i2 = ((u_char *)strchr(pd + offset + i1 + 1, '\r') - (pd + offset)) - i1 - 1;
70           strncpy(rd, pd + offset + i1 + 1, MIN(i2, sizeof(rd) - 1));
71         }
72
73         if (check_col(fd, COL_PROTOCOL))
74                 col_add_str(fd, COL_PROTOCOL, "POP");
75
76         if (check_col(fd, COL_INFO)) {
77
78           col_add_fstr(fd, COL_INFO, "%s: %s %s", (pi.match_port == pi.destport)? "Request" : "Response", rr, rd);
79
80         }
81
82         if (tree) {
83
84           ti = proto_tree_add_text(tree, offset, END_OF_FRAME,
85                                 "Post Office Protocol");
86           pop_tree = proto_item_add_subtree(ti, ETT_POP);
87
88           if (pi.match_port == pi.destport) { /* Request */
89
90             proto_tree_add_text(pop_tree, offset, i1, "Request: %s", rr);
91
92             proto_tree_add_text(pop_tree, offset + i1 + 1, END_OF_FRAME, "Request Arg: %s", rd);
93
94           }
95           else {
96
97             proto_tree_add_text(pop_tree, offset, i1, "Response: %s", rr);
98
99             proto_tree_add_text(pop_tree, offset + i1 + 1, END_OF_FRAME, "Response Arg: %s", rd);
100           }
101
102         }
103 }
104
105
106
107
108
109