1214456Srpaulo/*
2214456Srpaulo * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
3214456Srpaulo *	The Regents of the University of California.  All rights reserved.
4214456Srpaulo *
5214456Srpaulo * Redistribution and use in source and binary forms, with or without
6214456Srpaulo * modification, are permitted provided that: (1) source code distributions
7214456Srpaulo * retain the above copyright notice and this paragraph in its entirety, (2)
8214456Srpaulo * distributions including binary code include the above copyright notice and
9214456Srpaulo * this paragraph in its entirety in the documentation or other materials
10214456Srpaulo * provided with the distribution, and (3) all advertising materials mentioning
11214456Srpaulo * features or use of this software display the following acknowledgement:
12214456Srpaulo * ``This product includes software developed by the University of California,
13214456Srpaulo * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14214456Srpaulo * the University nor the names of its contributors may be used to endorse
15214456Srpaulo * or promote products derived from this software without specific prior
16214456Srpaulo * written permission.
17214456Srpaulo * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18214456Srpaulo * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19214456Srpaulo * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20214456Srpaulo */
21214456Srpaulo#ifndef lint
22214456Srpaulostatic const char rcsid[] _U_ =
23214456Srpaulo    "@(#) $Header: /tcpdump/master/tcpdump/print-ap1394.c,v 1.5 2006-02-11 22:12:06 hannes Exp $ (LBL)";
24214456Srpaulo#endif
25214456Srpaulo
26214456Srpaulo#ifdef HAVE_CONFIG_H
27214456Srpaulo#include "config.h"
28214456Srpaulo#endif
29214456Srpaulo
30214456Srpaulo#include <tcpdump-stdinc.h>
31214456Srpaulo
32214456Srpaulo#include <stdio.h>
33214456Srpaulo#include <pcap.h>
34214456Srpaulo
35214456Srpaulo#include "interface.h"
36214456Srpaulo#include "extract.h"
37214456Srpaulo#include "addrtoname.h"
38214456Srpaulo#include "ethertype.h"
39214456Srpaulo
40214456Srpaulo/*
41214456Srpaulo * Structure of a header for Apple's IP-over-IEEE 1384 BPF header.
42214456Srpaulo */
43214456Srpaulo#define FIREWIRE_EUI64_LEN	8
44214456Srpaulostruct firewire_header {
45214456Srpaulo	u_char  firewire_dhost[FIREWIRE_EUI64_LEN];
46214456Srpaulo	u_char  firewire_shost[FIREWIRE_EUI64_LEN];
47214456Srpaulo	u_short firewire_type;
48214456Srpaulo};
49214456Srpaulo
50214456Srpaulo/*
51214456Srpaulo * Length of that header; note that some compilers may pad
52214456Srpaulo * "struct firewire_header" to a multiple of 4 bytes, for example, so
53214456Srpaulo * "sizeof (struct firewire_header)" may not give the right answer.
54214456Srpaulo */
55214456Srpaulo#define FIREWIRE_HDRLEN		18
56214456Srpaulo
57214456Srpaulostatic inline void
58214456Srpauloap1394_hdr_print(register const u_char *bp, u_int length)
59214456Srpaulo{
60214456Srpaulo	register const struct firewire_header *fp;
61214456Srpaulo	u_int16_t firewire_type;
62214456Srpaulo
63214456Srpaulo	fp = (const struct firewire_header *)bp;
64214456Srpaulo
65214456Srpaulo	(void)printf("%s > %s",
66214456Srpaulo		     linkaddr_string(fp->firewire_dhost, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN),
67214456Srpaulo		     linkaddr_string(fp->firewire_shost, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN));
68214456Srpaulo
69214456Srpaulo	firewire_type = EXTRACT_16BITS(&fp->firewire_type);
70214456Srpaulo	if (!qflag) {
71214456Srpaulo		(void)printf(", ethertype %s (0x%04x)",
72214456Srpaulo			       tok2str(ethertype_values,"Unknown", firewire_type),
73214456Srpaulo                               firewire_type);
74214456Srpaulo        } else {
75214456Srpaulo                (void)printf(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type));
76214456Srpaulo        }
77214456Srpaulo
78214456Srpaulo	(void)printf(", length %u: ", length);
79214456Srpaulo}
80214456Srpaulo
81214456Srpaulo/*
82214456Srpaulo * This is the top level routine of the printer.  'p' points
83214456Srpaulo * to the ether header of the packet, 'h->ts' is the timestamp,
84214456Srpaulo * 'h->len' is the length of the packet off the wire, and 'h->caplen'
85214456Srpaulo * is the number of bytes actually captured.
86214456Srpaulo */
87214456Srpaulou_int
88214456Srpauloap1394_if_print(const struct pcap_pkthdr *h, const u_char *p)
89214456Srpaulo{
90214456Srpaulo	u_int length = h->len;
91214456Srpaulo	u_int caplen = h->caplen;
92214456Srpaulo	struct firewire_header *fp;
93214456Srpaulo	u_short ether_type;
94214456Srpaulo
95214456Srpaulo	if (caplen < FIREWIRE_HDRLEN) {
96214456Srpaulo		printf("[|ap1394]");
97214456Srpaulo		return FIREWIRE_HDRLEN;
98214456Srpaulo	}
99214456Srpaulo
100214456Srpaulo	if (eflag)
101214456Srpaulo		ap1394_hdr_print(p, length);
102214456Srpaulo
103214456Srpaulo	length -= FIREWIRE_HDRLEN;
104214456Srpaulo	caplen -= FIREWIRE_HDRLEN;
105214456Srpaulo	fp = (struct firewire_header *)p;
106214456Srpaulo	p += FIREWIRE_HDRLEN;
107214456Srpaulo
108214456Srpaulo	ether_type = EXTRACT_16BITS(&fp->firewire_type);
109214456Srpaulo	if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) {
110214456Srpaulo		/* ether_type not known, print raw packet */
111214456Srpaulo		if (!eflag)
112214456Srpaulo			ap1394_hdr_print((u_char *)fp, length + FIREWIRE_HDRLEN);
113214456Srpaulo
114214456Srpaulo		if (!suppress_default_print)
115214456Srpaulo			default_print(p, caplen);
116214456Srpaulo	}
117214456Srpaulo
118214456Srpaulo	return FIREWIRE_HDRLEN;
119214456Srpaulo}
120214456Srpaulo