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.
30 #include <epan/packet.h>
33 static int proto_etherip = -1;
34 static int hf_etherip_ver = -1;
36 static gint ett_etherip = -1;
38 static dissector_handle_t eth_handle;
41 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
46 * RFC 3378: EtherIP: Tunneling Ethernet Frames in IP Datagrams
48 * Bits 0-3: Protocol version
49 * Bits 4-15: Reserved for future use
53 guint8 ver; /* version/reserved */
54 guint8 pad; /* required padding byte */
57 #define ETHERIP_VERS_MASK 0x0f
61 dissect_etherip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
63 struct etheriphdr etheriph;
65 proto_tree *etherip_tree;
68 if (check_col(pinfo->cinfo, COL_PROTOCOL))
69 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ETHERIP");
71 /* Copy out the etherip header to insure alignment */
72 tvb_memcpy(tvb, (guint8 *)ðeriph, 0, sizeof(etheriph));
74 /* mask out reserved bits */
75 etheriph.ver &= ETHERIP_VERS_MASK;
78 ti = proto_tree_add_protocol_format(tree, proto_etherip, tvb, 0,
80 "EtherIP, Version %d",
83 etherip_tree = proto_item_add_subtree(ti, ett_etherip);
85 proto_tree_add_uint(etherip_tree, hf_etherip_ver, tvb,
86 offsetof(struct etheriphdr, ver), sizeof(etheriph.ver),
90 /* Set the tvbuff for the payload after the header */
91 next_tvb = tvb_new_subset(tvb, sizeof(etheriph), -1, -1);
93 call_dissector(eth_handle, next_tvb, pinfo, tree);
97 proto_register_etherip(void)
99 static hf_register_info hf_etherip[] = {
101 { "Version", "etherip.ver", FT_UINT8, BASE_HEX, NULL, 0x0,
104 static gint *ett[] = {
108 proto_etherip = proto_register_protocol("Ethernet over IP",
109 "ETHERIP", "etherip");
110 proto_register_field_array(proto_etherip, hf_etherip, array_length(hf_etherip));
111 proto_register_subtree_array(ett, array_length(ett));
113 register_dissector("etherip", dissect_etherip, proto_etherip);
117 proto_reg_handoff_etherip(void)
119 dissector_handle_t etherip_handle;
121 eth_handle = find_dissector("eth");
122 etherip_handle = find_dissector("etherip");
123 dissector_add("ip.proto", IP_PROTO_ETHERIP, etherip_handle);