1127668Sbms/*
2127668Sbms * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
3127668Sbms *	The Regents of the University of California.  All rights reserved.
4127668Sbms *
5127668Sbms * Redistribution and use in source and binary forms, with or without
6127668Sbms * modification, are permitted provided that: (1) source code distributions
7127668Sbms * retain the above copyright notice and this paragraph in its entirety, (2)
8127668Sbms * distributions including binary code include the above copyright notice and
9127668Sbms * this paragraph in its entirety in the documentation or other materials
10127668Sbms * provided with the distribution, and (3) all advertising materials mentioning
11127668Sbms * features or use of this software display the following acknowledgement:
12127668Sbms * ``This product includes software developed by the University of California,
13127668Sbms * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14127668Sbms * the University nor the names of its contributors may be used to endorse
15127668Sbms * or promote products derived from this software without specific prior
16127668Sbms * written permission.
17127668Sbms * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18127668Sbms * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19127668Sbms * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20127668Sbms */
21127668Sbms#ifndef lint
22127668Sbmsstatic const char rcsid[] _U_ =
23190207Srpaulo    "@(#) $Header: /tcpdump/master/tcpdump/print-ap1394.c,v 1.5 2006-02-11 22:12:06 hannes Exp $ (LBL)";
24127668Sbms#endif
25127668Sbms
26127668Sbms#ifdef HAVE_CONFIG_H
27127668Sbms#include "config.h"
28127668Sbms#endif
29127668Sbms
30127668Sbms#include <tcpdump-stdinc.h>
31127668Sbms
32127668Sbms#include <stdio.h>
33127668Sbms#include <pcap.h>
34127668Sbms
35127668Sbms#include "interface.h"
36214478Srpaulo#include "extract.h"
37127668Sbms#include "addrtoname.h"
38127668Sbms#include "ethertype.h"
39127668Sbms
40127668Sbms/*
41127668Sbms * Structure of a header for Apple's IP-over-IEEE 1384 BPF header.
42127668Sbms */
43127668Sbms#define FIREWIRE_EUI64_LEN	8
44127668Sbmsstruct firewire_header {
45127668Sbms	u_char  firewire_dhost[FIREWIRE_EUI64_LEN];
46127668Sbms	u_char  firewire_shost[FIREWIRE_EUI64_LEN];
47127668Sbms	u_short firewire_type;
48127668Sbms};
49127668Sbms
50127668Sbms/*
51127668Sbms * Length of that header; note that some compilers may pad
52127668Sbms * "struct firewire_header" to a multiple of 4 bytes, for example, so
53127668Sbms * "sizeof (struct firewire_header)" may not give the right answer.
54127668Sbms */
55127668Sbms#define FIREWIRE_HDRLEN		18
56127668Sbms
57127668Sbmsstatic inline void
58127668Sbmsap1394_hdr_print(register const u_char *bp, u_int length)
59127668Sbms{
60127668Sbms	register const struct firewire_header *fp;
61214478Srpaulo	u_int16_t firewire_type;
62214478Srpaulo
63127668Sbms	fp = (const struct firewire_header *)bp;
64127668Sbms
65127668Sbms	(void)printf("%s > %s",
66190207Srpaulo		     linkaddr_string(fp->firewire_dhost, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN),
67190207Srpaulo		     linkaddr_string(fp->firewire_shost, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN));
68127668Sbms
69214478Srpaulo	firewire_type = EXTRACT_16BITS(&fp->firewire_type);
70127668Sbms	if (!qflag) {
71127668Sbms		(void)printf(", ethertype %s (0x%04x)",
72214478Srpaulo			       tok2str(ethertype_values,"Unknown", firewire_type),
73214478Srpaulo                               firewire_type);
74127668Sbms        } else {
75214478Srpaulo                (void)printf(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type));
76127668Sbms        }
77127668Sbms
78127668Sbms	(void)printf(", length %u: ", length);
79127668Sbms}
80127668Sbms
81127668Sbms/*
82127668Sbms * This is the top level routine of the printer.  'p' points
83127668Sbms * to the ether header of the packet, 'h->ts' is the timestamp,
84146773Ssam * 'h->len' is the length of the packet off the wire, and 'h->caplen'
85127668Sbms * is the number of bytes actually captured.
86127668Sbms */
87127668Sbmsu_int
88127668Sbmsap1394_if_print(const struct pcap_pkthdr *h, const u_char *p)
89127668Sbms{
90127668Sbms	u_int length = h->len;
91127668Sbms	u_int caplen = h->caplen;
92127668Sbms	struct firewire_header *fp;
93127668Sbms	u_short ether_type;
94127668Sbms
95127668Sbms	if (caplen < FIREWIRE_HDRLEN) {
96127668Sbms		printf("[|ap1394]");
97127668Sbms		return FIREWIRE_HDRLEN;
98127668Sbms	}
99127668Sbms
100127668Sbms	if (eflag)
101127668Sbms		ap1394_hdr_print(p, length);
102127668Sbms
103127668Sbms	length -= FIREWIRE_HDRLEN;
104127668Sbms	caplen -= FIREWIRE_HDRLEN;
105127668Sbms	fp = (struct firewire_header *)p;
106127668Sbms	p += FIREWIRE_HDRLEN;
107127668Sbms
108214478Srpaulo	ether_type = EXTRACT_16BITS(&fp->firewire_type);
109235530Sdelphij	if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) {
110127668Sbms		/* ether_type not known, print raw packet */
111127668Sbms		if (!eflag)
112127668Sbms			ap1394_hdr_print((u_char *)fp, length + FIREWIRE_HDRLEN);
113127668Sbms
114162017Ssam		if (!suppress_default_print)
115127668Sbms			default_print(p, caplen);
116127668Sbms	}
117127668Sbms
118127668Sbms	return FIREWIRE_HDRLEN;
119127668Sbms}
120