2009-11-25 10:20:25 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <tcpdump-stdinc.h>
|
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2013-12-31 14:52:15 +08:00
|
|
|
|
|
|
|
typedef struct ipnet_hdr {
|
|
|
|
uint8_t iph_version;
|
|
|
|
uint8_t iph_family;
|
|
|
|
uint16_t iph_htype;
|
|
|
|
uint32_t iph_pktlen;
|
|
|
|
uint32_t iph_ifindex;
|
|
|
|
uint32_t iph_grifindex;
|
|
|
|
uint32_t iph_zsrc;
|
|
|
|
uint32_t iph_zdst;
|
|
|
|
} ipnet_hdr_t;
|
|
|
|
|
|
|
|
#define IPH_AF_INET 2 /* Matches Solaris's AF_INET */
|
|
|
|
#define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */
|
2009-11-25 10:20:25 +08:00
|
|
|
|
|
|
|
#ifdef DLT_IPNET
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok ipnet_values[] = {
|
2009-11-25 10:20:25 +08:00
|
|
|
{ IPH_AF_INET, "IPv4" },
|
|
|
|
{ IPH_AF_INET6, "IPv6" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void
|
2014-04-04 15:43:46 +08:00
|
|
|
ipnet_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
|
2009-11-25 10:20:25 +08:00
|
|
|
{
|
|
|
|
const ipnet_hdr_t *hdr;
|
|
|
|
hdr = (const ipnet_hdr_t *)bp;
|
|
|
|
|
2009-11-25 10:31:04 +08:00
|
|
|
ND_PRINT((ndo, "%d > %d", hdr->iph_zsrc, hdr->iph_zdst));
|
2009-11-25 10:20:25 +08:00
|
|
|
|
2009-11-25 10:31:04 +08:00
|
|
|
if (!ndo->ndo_qflag) {
|
|
|
|
ND_PRINT((ndo,", family %s (%d)",
|
|
|
|
tok2str(ipnet_values, "Unknown",
|
|
|
|
hdr->iph_family),
|
|
|
|
hdr->iph_family));
|
2009-11-25 10:20:25 +08:00
|
|
|
} else {
|
2009-11-25 10:31:04 +08:00
|
|
|
ND_PRINT((ndo,", %s",
|
|
|
|
tok2str(ipnet_values,
|
|
|
|
"Unknown Ethertype (0x%04x)",
|
|
|
|
hdr->iph_family)));
|
2009-11-25 10:20:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-25 10:31:04 +08:00
|
|
|
ND_PRINT((ndo, ", length %u: ", length));
|
2009-11-25 10:20:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-27 06:57:38 +08:00
|
|
|
static void
|
2014-04-04 15:43:46 +08:00
|
|
|
ipnet_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
|
2009-11-25 10:20:25 +08:00
|
|
|
{
|
2015-04-27 08:24:42 +08:00
|
|
|
const ipnet_hdr_t *hdr;
|
2009-11-25 10:20:25 +08:00
|
|
|
|
|
|
|
if (caplen < sizeof(ipnet_hdr_t)) {
|
2009-11-25 10:31:04 +08:00
|
|
|
ND_PRINT((ndo, "[|ipnet]"));
|
2009-11-25 10:20:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-25 10:31:04 +08:00
|
|
|
if (ndo->ndo_eflag)
|
|
|
|
ipnet_hdr_print(ndo, p, length);
|
2009-11-25 10:20:25 +08:00
|
|
|
|
|
|
|
length -= sizeof(ipnet_hdr_t);
|
|
|
|
caplen -= sizeof(ipnet_hdr_t);
|
2015-04-27 08:24:42 +08:00
|
|
|
hdr = (const ipnet_hdr_t *)p;
|
2009-11-25 10:20:25 +08:00
|
|
|
p += sizeof(ipnet_hdr_t);
|
|
|
|
|
2009-11-26 05:26:52 +08:00
|
|
|
switch (hdr->iph_family) {
|
|
|
|
|
|
|
|
case IPH_AF_INET:
|
|
|
|
ip_print(ndo, p, length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IPH_AF_INET6:
|
2010-11-08 04:50:16 +08:00
|
|
|
ip6_print(ndo, p, length);
|
2009-11-26 05:26:52 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-11-25 10:31:04 +08:00
|
|
|
if (!ndo->ndo_eflag)
|
2015-04-27 08:24:42 +08:00
|
|
|
ipnet_hdr_print(ndo, (const u_char *)hdr,
|
2009-11-25 10:20:25 +08:00
|
|
|
length + sizeof(ipnet_hdr_t));
|
|
|
|
|
2009-11-25 10:31:04 +08:00
|
|
|
if (!ndo->ndo_suppress_default_print)
|
2014-03-26 22:52:40 +08:00
|
|
|
ND_DEFAULTPRINT(p, caplen);
|
2009-11-26 05:26:52 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-11-25 10:20:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the top level routine of the printer. 'p' points
|
|
|
|
* to the ether header of the packet, 'h->ts' is the timestamp,
|
|
|
|
* 'h->len' is the length of the packet off the wire, and 'h->caplen'
|
|
|
|
* is the number of bytes actually captured.
|
|
|
|
*/
|
|
|
|
u_int
|
2014-04-04 15:43:46 +08:00
|
|
|
ipnet_if_print(netdissect_options *ndo,
|
2010-01-11 03:36:07 +08:00
|
|
|
const struct pcap_pkthdr *h, const u_char *p)
|
2009-11-25 10:20:25 +08:00
|
|
|
{
|
2009-11-25 10:31:04 +08:00
|
|
|
ipnet_print(ndo, p, h->len, h->caplen);
|
2009-11-25 10:20:25 +08:00
|
|
|
|
|
|
|
return (sizeof(ipnet_hdr_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-style: whitesmith
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif /* DLT_IPNET */
|