2 * Copyright (c) 2003 Markus Friedl. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * $Id: packet-etherip.c,v 1.2 2003/10/02 22:44:19 guy Exp $
32 #include <epan/packet.h>
35 static int proto_etherip = -1;
36 static int hf_etherip_ver = -1;
38 static gint ett_etherip = -1;
40 static dissector_handle_t eth_handle;
43 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
48 * RFC 3378: EtherIP: Tunneling Ethernet Frames in IP Datagrams
50 * Bits 0-3: Protocol version
51 * Bits 4-15: Reserved for future use
55 guint8 ver; /* version/reserved */
56 guint8 pad; /* required padding byte */
59 #define ETHERIP_VERS_MASK 0x0f
63 dissect_etherip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
65 struct etheriphdr etheriph;
67 proto_tree *etherip_tree;
70 if (check_col(pinfo->cinfo, COL_PROTOCOL))
71 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ETHERIP");
73 /* Copy out the etherip header to insure alignment */
74 tvb_memcpy(tvb, (guint8 *)ðeriph, 0, sizeof(etheriph));
76 /* mask out reserved bits */
77 etheriph.ver &= ETHERIP_VERS_MASK;
80 ti = proto_tree_add_protocol_format(tree, proto_etherip, tvb, 0,
82 "EtherIP, Version %d",
85 etherip_tree = proto_item_add_subtree(ti, ett_etherip);
87 proto_tree_add_uint(etherip_tree, hf_etherip_ver, tvb,
88 offsetof(struct etheriphdr, ver), sizeof(etheriph.ver),
92 /* Set the tvbuff for the payload after the header */
93 next_tvb = tvb_new_subset(tvb, sizeof(etheriph), -1, -1);
95 call_dissector(eth_handle, next_tvb, pinfo, tree);
99 proto_register_etherip(void)
101 static hf_register_info hf_etherip[] = {
103 { "Version", "etherip.ver", FT_UINT8, BASE_HEX, NULL, 0x0,
106 static gint *ett[] = {
110 proto_etherip = proto_register_protocol("Ethernet over IP",
111 "ETHERIP", "etherip");
112 proto_register_field_array(proto_etherip, hf_etherip, array_length(hf_etherip));
113 proto_register_subtree_array(ett, array_length(ett));
115 register_dissector("etherip", dissect_etherip, proto_etherip);
119 proto_reg_handoff_etherip(void)
121 dissector_handle_t etherip_handle;
123 eth_handle = find_dissector("eth");
124 etherip_handle = find_dissector("etherip");
125 dissector_add("ip.proto", IP_PROTO_ETHERIP, etherip_handle);