2 * dissector for EPMD (Erlang Port Mapper Daemon) messages;
3 * this are the messages sent between Erlang nodes and
5 * The message formats are derived from the
6 * lib/kernel/src/erl_epmd.* files as part of the Erlang
7 * distribution available from http://www.erlang.org/
9 * (c) 2007 Joost Yervante Damad <joost[AT]teluna.org>
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald[AT]wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * Copied from packet-time.c
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 #include <epan/packet.h>
39 #include <epan/ptvcursor.h>
41 static int proto_epmd = -1;
42 static int hf_epmd_len = -1;
43 static int hf_epmd_type = -1;
44 static int hf_epmd_tcp_port = -1;
45 static int hf_epmd_dist_high = -1;
46 static int hf_epmd_dist_low = -1;
47 static int hf_epmd_name_len = -1;
48 static int hf_epmd_name = -1;
49 static int hf_epmd_elen = -1;
50 static int hf_epmd_edata = -1;
51 static int hf_epmd_names = -1;
52 static int hf_epmd_result = -1;
53 static int hf_epmd_creation = -1;
55 static gint ett_epmd = -1;
57 #define EPMD_PORT 4369
60 #define EPMD_ALIVE2 'x'
61 #define EPMD_PORT_PLEASE 'p'
62 #define EPMD_PORT_PLEASE2 'z'
63 #define EPMD_NAMES 'n'
64 #define EPMD_ALIVE 'a'
67 #define EPMD_ALIVE_OK 'Y'
68 #define EPMD_ALIVE2_OK 'y'
69 #define EPMD_PORT_PLEASE2_OK 'w'
71 /* unknown; currently not implemented */
76 static const value_string message_types[] =
78 { EPMD_ALIVE, "Alive" },
79 { EPMD_PORT_PLEASE, "Port Please" },
80 { EPMD_NAMES, "Names" },
81 { EPMD_DUMP, "Dump" },
82 { EPMD_KILL, "Kill" },
83 { EPMD_STOP, "Stop" },
84 { EPMD_ALIVE_OK, "Alive Ok" },
85 { EPMD_ALIVE2, "Alive 2" },
86 { EPMD_PORT_PLEASE2, "Port Please 2" },
87 { EPMD_ALIVE2_OK, "Alive 2 Ok" },
88 { EPMD_PORT_PLEASE2_OK, "Port Please 2 Ok" },
93 dissect_epmd_request(ptvcursor_t *cursor)
98 tvb = ptvcursor_tvbuff(cursor);
99 ptvcursor_add(cursor, hf_epmd_len, 2, FALSE);
101 type = tvb_get_guint8(tvb, ptvcursor_current_offset(cursor));
102 ptvcursor_add(cursor, hf_epmd_type, 1, FALSE);
105 guint16 name_length, elen;
106 ptvcursor_add(cursor, hf_epmd_tcp_port, 2, FALSE);
107 ptvcursor_advance(cursor,2); /* 'M', 0 */
108 ptvcursor_add(cursor, hf_epmd_dist_high, 2, FALSE);
109 ptvcursor_add(cursor, hf_epmd_dist_low, 2, FALSE);
110 name_length = tvb_get_ntohs(tvb, ptvcursor_current_offset(cursor));
111 ptvcursor_add(cursor, hf_epmd_name_len, 2, FALSE);
112 ptvcursor_add(cursor, hf_epmd_name, name_length, FALSE);
113 elen = tvb_get_ntohs(tvb, ptvcursor_current_offset(cursor));
114 ptvcursor_add(cursor, hf_epmd_elen, 2, FALSE);
116 ptvcursor_add(cursor, hf_epmd_edata, elen, FALSE);
119 case EPMD_PORT_PLEASE:
120 case EPMD_PORT_PLEASE2:
121 /*ptvcursor_add(cursor, hf_epmd_name, tvb_length(tvb)-3, FALSE);*/
122 ptvcursor_add(cursor, hf_epmd_name, -1, FALSE);
125 ptvcursor_add(cursor, hf_epmd_tcp_port, 2, FALSE);
126 /*ptvcursor_add(cursor, hf_epmd_name, tvb_length(tvb)-3, FALSE);*/
127 ptvcursor_add(cursor, hf_epmd_name, -1, FALSE);
137 dissect_epmd_response_names(ptvcursor_t *cursor)
139 ptvcursor_add(cursor, hf_epmd_tcp_port, 2, FALSE);
140 ptvcursor_add(cursor, hf_epmd_names, -1, FALSE);
141 /* TODO: parse names */
145 dissect_epmd_response(ptvcursor_t *cursor)
151 tvb = ptvcursor_tvbuff(cursor);
152 port = tvb_get_ntohl(tvb, 0);
153 if (port == EPMD_PORT) {
154 dissect_epmd_response_names(cursor);
158 type = tvb_get_guint8(tvb, 0);
159 ptvcursor_add(cursor, hf_epmd_type, 1, FALSE);
161 case EPMD_PORT_PLEASE2_OK: {
162 ptvcursor_advance(cursor, 1);
163 /* 'w', 0, Port(16), Type(8), Proto(8), High(16), Low(16), NLen(16), Name(x) */
164 ptvcursor_add(cursor, hf_epmd_tcp_port, 2, FALSE);
165 ptvcursor_advance(cursor, 2); /* 'M', 0 */
166 ptvcursor_add(cursor, hf_epmd_dist_high, 2, FALSE);
167 ptvcursor_add(cursor, hf_epmd_dist_low, 2, FALSE);
168 ptvcursor_add(cursor, hf_epmd_name_len, 2, FALSE);
169 ptvcursor_add(cursor, hf_epmd_name, -1, FALSE);
172 case EPMD_ALIVE2_OK: {
173 ptvcursor_add(cursor, hf_epmd_result, 1, FALSE);
174 ptvcursor_add(cursor, hf_epmd_creation, 2, FALSE);
182 check_epmd(tvbuff_t *tvb)
188 * just check if the type is one of the EPMD
191 * It's possible to start checking lengths but imho that
192 * doesn't bring very much.
194 if (tvb_length(tvb) < 3)
197 type = tvb_get_guint8(tvb, 0);
201 case EPMD_PORT_PLEASE2_OK:
207 type = tvb_get_guint8(tvb, 2);
210 case EPMD_PORT_PLEASE:
211 case EPMD_PORT_PLEASE2:
223 dissect_epmd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
225 proto_tree *epmd_tree;
229 if (!check_epmd(tvb))
232 if (check_col(pinfo->cinfo, COL_PROTOCOL))
233 col_set_str(pinfo->cinfo, COL_PROTOCOL, "EPMD");
236 ti = proto_tree_add_item(tree, proto_epmd, tvb, 0, -1, FALSE);
237 epmd_tree = proto_item_add_subtree(ti, ett_epmd);
238 cursor = ptvcursor_new(epmd_tree, tvb, 0);
240 if (pinfo->srcport==EPMD_PORT) {
241 dissect_epmd_response(cursor);
243 dissect_epmd_request(cursor);
246 ptvcursor_free(cursor);
249 return(tvb_length(tvb));
253 proto_register_epmd(void)
255 static hf_register_info hf[] = {
257 { "Length", "epmd.len",
258 FT_UINT16, BASE_DEC, NULL, 0x0,
259 "Message Length", HFILL }},
261 { "Type", "epmd.type",
262 FT_UINT8, BASE_DEC, VALS(message_types), 0x0,
263 "Message Type", HFILL }},
265 { "Result", "epmd.result",
266 FT_UINT8, BASE_DEC, NULL, 0x0,
269 { "TCP Port", "epmd.tcp_port",
270 FT_UINT16, BASE_DEC, NULL, 0x0,
271 "TCP Port", HFILL }},
273 { "Creation", "epmd.creation",
274 FT_UINT16, BASE_DEC, NULL, 0x0,
275 "Creation", HFILL }},
276 { &hf_epmd_dist_high,
277 { "Dist High", "epmd.dist_high",
278 FT_UINT16, BASE_DEC, NULL, 0x0,
279 "Dist High", HFILL }},
281 { "Dist Low", "epmd.dist_low",
282 FT_UINT16, BASE_DEC, NULL, 0x0,
283 "Dist Low", HFILL }},
285 { "Name Length", "epmd.name_len",
286 FT_UINT16, BASE_DEC, NULL, 0x0,
287 "Name Length", HFILL }},
289 { "Name", "epmd.name",
290 FT_STRING, BASE_DEC, NULL, 0x0,
293 { "Elen", "epmd.elen",
294 FT_UINT16, BASE_DEC, NULL, 0x0,
295 "Extra Length", HFILL }},
297 { "Edata", "epmd.edata",
298 FT_BYTES, BASE_DEC, NULL, 0x0,
299 "Extra Data", HFILL }},
301 { "Names", "epmd.names",
302 FT_BYTES, BASE_DEC, NULL, 0x0,
303 "List of names", HFILL }}
305 static gint *ett[] = {
309 proto_epmd = proto_register_protocol("EPMD Protocol", "EPMD", "epmd");
310 proto_register_field_array(proto_epmd, hf, array_length(hf));
311 proto_register_subtree_array(ett, array_length(ett));
312 new_register_dissector("epmd", dissect_epmd, proto_epmd);
316 proto_reg_handoff_epmd(void)
318 dissector_handle_t epmd_handle;
319 epmd_handle = find_dissector("epmd");
320 dissector_add("tcp.port", EPMD_PORT, epmd_handle);