X.25 over TCP support, from Paul Ionescu.
[obnox/wireshark/wip.git] / packet-mapi.c
1 /* packet-mapi.c
2  * Routines for MSX mapi packet dissection
3  *
4  * $Id: packet-mapi.c,v 1.10 2000/11/19 08:54:00 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * Copied from packet-tftp.c
11  * 
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.
16  * 
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.
21  * 
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.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stdio.h>
32
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
35 #endif
36
37 #ifdef HAVE_NETINET_IN_H
38 # include <netinet/in.h>
39 #endif
40
41 #include <string.h>
42 #include <glib.h>
43 #include "packet.h"
44
45 static int proto_mapi = -1;
46 static int hf_mapi_request = -1;
47 static int hf_mapi_response = -1;
48
49 static gint ett_mapi = -1;
50
51 #define TCP_PORT_MAPI                   1065
52
53 static void
54 dissect_mapi(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
55 {
56         proto_tree      *mapi_tree, *ti;
57
58         OLD_CHECK_DISPLAY_AS_DATA(proto_mapi, pd, offset, fd, tree);
59
60         if (check_col(fd, COL_PROTOCOL))
61                 col_set_str(fd, COL_PROTOCOL, "MAPI");
62
63         if (check_col(fd, COL_INFO))
64         {
65                 col_add_fstr(fd, COL_INFO, "%s", 
66                         (pi.match_port == pi.destport) ? "Request" : "Response");         
67         }
68
69         if (tree) 
70         {
71                 ti = proto_tree_add_item(tree, proto_mapi, NullTVB, offset, END_OF_FRAME, FALSE);
72                 mapi_tree = proto_item_add_subtree(ti, ett_mapi);
73
74                 if (pi.match_port == pi.destport)
75                 {
76                         proto_tree_add_boolean_hidden(mapi_tree, hf_mapi_request, NullTVB,
77                                                    offset, END_OF_FRAME, TRUE);
78                         proto_tree_add_text(mapi_tree, NullTVB, offset, 
79                                 END_OF_FRAME, "Request: <opaque data>" );
80                 }
81                 else
82                 {
83                         proto_tree_add_boolean_hidden(mapi_tree, hf_mapi_response, NullTVB,
84                                                    offset, END_OF_FRAME, TRUE);
85                         proto_tree_add_text(mapi_tree, NullTVB, offset, 
86                                 END_OF_FRAME, "Response: <opaque data>");
87                 }
88         }
89 }
90
91 void
92 proto_register_mapi(void)
93 {
94         static hf_register_info hf[] = {
95           { &hf_mapi_response,
96             { "Response",           "mapi.response",
97               FT_BOOLEAN, BASE_NONE, NULL, 0x0,
98               "TRUE if MAPI response" }},
99           
100           { &hf_mapi_request,
101             { "Request",            "mapi.request",
102               FT_BOOLEAN, BASE_NONE, NULL, 0x0,
103               "TRUE if MAPI request" }}
104         };
105
106         static gint *ett[] = {
107                 &ett_mapi,
108         };
109         proto_mapi = proto_register_protocol("MAPI", "mapi");
110         proto_register_field_array(proto_mapi, hf, array_length(hf));
111         proto_register_subtree_array(ett, array_length(ett));
112 }
113
114 void
115 proto_reg_handoff_mapi(void)
116 {
117         old_dissector_add("tcp.port", TCP_PORT_MAPI, dissect_mapi);
118 }