]> The Tcpdump Group git mirrors - tcpdump/blob - print-ipfc.c
a33cfbdf49444bf13311cdbc76f99abaf847f998
[tcpdump] / print-ipfc.c
1 /*
2 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-ipfc.c,v 1.2 2002-12-18 08:53:21 guy Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <tcpdump-stdinc.h>
32
33 #include <pcap.h>
34 #include <stdio.h>
35 #include <string.h>
36
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "ethertype.h"
40
41 #include "ether.h"
42 #include "ipfc.h"
43
44 /*
45 * RFC 2625 IP-over-Fibre Channel.
46 */
47
48 /* Extract src, dst addresses */
49 static inline void
50 extract_ipfc_addrs(const struct ipfc_header *ipfcp, char *ipfcsrc,
51 char *ipfcdst)
52 {
53 /*
54 * We assume that, as per RFC 2625, the lower 48 bits of the
55 * source and destination addresses are MAC addresses.
56 */
57 memcpy(ipfcdst, (const char *)&ipfcp->ipfc_dhost[2], 6);
58 memcpy(ipfcsrc, (const char *)&ipfcp->ipfc_shost[2], 6);
59 }
60
61 /*
62 * Print the Network_Header
63 */
64 static inline void
65 ipfc_hdr_print(register const struct ipfc_header *ipfcp _U_,
66 register u_int length, register const u_char *ipfcsrc,
67 register const u_char *ipfcdst)
68 {
69 const char *srcname, *dstname;
70
71 srcname = etheraddr_string(ipfcsrc);
72 dstname = etheraddr_string(ipfcdst);
73
74 /*
75 * XXX - show the upper 16 bits? Do so only if "vflag" is set?
76 */
77 (void) printf("%s %s %d: ", srcname, dstname, length);
78 }
79
80 static void
81 ipfc_print(const u_char *p, u_int length, u_int caplen)
82 {
83 const struct ipfc_header *ipfcp = (const struct ipfc_header *)p;
84 struct ether_header ehdr;
85 u_short extracted_ethertype;
86
87 if (caplen < IPFC_HDRLEN) {
88 printf("[|ipfc]");
89 return;
90 }
91 /*
92 * Get the network addresses into a canonical form
93 */
94 extract_ipfc_addrs(ipfcp, (char *)ESRC(&ehdr), (char *)EDST(&ehdr));
95
96 /*
97 * Some printers want to check that they're not walking off the
98 * end of the packet.
99 * Rather than pass it all the way down, we set this global.
100 */
101 snapend = p + caplen;
102
103 if (eflag)
104 ipfc_hdr_print(ipfcp, length, ESRC(&ehdr), EDST(&ehdr));
105
106 /* Skip over Network_Header */
107 length -= IPFC_HDRLEN;
108 p += IPFC_HDRLEN;
109 caplen -= IPFC_HDRLEN;
110
111 /* Frame Control field determines interpretation of packet */
112 extracted_ethertype = 0;
113 /* Try to print the LLC-layer header & higher layers */
114 if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
115 &extracted_ethertype) == 0) {
116 /*
117 * Some kinds of LLC packet we cannot
118 * handle intelligently
119 */
120 if (!eflag)
121 ipfc_hdr_print(ipfcp, length + IPFC_HDRLEN,
122 ESRC(&ehdr), EDST(&ehdr));
123 if (extracted_ethertype) {
124 printf("(LLC %s) ",
125 etherproto_string(htons(extracted_ethertype)));
126 }
127 if (!xflag && !qflag)
128 default_print(p, caplen);
129 }
130 }
131
132 /*
133 * This is the top level routine of the printer. 'sp' is the points
134 * to the Network_Header of the packet, 'tvp' is the timestamp,
135 * 'length' is the length of the packet off the wire, and 'caplen'
136 * is the number of bytes actually captured.
137 */
138 void
139 ipfc_if_print(u_char *pcap _U_, const struct pcap_pkthdr *h,
140 register const u_char *p)
141 {
142 u_int caplen = h->caplen;
143 u_int length = h->len;
144
145 ++infodelay;
146 ts_print(&h->ts);
147
148 ipfc_print(p, length, caplen);
149
150 /*
151 * If "-x" was specified, print stuff past the Network_Header,
152 * if there's anything to print.
153 */
154 if (xflag && caplen > IPFC_HDRLEN)
155 default_print(p + IPFC_HDRLEN, caplen - IPFC_HDRLEN);
156
157 putchar('\n');
158
159 --infodelay;
160 if (infoprint)
161 info(0);
162 }