Made the protocol (but not the fields) use the new proto_tree routine,
[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.5 1999/07/29 05:47:01 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 static int proto_pop = -1;
50
51 void
52 dissect_pop(const u_char *pd, int offset, frame_data *fd, proto_tree *tree, int max_data)
53 {
54         proto_tree      *pop_tree, *ti;
55         gchar          rr[50], rd[1500];
56         int i1 = (u_char *)strchr(pd + offset, ' ') - (pd + offset); /* Where is that space */
57         int i2;
58
59         memset(rr, '\0', sizeof(rr));
60         memset(rd, '\0', sizeof(rd));
61
62         if ((i1 > max_data) || (i1 <= 0)) {
63           
64           i1 = max_data;
65           strncpy(rr, pd + offset, MIN(max_data - 2, sizeof(rr) - 1));
66
67         }
68         else {
69
70           strncpy(rr, pd + offset, MIN(i1, sizeof(rr) - 1));
71           i2 = ((u_char *)strchr(pd + offset + i1 + 1, '\r') - (pd + offset)) - i1 - 1;
72           strncpy(rd, pd + offset + i1 + 1, MIN(i2, sizeof(rd) - 1));
73         }
74
75         if (check_col(fd, COL_PROTOCOL))
76                 col_add_str(fd, COL_PROTOCOL, "POP");
77
78         if (check_col(fd, COL_INFO)) {
79
80           col_add_fstr(fd, COL_INFO, "%s: %s %s", (pi.match_port == pi.destport)? "Request" : "Response", rr, rd);
81
82         }
83
84         if (tree) {
85
86           ti = proto_tree_add_item(tree, proto_pop, offset, END_OF_FRAME, NULL);
87           pop_tree = proto_item_add_subtree(ti, ETT_POP);
88
89           if (pi.match_port == pi.destport) { /* Request */
90
91             proto_tree_add_text(pop_tree, offset, i1, "Request: %s", rr);
92
93             proto_tree_add_text(pop_tree, offset + i1 + 1, END_OF_FRAME, "Request Arg: %s", rd);
94
95           }
96           else {
97
98             proto_tree_add_text(pop_tree, offset, i1, "Response: %s", rr);
99
100             proto_tree_add_text(pop_tree, offset + i1 + 1, END_OF_FRAME, "Response Arg: %s", rd);
101           }
102
103         }
104 }
105
106 void
107 proto_register_pop(void)
108 {
109 /*        static hf_register_info hf[] = {
110                 { &variable,
111                 { "Name",           "pop.abbreviation", TYPE, VALS_POINTER }},
112         };*/
113
114         proto_pop = proto_register_protocol("Post Office Protocol", "pop");
115  /*       proto_register_field_array(proto_pop, hf, array_length(hf));*/
116 }