]> The Tcpdump Group git mirrors - tcpdump/blob - print-ipfc.c
dismiss NETDISSECT_REWORKED macro
[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 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <tcpdump-stdinc.h>
27
28 #include <string.h>
29
30 #include "interface.h"
31 #include "addrtoname.h"
32
33 #include "ether.h"
34
35 /*
36 * RFC 2625 IP-over-Fibre Channel.
37 */
38
39 struct ipfc_header {
40 u_char ipfc_dhost[8];
41 u_char ipfc_shost[8];
42 };
43
44 #define IPFC_HDRLEN 16
45
46 /* Extract src, dst addresses */
47 static inline void
48 extract_ipfc_addrs(const struct ipfc_header *ipfcp, char *ipfcsrc,
49 char *ipfcdst)
50 {
51 /*
52 * We assume that, as per RFC 2625, the lower 48 bits of the
53 * source and destination addresses are MAC addresses.
54 */
55 memcpy(ipfcdst, (const char *)&ipfcp->ipfc_dhost[2], 6);
56 memcpy(ipfcsrc, (const char *)&ipfcp->ipfc_shost[2], 6);
57 }
58
59 /*
60 * Print the Network_Header
61 */
62 static inline void
63 ipfc_hdr_print(netdissect_options *ndo,
64 register const struct ipfc_header *ipfcp _U_,
65 register u_int length, register const u_char *ipfcsrc,
66 register const u_char *ipfcdst)
67 {
68 const char *srcname, *dstname;
69
70 srcname = etheraddr_string(ndo, ipfcsrc);
71 dstname = etheraddr_string(ndo, ipfcdst);
72
73 /*
74 * XXX - show the upper 16 bits? Do so only if "vflag" is set?
75 */
76 ND_PRINT((ndo, "%s %s %d: ", srcname, dstname, length));
77 }
78
79 static void
80 ipfc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
81 {
82 const struct ipfc_header *ipfcp = (const struct ipfc_header *)p;
83 struct ether_header ehdr;
84 u_short extracted_ethertype;
85
86 if (caplen < IPFC_HDRLEN) {
87 ND_PRINT((ndo, "[|ipfc]"));
88 return;
89 }
90 /*
91 * Get the network addresses into a canonical form
92 */
93 extract_ipfc_addrs(ipfcp, (char *)ESRC(&ehdr), (char *)EDST(&ehdr));
94
95 if (ndo->ndo_eflag)
96 ipfc_hdr_print(ndo, ipfcp, length, ESRC(&ehdr), EDST(&ehdr));
97
98 /* Skip over Network_Header */
99 length -= IPFC_HDRLEN;
100 p += IPFC_HDRLEN;
101 caplen -= IPFC_HDRLEN;
102
103 /* Try to print the LLC-layer header & higher layers */
104 if (llc_print(ndo, p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
105 &extracted_ethertype) == 0) {
106 /*
107 * Some kinds of LLC packet we cannot
108 * handle intelligently
109 */
110 if (!ndo->ndo_eflag)
111 ipfc_hdr_print(ndo, ipfcp, length + IPFC_HDRLEN,
112 ESRC(&ehdr), EDST(&ehdr));
113 if (extracted_ethertype) {
114 ND_PRINT((ndo, "(LLC %s) ",
115 etherproto_string(htons(extracted_ethertype))));
116 }
117 if (!ndo->ndo_suppress_default_print)
118 ND_DEFAULTPRINT(p, caplen);
119 }
120 }
121
122 /*
123 * This is the top level routine of the printer. 'p' points
124 * to the Network_Header of the packet, 'h->ts' is the timestamp,
125 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
126 * is the number of bytes actually captured.
127 */
128 u_int
129 ipfc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p)
130 {
131 ipfc_print(ndo, p, h->len, h->caplen);
132
133 return (IPFC_HDRLEN);
134 }