141c99275SPeter Avalos /*
241c99275SPeter Avalos * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
341c99275SPeter Avalos * The Regents of the University of California. All rights reserved.
441c99275SPeter Avalos *
541c99275SPeter Avalos * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos * or promote products derived from this software without specific prior
1641c99275SPeter Avalos * written permission.
1741c99275SPeter Avalos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos */
21411677aeSAaron LI
22411677aeSAaron LI /* \summary: Apple IP-over-IEEE 1394 printer */
2341c99275SPeter Avalos
2441c99275SPeter Avalos #ifdef HAVE_CONFIG_H
25*ed775ee7SAntonio Huete Jimenez #include <config.h>
2641c99275SPeter Avalos #endif
2741c99275SPeter Avalos
28*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
2941c99275SPeter Avalos
30*ed775ee7SAntonio Huete Jimenez #define ND_LONGJMP_FROM_TCHECK
31411677aeSAaron LI #include "netdissect.h"
3227bfbee1SPeter Avalos #include "extract.h"
3341c99275SPeter Avalos #include "addrtoname.h"
3441c99275SPeter Avalos #include "ethertype.h"
3541c99275SPeter Avalos
3641c99275SPeter Avalos /*
3741c99275SPeter Avalos * Structure of a header for Apple's IP-over-IEEE 1384 BPF header.
3841c99275SPeter Avalos */
3941c99275SPeter Avalos #define FIREWIRE_EUI64_LEN 8
4041c99275SPeter Avalos struct firewire_header {
41*ed775ee7SAntonio Huete Jimenez nd_byte firewire_dhost[FIREWIRE_EUI64_LEN];
42*ed775ee7SAntonio Huete Jimenez nd_byte firewire_shost[FIREWIRE_EUI64_LEN];
43*ed775ee7SAntonio Huete Jimenez nd_uint16_t firewire_type;
4441c99275SPeter Avalos };
4541c99275SPeter Avalos
4641c99275SPeter Avalos /*
4741c99275SPeter Avalos * Length of that header; note that some compilers may pad
4841c99275SPeter Avalos * "struct firewire_header" to a multiple of 4 bytes, for example, so
4941c99275SPeter Avalos * "sizeof (struct firewire_header)" may not give the right answer.
5041c99275SPeter Avalos */
5141c99275SPeter Avalos #define FIREWIRE_HDRLEN 18
5241c99275SPeter Avalos
53411677aeSAaron LI static const char *
fwaddr_string(netdissect_options * ndo,const u_char * addr)54411677aeSAaron LI fwaddr_string(netdissect_options *ndo, const u_char *addr)
55411677aeSAaron LI {
56*ed775ee7SAntonio Huete Jimenez return GET_LINKADDR_STRING(addr, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN);
57411677aeSAaron LI }
58411677aeSAaron LI
59*ed775ee7SAntonio Huete Jimenez static void
ap1394_hdr_print(netdissect_options * ndo,const u_char * bp,u_int length)60*ed775ee7SAntonio Huete Jimenez ap1394_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
6141c99275SPeter Avalos {
62*ed775ee7SAntonio Huete Jimenez const struct firewire_header *fp;
63411677aeSAaron LI uint16_t firewire_type;
6427bfbee1SPeter Avalos
6541c99275SPeter Avalos fp = (const struct firewire_header *)bp;
6641c99275SPeter Avalos
67*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s > %s",
68411677aeSAaron LI fwaddr_string(ndo, fp->firewire_shost),
69*ed775ee7SAntonio Huete Jimenez fwaddr_string(ndo, fp->firewire_dhost));
7041c99275SPeter Avalos
71*ed775ee7SAntonio Huete Jimenez firewire_type = GET_BE_U_2(fp->firewire_type);
72411677aeSAaron LI if (!ndo->ndo_qflag) {
73*ed775ee7SAntonio Huete Jimenez ND_PRINT(", ethertype %s (0x%04x)",
7427bfbee1SPeter Avalos tok2str(ethertype_values,"Unknown", firewire_type),
75*ed775ee7SAntonio Huete Jimenez firewire_type);
7641c99275SPeter Avalos } else {
77*ed775ee7SAntonio Huete Jimenez ND_PRINT(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type));
7841c99275SPeter Avalos }
7941c99275SPeter Avalos
80*ed775ee7SAntonio Huete Jimenez ND_PRINT(", length %u: ", length);
8141c99275SPeter Avalos }
8241c99275SPeter Avalos
8341c99275SPeter Avalos /*
8441c99275SPeter Avalos * This is the top level routine of the printer. 'p' points
8541c99275SPeter Avalos * to the ether header of the packet, 'h->ts' is the timestamp,
8641c99275SPeter Avalos * 'h->len' is the length of the packet off the wire, and 'h->caplen'
8741c99275SPeter Avalos * is the number of bytes actually captured.
8841c99275SPeter Avalos */
89*ed775ee7SAntonio Huete Jimenez void
ap1394_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)90411677aeSAaron LI ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
9141c99275SPeter Avalos {
9241c99275SPeter Avalos u_int length = h->len;
9341c99275SPeter Avalos u_int caplen = h->caplen;
94411677aeSAaron LI const struct firewire_header *fp;
9541c99275SPeter Avalos u_short ether_type;
96411677aeSAaron LI struct lladdr_info src, dst;
9741c99275SPeter Avalos
98*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "ap1394";
99*ed775ee7SAntonio Huete Jimenez ND_TCHECK_LEN(p, FIREWIRE_HDRLEN);
100*ed775ee7SAntonio Huete Jimenez ndo->ndo_ll_hdr_len += FIREWIRE_HDRLEN;
10141c99275SPeter Avalos
102411677aeSAaron LI if (ndo->ndo_eflag)
103411677aeSAaron LI ap1394_hdr_print(ndo, p, length);
10441c99275SPeter Avalos
10541c99275SPeter Avalos length -= FIREWIRE_HDRLEN;
10641c99275SPeter Avalos caplen -= FIREWIRE_HDRLEN;
107411677aeSAaron LI fp = (const struct firewire_header *)p;
10841c99275SPeter Avalos p += FIREWIRE_HDRLEN;
10941c99275SPeter Avalos
110*ed775ee7SAntonio Huete Jimenez ether_type = GET_BE_U_2(fp->firewire_type);
111411677aeSAaron LI src.addr = fp->firewire_shost;
112411677aeSAaron LI src.addr_string = fwaddr_string;
113411677aeSAaron LI dst.addr = fp->firewire_dhost;
114411677aeSAaron LI dst.addr_string = fwaddr_string;
115411677aeSAaron LI if (ethertype_print(ndo, ether_type, p, length, caplen, &src, &dst) == 0) {
11641c99275SPeter Avalos /* ether_type not known, print raw packet */
117411677aeSAaron LI if (!ndo->ndo_eflag)
118411677aeSAaron LI ap1394_hdr_print(ndo, (const u_char *)fp, length + FIREWIRE_HDRLEN);
11941c99275SPeter Avalos
120411677aeSAaron LI if (!ndo->ndo_suppress_default_print)
121411677aeSAaron LI ND_DEFAULTPRINT(p, caplen);
12241c99275SPeter Avalos }
12341c99275SPeter Avalos }
124