141c99275SPeter Avalos /*
241c99275SPeter Avalos * Marko Kiiskila carnil@cs.tut.fi
341c99275SPeter Avalos *
441c99275SPeter Avalos * Tampere University of Technology - Telecommunications Laboratory
541c99275SPeter Avalos *
641c99275SPeter Avalos * Permission to use, copy, modify and distribute this
741c99275SPeter Avalos * software and its documentation is hereby granted,
841c99275SPeter Avalos * provided that both the copyright notice and this
941c99275SPeter Avalos * permission notice appear in all copies of the software,
1041c99275SPeter Avalos * derivative works or modified versions, and any portions
1141c99275SPeter Avalos * thereof, that both notices appear in supporting
1241c99275SPeter Avalos * documentation, and that the use of this software is
1341c99275SPeter Avalos * acknowledged in any publications resulting from using
1441c99275SPeter Avalos * the software.
1541c99275SPeter Avalos *
1641c99275SPeter Avalos * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1741c99275SPeter Avalos * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
1841c99275SPeter Avalos * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
1941c99275SPeter Avalos * SOFTWARE.
2041c99275SPeter Avalos *
2141c99275SPeter Avalos */
2241c99275SPeter Avalos
23*ed775ee7SAntonio Huete Jimenez /* \summary: Linux Classical IP over ATM printer */
2441c99275SPeter Avalos
2541c99275SPeter Avalos #ifdef HAVE_CONFIG_H
26*ed775ee7SAntonio Huete Jimenez #include <config.h>
2741c99275SPeter Avalos #endif
2841c99275SPeter Avalos
2941c99275SPeter Avalos #include <string.h>
3041c99275SPeter Avalos
31*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3241c99275SPeter Avalos
33*ed775ee7SAntonio Huete Jimenez #define ND_LONGJMP_FROM_TCHECK
34411677aeSAaron LI #include "netdissect.h"
3541c99275SPeter Avalos #include "addrtoname.h"
3641c99275SPeter Avalos
37411677aeSAaron LI static const unsigned char rfcllc[] = {
3841c99275SPeter Avalos 0xaa, /* DSAP: non-ISO */
3941c99275SPeter Avalos 0xaa, /* SSAP: non-ISO */
4041c99275SPeter Avalos 0x03, /* Ctrl: Unnumbered Information Command PDU */
4141c99275SPeter Avalos 0x00, /* OUI: EtherType */
4241c99275SPeter Avalos 0x00,
4341c99275SPeter Avalos 0x00 };
4441c99275SPeter Avalos
4541c99275SPeter Avalos /*
4641c99275SPeter Avalos * This is the top level routine of the printer. 'p' points
4741c99275SPeter Avalos * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
4841c99275SPeter Avalos * 'h->len' is the length of the packet off the wire, and 'h->caplen'
4941c99275SPeter Avalos * is the number of bytes actually captured.
5041c99275SPeter Avalos */
51*ed775ee7SAntonio Huete Jimenez void
cip_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)52411677aeSAaron LI cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
5341c99275SPeter Avalos {
5441c99275SPeter Avalos u_int caplen = h->caplen;
5541c99275SPeter Avalos u_int length = h->len;
56411677aeSAaron LI int llc_hdrlen;
5741c99275SPeter Avalos
58*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "cip";
59411677aeSAaron LI
60411677aeSAaron LI if (ndo->ndo_eflag)
61*ed775ee7SAntonio Huete Jimenez /*
62*ed775ee7SAntonio Huete Jimenez * There is no MAC-layer header, so just print the length.
63*ed775ee7SAntonio Huete Jimenez */
64*ed775ee7SAntonio Huete Jimenez ND_PRINT("%u: ", length);
65411677aeSAaron LI
66*ed775ee7SAntonio Huete Jimenez ND_TCHECK_LEN(p, sizeof(rfcllc));
67*ed775ee7SAntonio Huete Jimenez if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
6841c99275SPeter Avalos /*
6941c99275SPeter Avalos * LLC header is present. Try to print it & higher layers.
7041c99275SPeter Avalos */
71411677aeSAaron LI llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
72411677aeSAaron LI if (llc_hdrlen < 0) {
73411677aeSAaron LI /* packet type not known, print raw packet */
74411677aeSAaron LI if (!ndo->ndo_suppress_default_print)
75411677aeSAaron LI ND_DEFAULTPRINT(p, caplen);
76411677aeSAaron LI llc_hdrlen = -llc_hdrlen;
7741c99275SPeter Avalos }
7841c99275SPeter Avalos } else {
7941c99275SPeter Avalos /*
8041c99275SPeter Avalos * LLC header is absent; treat it as just IP.
8141c99275SPeter Avalos */
82411677aeSAaron LI llc_hdrlen = 0;
83411677aeSAaron LI ip_print(ndo, p, length);
8441c99275SPeter Avalos }
8541c99275SPeter Avalos
86*ed775ee7SAntonio Huete Jimenez ndo->ndo_ll_hdr_len += llc_hdrlen;
8741c99275SPeter Avalos }
88