1999-11-21 11:52:11 +08:00
|
|
|
/*
|
2002-06-12 01:08:37 +08:00
|
|
|
* Marko Kiiskila carnil@cs.tut.fi
|
|
|
|
*
|
1999-11-21 11:52:11 +08:00
|
|
|
* Tampere University of Technology - Telecommunications Laboratory
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this
|
|
|
|
* software and its documentation is hereby granted,
|
|
|
|
* provided that both the copyright notice and this
|
|
|
|
* permission notice appear in all copies of the software,
|
|
|
|
* derivative works or modified versions, and any portions
|
|
|
|
* thereof, that both notices appear in supporting
|
|
|
|
* documentation, and that the use of this software is
|
|
|
|
* acknowledged in any publications resulting from using
|
|
|
|
* the software.
|
2002-06-12 01:08:37 +08:00
|
|
|
*
|
1999-11-21 11:52:11 +08:00
|
|
|
* TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
|
|
|
|
* SOFTWARE.
|
2002-06-12 01:08:37 +08:00
|
|
|
*
|
1999-11-21 11:52:11 +08:00
|
|
|
*/
|
|
|
|
|
2016-08-14 21:42:19 +08:00
|
|
|
/* \summary: Classical-IP over ATM printer */
|
|
|
|
|
1999-11-21 17:36:43 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
1999-11-21 11:52:11 +08:00
|
|
|
#endif
|
|
|
|
|
2001-03-19 11:58:10 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
1999-11-21 11:52:11 +08:00
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
1999-11-21 11:52:11 +08:00
|
|
|
#include "addrtoname.h"
|
|
|
|
|
2013-12-19 18:05:59 +08:00
|
|
|
static const unsigned char rfcllc[] = {
|
2000-04-28 19:34:12 +08:00
|
|
|
0xaa, /* DSAP: non-ISO */
|
|
|
|
0xaa, /* SSAP: non-ISO */
|
|
|
|
0x03, /* Ctrl: Unnumbered Information Command PDU */
|
|
|
|
0x00, /* OUI: EtherType */
|
|
|
|
0x00,
|
|
|
|
0x00 };
|
1999-11-21 11:52:11 +08:00
|
|
|
|
2018-01-26 22:15:58 +08:00
|
|
|
static void
|
2015-07-04 02:24:37 +08:00
|
|
|
cip_print(netdissect_options *ndo, u_int length)
|
1999-11-21 11:52:11 +08:00
|
|
|
{
|
2001-09-24 05:52:38 +08:00
|
|
|
/*
|
|
|
|
* There is no MAC-layer header, so just print the length.
|
|
|
|
*/
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%u: ", length);
|
1999-11-21 11:52:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-06 05:25:34 +08:00
|
|
|
* This is the top level routine of the printer. 'p' points
|
|
|
|
* to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
|
2004-03-18 07:24:35 +08:00
|
|
|
* 'h->len' is the length of the packet off the wire, and 'h->caplen'
|
1999-11-21 11:52:11 +08:00
|
|
|
* is the number of bytes actually captured.
|
|
|
|
*/
|
2002-12-19 17:39:10 +08:00
|
|
|
u_int
|
2014-02-28 17:42:37 +08:00
|
|
|
cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
|
1999-11-21 11:52:11 +08:00
|
|
|
{
|
2001-09-18 05:57:50 +08:00
|
|
|
u_int caplen = h->caplen;
|
|
|
|
u_int length = h->len;
|
2015-07-04 02:24:37 +08:00
|
|
|
size_t cmplen;
|
2015-04-18 14:42:22 +08:00
|
|
|
int llc_hdrlen;
|
1999-11-21 11:52:11 +08:00
|
|
|
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "cip_if";
|
2015-07-04 02:24:37 +08:00
|
|
|
cmplen = sizeof(rfcllc);
|
|
|
|
if (cmplen > caplen)
|
|
|
|
cmplen = caplen;
|
|
|
|
if (cmplen > length)
|
|
|
|
cmplen = length;
|
1999-11-21 11:52:11 +08:00
|
|
|
|
2014-02-28 17:42:37 +08:00
|
|
|
if (ndo->ndo_eflag)
|
|
|
|
cip_print(ndo, length);
|
1999-11-21 11:52:11 +08:00
|
|
|
|
2015-07-04 02:24:37 +08:00
|
|
|
if (cmplen == 0) {
|
2018-05-11 00:05:56 +08:00
|
|
|
nd_print_trunc(ndo);
|
2015-07-04 02:24:37 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (memcmp(rfcllc, p, cmplen) == 0) {
|
2001-09-24 05:52:38 +08:00
|
|
|
/*
|
|
|
|
* LLC header is present. Try to print it & higher layers.
|
|
|
|
*/
|
2015-04-18 14:42:22 +08:00
|
|
|
llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
|
|
|
|
if (llc_hdrlen < 0) {
|
|
|
|
/* packet type not known, print raw packet */
|
2014-02-28 17:42:37 +08:00
|
|
|
if (!ndo->ndo_suppress_default_print)
|
2014-03-26 22:52:40 +08:00
|
|
|
ND_DEFAULTPRINT(p, caplen);
|
2015-04-18 14:42:22 +08:00
|
|
|
llc_hdrlen = -llc_hdrlen;
|
1999-11-21 11:52:11 +08:00
|
|
|
}
|
2001-09-24 05:52:38 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* LLC header is absent; treat it as just IP.
|
|
|
|
*/
|
2015-04-18 14:42:22 +08:00
|
|
|
llc_hdrlen = 0;
|
2014-02-28 17:42:37 +08:00
|
|
|
ip_print(ndo, p, length);
|
1999-11-21 11:52:11 +08:00
|
|
|
}
|
2001-09-24 05:52:38 +08:00
|
|
|
|
2015-04-18 14:42:22 +08:00
|
|
|
return (llc_hdrlen);
|
1999-11-21 11:52:11 +08:00
|
|
|
}
|