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