Set the svn:eol-style property on all text files to "native", so that
[obnox/wireshark/wip.git] / packet-ap1394.c
1 /* packet-ap1394.c
2  * Routines for Apple IP-over-IEEE 1394 packet disassembly
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/resolv.h>
32 #include <epan/strutil.h>
33
34 #include "packet-ap1394.h"
35 #include "etypes.h"
36
37 static int proto_ap1394 = -1;
38 static int hf_ap1394_dst = -1;
39 static int hf_ap1394_src = -1;
40 static int hf_ap1394_type = -1;
41
42 static gint ett_ap1394 = -1;
43
44 void
45 capture_ap1394(const guchar *pd, int offset, int len, packet_counts *ld)
46 {
47   guint16    etype;
48
49   if (!BYTES_ARE_IN_FRAME(offset, len, 18)) {
50     ld->other++;
51     return;
52   }
53
54   /* Skip destination and source addresses */
55   offset += 16;
56
57   etype = pntohs(&pd[offset]);
58   offset += 2;
59   capture_ethertype(etype, pd, offset, len, ld);
60 }
61
62 static void
63 dissect_ap1394(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
64 {
65   proto_item *ti;
66   proto_tree *fh_tree = NULL;
67   const char *src_addr, *dst_addr;
68   guint16    etype;
69
70   if (check_col(pinfo->cinfo, COL_PROTOCOL))
71     col_set_str(pinfo->cinfo, COL_PROTOCOL, "IP/IEEE1394");
72   if (check_col(pinfo->cinfo, COL_INFO))
73     col_clear(pinfo->cinfo, COL_INFO);
74
75   src_addr=tvb_get_ptr(tvb, 8, 8);
76   SET_ADDRESS(&pinfo->dl_src,   AT_EUI64, 8, src_addr);
77   SET_ADDRESS(&pinfo->src,      AT_EUI64, 8, src_addr);
78   dst_addr=tvb_get_ptr(tvb, 0, 8);
79   SET_ADDRESS(&pinfo->dl_dst,   AT_EUI64, 8, dst_addr);
80   SET_ADDRESS(&pinfo->dst,      AT_EUI64, 8, dst_addr);
81
82   if (tree) {
83     ti = proto_tree_add_protocol_format(tree, proto_ap1394, tvb, 0, 18,
84                 "Apple IP-over-IEEE 1394, Src: %s, Dst: %s",
85                 bytes_to_str(src_addr, 8), bytes_to_str(dst_addr, 8));
86     fh_tree = proto_item_add_subtree(ti, ett_ap1394);
87     proto_tree_add_bytes(fh_tree, hf_ap1394_dst, tvb, 0, 8, dst_addr);
88     proto_tree_add_bytes(fh_tree, hf_ap1394_src, tvb, 8, 8, src_addr);
89   }
90   etype = tvb_get_ntohs(tvb, 16);
91   ethertype(etype, tvb, 18, pinfo, tree, fh_tree, hf_ap1394_type, -1, 0);
92 }
93
94 void
95 proto_register_ap1394(void)
96 {
97   static hf_register_info hf[] = {
98     { &hf_ap1394_dst,
99       { "Destination", "ap1394.dst", FT_BYTES, BASE_NONE,
100         NULL, 0x0, "Destination address", HFILL }},
101     { &hf_ap1394_src,
102       { "Source", "ap1394.src", FT_BYTES, BASE_NONE,
103         NULL, 0x0, "Source address", HFILL }},
104     /* registered here but handled in ethertype.c */
105     { &hf_ap1394_type,
106       { "Type", "ap1394.type", FT_UINT16, BASE_HEX,
107         VALS(etype_vals), 0x0, "", HFILL }},
108   };
109   static gint *ett[] = {
110     &ett_ap1394,
111   };
112
113   proto_ap1394 = proto_register_protocol("Apple IP-over-IEEE 1394", "IP/IEEE1394", "ap1394");
114   proto_register_field_array(proto_ap1394, hf, array_length(hf));
115   proto_register_subtree_array(ett, array_length(ett));
116 }
117
118 void
119 proto_reg_handoff_ap1394(void)
120 {
121   dissector_handle_t ap1394_handle;
122
123   ap1394_handle = create_dissector_handle(dissect_ap1394, proto_ap1394);
124   dissector_add("wtap_encap", WTAP_ENCAP_APPLE_IP_OVER_IEEE1394, ap1394_handle);
125 }