X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/3c4027f5993cf8def131e56b98d1c137be1b1f72..refs/pull/471/head:/print-802_15_4.c diff --git a/print-802_15_4.c b/print-802_15_4.c index a5364124..4a1ef49b 100644 --- a/print-802_15_4.c +++ b/print-802_15_4.c @@ -24,13 +24,9 @@ #include "config.h" #endif -#include +#include -#include -#include -#include - -#include "interface.h" +#include "netdissect.h" #include "addrtoname.h" #include "extract.h" @@ -47,16 +43,16 @@ static const char *ftypes[] = { }; static int -extract_header_length(u_int16_t fc) +extract_header_length(uint16_t fc) { int len = 0; switch ((fc >> 10) & 0x3) { - case 0x0: + case 0x00: if (fc & (1 << 6)) /* intra-PAN with none dest addr */ return -1; break; - case 0x1: + case 0x01: return -1; case 0x02: len += 4; @@ -67,9 +63,9 @@ extract_header_length(u_int16_t fc) } switch ((fc >> 14) & 0x3) { - case 0x0: + case 0x00: break; - case 0x1: + case 0x01: return -1; case 0x02: len += 4; @@ -79,23 +75,27 @@ extract_header_length(u_int16_t fc) break; } - if (fc & (1 << 6)) + if (fc & (1 << 6)) { + if (len < 2) + return -1; len -= 2; + } return len; } u_int -ieee802_15_4_if_print(const struct pcap_pkthdr *h, const u_char *p) +ieee802_15_4_if_print(netdissect_options *ndo, + const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; - u_int hdrlen; - u_int16_t fc; - u_int8_t seq; + int hdrlen; + uint16_t fc; + uint8_t seq; if (caplen < 3) { - printf("[|802.15.4] %x", caplen); + ND_PRINT((ndo, "[|802.15.4] %x", caplen)); return caplen; } @@ -107,50 +107,56 @@ ieee802_15_4_if_print(const struct pcap_pkthdr *h, const u_char *p) p += 3; caplen -= 3; - printf("IEEE 802.15.4 %s packet ", ftypes[fc & 0x7]); - if (vflag) - printf("seq %02x ", seq); + ND_PRINT((ndo,"IEEE 802.15.4 %s packet ", ftypes[fc & 0x7])); + if (ndo->ndo_vflag) + ND_PRINT((ndo,"seq %02x ", seq)); if (hdrlen == -1) { - printf("malformed! "); + ND_PRINT((ndo,"invalid! ")); return caplen; } - if (!vflag) { + if (!ndo->ndo_vflag) { p+= hdrlen; caplen -= hdrlen; } else { - u_int16_t panid; + uint16_t panid = 0; switch ((fc >> 10) & 0x3) { case 0x00: - printf("none "); + ND_PRINT((ndo,"none ")); break; + case 0x01: + ND_PRINT((ndo,"reserved destination addressing mode")); + return 0; case 0x02: panid = EXTRACT_LE_16BITS(p); p += 2; - printf("%04x:%04x ", panid, EXTRACT_LE_16BITS(p)); + ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p))); p += 2; break; case 0x03: panid = EXTRACT_LE_16BITS(p); p += 2; - printf("%04x:%s ", panid, le64addr_string(p)); + ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(ndo, p))); p += 8; break; } - printf("< "); + ND_PRINT((ndo,"< ")); switch ((fc >> 14) & 0x3) { case 0x00: - printf("none "); + ND_PRINT((ndo,"none ")); break; + case 0x01: + ND_PRINT((ndo,"reserved source addressing mode")); + return 0; case 0x02: if (!(fc & (1 << 6))) { panid = EXTRACT_LE_16BITS(p); p += 2; } - printf("%04x:%04x ", panid, EXTRACT_LE_16BITS(p)); + ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p))); p += 2; break; case 0x03: @@ -158,7 +164,7 @@ ieee802_15_4_if_print(const struct pcap_pkthdr *h, const u_char *p) panid = EXTRACT_LE_16BITS(p); p += 2; } - printf("%04x:%s ", panid, le64addr_string(p)); + ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(ndo, p))); p += 8; break; } @@ -166,8 +172,8 @@ ieee802_15_4_if_print(const struct pcap_pkthdr *h, const u_char *p) caplen -= hdrlen; } - if (!suppress_default_print) - default_print(p, caplen); + if (!ndo->ndo_suppress_default_print) + ND_DEFAULTPRINT(p, caplen); return 0; }