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