summaryrefslogtreecommitdiff
path: root/print-pgm.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-09-17 14:56:44 -0700
committerGuy Harris <guy@alum.mit.edu>2015-09-17 14:56:44 -0700
commit11f73ad248fa22461ca040baa8dc94b864509efa (patch)
tree5a0e2679a78a1dfbe2388b4bf2d55490a38ef989 /print-pgm.c
parent2a85a1bba4c2e63094a259c5d0ed397f234ba5f3 (diff)
downloadtcpdump-11f73ad248fa22461ca040baa8dc94b864509efa.tar.gz
Don't require IPv6 library support in order to support IPv6 addresses.
Have our own routines to convert between IPv4/IPv6 addresses and strings; that helps if, for example, we want to build binary versions of tcpdump for Windows that can run both on NT 5 (W2K/WXP), which doesn't have inet_ntop() or inet_pton(), and NT 6 (Vista/7/8/10), which do. It also means that we don't require IPv6 library support on UN*X to print addresses (if somebody wants to build tcpdump for older UN*Xes lacking IPv6 support in the system library or in add-on libraries). Get rid of files in the missing directory that we don't need, and various no-longer-necessary autoconf tests.
Diffstat (limited to 'print-pgm.c')
-rw-r--r--print-pgm.c215
1 files changed, 89 insertions, 126 deletions
diff --git a/print-pgm.c b/print-pgm.c
index ddba527f..0d5685d9 100644
--- a/print-pgm.c
+++ b/print-pgm.c
@@ -22,11 +22,10 @@
#include "netdissect.h"
#include "extract.h"
#include "addrtoname.h"
+#include "addrtostr.h"
#include "ip.h"
-#ifdef INET6
#include "ip6.h"
-#endif
#include "ipproto.h"
#include "af.h"
@@ -150,42 +149,26 @@ pgm_print(netdissect_options *ndo,
register const struct ip *ip;
register char ch;
uint16_t sport, dport;
- int addr_size;
- const void *nla;
- int nla_af;
-#ifdef INET6
+ u_int nla_afnum;
char nla_buf[INET6_ADDRSTRLEN];
register const struct ip6_hdr *ip6;
-#else
- char nla_buf[INET_ADDRSTRLEN];
-#endif
uint8_t opt_type, opt_len;
uint32_t seq, opts_len, len, offset;
pgm = (const struct pgm_header *)bp;
ip = (const struct ip *)bp2;
-#ifdef INET6
if (IP_V(ip) == 6)
ip6 = (const struct ip6_hdr *)bp2;
else
ip6 = NULL;
-#else /* INET6 */
- if (IP_V(ip) == 6) {
- ND_PRINT((ndo, "Can't handle IPv6"));
- return;
- }
-#endif /* INET6 */
ch = '\0';
if (!ND_TTEST(pgm->pgm_dport)) {
-#ifdef INET6
if (ip6) {
ND_PRINT((ndo, "%s > %s: [|pgm]",
ip6addr_string(ndo, &ip6->ip6_src),
ip6addr_string(ndo, &ip6->ip6_dst)));
return;
- } else
-#endif /* INET6 */
- {
+ } else {
ND_PRINT((ndo, "%s > %s: [|pgm]",
ipaddr_string(ndo, &ip->ip_src),
ipaddr_string(ndo, &ip->ip_dst)));
@@ -196,7 +179,6 @@ pgm_print(netdissect_options *ndo,
sport = EXTRACT_16BITS(&pgm->pgm_sport);
dport = EXTRACT_16BITS(&pgm->pgm_dport);
-#ifdef INET6
if (ip6) {
if (ip6->ip6_nxt == IPPROTO_PGM) {
ND_PRINT((ndo, "%s.%s > %s.%s: ",
@@ -208,9 +190,7 @@ pgm_print(netdissect_options *ndo,
ND_PRINT((ndo, "%s > %s: ",
tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
}
- } else
-#endif /*INET6*/
- {
+ } else {
if (ip->ip_p == IPPROTO_PGM) {
ND_PRINT((ndo, "%s.%s > %s.%s: ",
ipaddr_string(ndo, &ip->ip_src),
@@ -243,28 +223,24 @@ pgm_print(netdissect_options *ndo,
spm = (const struct pgm_spm *)(pgm + 1);
ND_TCHECK(*spm);
+ bp = (const u_char *) (spm + 1);
switch (EXTRACT_16BITS(&spm->pgms_nla_afi)) {
case AFNUM_INET:
- addr_size = sizeof(struct in_addr);
- nla_af = AF_INET;
+ ND_TCHECK2(*bp, sizeof(struct in_addr));
+ addrtostr(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in_addr);
break;
-#ifdef INET6
case AFNUM_INET6:
- addr_size = sizeof(struct in6_addr);
- nla_af = AF_INET6;
+ ND_TCHECK2(*bp, sizeof(struct in6_addr));
+ addrtostr6(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in6_addr);
break;
-#endif
default:
goto trunc;
break;
}
- bp = (const u_char *) (spm + 1);
- ND_TCHECK2(*bp, addr_size);
- nla = bp;
- bp += addr_size;
- inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
ND_PRINT((ndo, "SPM seq %u trail %u lead %u nla %s",
EXTRACT_32BITS(&spm->pgms_seq),
EXTRACT_32BITS(&spm->pgms_trailseq),
@@ -290,28 +266,23 @@ pgm_print(netdissect_options *ndo,
polr = (const struct pgm_polr *)(pgm + 1);
ND_TCHECK(*polr);
+ bp = (const u_char *) (polr + 1);
switch (EXTRACT_16BITS(&polr->pgmp_nla_afi)) {
case AFNUM_INET:
- addr_size = sizeof(struct in_addr);
- nla_af = AF_INET;
+ ND_TCHECK2(*bp, sizeof(struct in_addr));
+ addrtostr(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in_addr);
break;
-#ifdef INET6
case AFNUM_INET6:
- addr_size = sizeof(struct in6_addr);
- nla_af = AF_INET6;
+ ND_TCHECK2(*bp, sizeof(struct in6_addr));
+ addrtostr6(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in6_addr);
break;
-#endif
default:
goto trunc;
break;
}
- bp = (const u_char *) (polr + 1);
- ND_TCHECK2(*bp, addr_size);
- nla = bp;
- bp += addr_size;
-
- inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
ND_TCHECK2(*bp, sizeof(uint32_t));
ivl = EXTRACT_32BITS(bp);
@@ -358,16 +329,11 @@ pgm_print(netdissect_options *ndo,
case PGM_NULLNAK:
case PGM_NCF: {
const struct pgm_nak *nak;
- const void *source, *group;
- int source_af, group_af;
-#ifdef INET6
char source_buf[INET6_ADDRSTRLEN], group_buf[INET6_ADDRSTRLEN];
-#else
- char source_buf[INET_ADDRSTRLEN], group_buf[INET_ADDRSTRLEN];
-#endif
nak = (const struct pgm_nak *)(pgm + 1);
ND_TCHECK(*nak);
+ bp = (const u_char *) (nak + 1);
/*
* Skip past the source, saving info along the way
@@ -375,53 +341,44 @@ pgm_print(netdissect_options *ndo,
*/
switch (EXTRACT_16BITS(&nak->pgmn_source_afi)) {
case AFNUM_INET:
- addr_size = sizeof(struct in_addr);
- source_af = AF_INET;
+ ND_TCHECK2(*bp, sizeof(struct in_addr));
+ addrtostr(bp, source_buf, sizeof(source_buf));
+ bp += sizeof(struct in_addr);
break;
-#ifdef INET6
case AFNUM_INET6:
- addr_size = sizeof(struct in6_addr);
- source_af = AF_INET6;
+ ND_TCHECK2(*bp, sizeof(struct in6_addr));
+ addrtostr6(bp, source_buf, sizeof(source_buf));
+ bp += sizeof(struct in6_addr);
break;
-#endif
default:
goto trunc;
break;
}
- bp = (const u_char *) (nak + 1);
- ND_TCHECK2(*bp, addr_size);
- source = bp;
- bp += addr_size;
/*
* Skip past the group, saving info along the way
* and stopping if we don't have enough.
*/
+ bp += (2 * sizeof(uint16_t));
switch (EXTRACT_16BITS(bp)) {
case AFNUM_INET:
- addr_size = sizeof(struct in_addr);
- group_af = AF_INET;
+ ND_TCHECK2(*bp, sizeof(struct in_addr));
+ addrtostr(bp, group_buf, sizeof(group_buf));
+ bp += sizeof(struct in_addr);
break;
-#ifdef INET6
case AFNUM_INET6:
- addr_size = sizeof(struct in6_addr);
- group_af = AF_INET6;
+ ND_TCHECK2(*bp, sizeof(struct in6_addr));
+ addrtostr6(bp, group_buf, sizeof(group_buf));
+ bp += sizeof(struct in6_addr);
break;
-#endif
default:
goto trunc;
break;
}
- bp += (2 * sizeof(uint16_t));
- ND_TCHECK2(*bp, addr_size);
- group = bp;
- bp += addr_size;
/*
* Options decoding can go here.
*/
- inet_ntop(source_af, source, source_buf, sizeof(source_buf));
- inet_ntop(group_af, group, group_buf, sizeof(group_buf));
switch (pgm->pgm_type) {
case PGM_NAK:
ND_PRINT((ndo, "NAK "));
@@ -600,33 +557,35 @@ pgm_print(netdissect_options *ndo,
case PGM_OPT_REDIRECT:
bp += 2;
- switch (EXTRACT_16BITS(bp)) {
+ nla_afnum = EXTRACT_16BITS(bp);
+ bp += (2 * sizeof(uint16_t));
+ switch (nla_afnum) {
case AFNUM_INET:
- addr_size = sizeof(struct in_addr);
- nla_af = AF_INET;
+ if (opt_len != 4 + sizeof(struct in_addr)) {
+ ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len));
+ return;
+ }
+ ND_TCHECK2(*bp, sizeof(struct in_addr));
+ addrtostr(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in_addr);
+ opts_len -= 4 + sizeof(struct in_addr);
break;
-#ifdef INET6
case AFNUM_INET6:
- addr_size = sizeof(struct in6_addr);
- nla_af = AF_INET6;
+ if (opt_len != 4 + sizeof(struct in6_addr)) {
+ ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len));
+ return;
+ }
+ ND_TCHECK2(*bp, sizeof(struct in6_addr));
+ addrtostr6(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in6_addr);
+ opts_len -= 4 + sizeof(struct in6_addr);
break;
-#endif
default:
goto trunc;
break;
}
- bp += (2 * sizeof(uint16_t));
- if (opt_len != 4 + addr_size) {
- ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len));
- return;
- }
- ND_TCHECK2(*bp, addr_size);
- nla = bp;
- bp += addr_size;
- inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
ND_PRINT((ndo, " REDIRECT %s", nla_buf));
- opts_len -= 4 + addr_size;
break;
case PGM_OPT_PARITY_PRM:
@@ -731,66 +690,70 @@ pgm_print(netdissect_options *ndo,
bp += 2;
offset = EXTRACT_32BITS(bp);
bp += sizeof(uint32_t);
- switch (EXTRACT_16BITS(bp)) {
+ nla_afnum = EXTRACT_16BITS(bp);
+ bp += (2 * sizeof(uint16_t));
+ switch (nla_afnum) {
case AFNUM_INET:
- addr_size = sizeof(struct in_addr);
- nla_af = AF_INET;
+ if (opt_len != 12 + sizeof(struct in_addr)) {
+ ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
+ return;
+ }
+ ND_TCHECK2(*bp, sizeof(struct in_addr));
+ addrtostr(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in_addr);
+ opts_len -= 12 + sizeof(struct in_addr);
break;
-#ifdef INET6
case AFNUM_INET6:
- addr_size = sizeof(struct in6_addr);
- nla_af = AF_INET6;
+ if (opt_len != 12 + sizeof(struct in6_addr)) {
+ ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
+ return;
+ }
+ ND_TCHECK2(*bp, sizeof(struct in6_addr));
+ addrtostr6(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in6_addr);
+ opts_len -= 12 + sizeof(struct in6_addr);
break;
-#endif
default:
goto trunc;
break;
}
- bp += (2 * sizeof(uint16_t));
- if (opt_len != 12 + addr_size) {
- ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
- return;
- }
- ND_TCHECK2(*bp, addr_size);
- nla = bp;
- bp += addr_size;
- inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
ND_PRINT((ndo, " PGMCC DATA %u %s", offset, nla_buf));
- opts_len -= 16;
break;
case PGM_OPT_PGMCC_FEEDBACK:
bp += 2;
offset = EXTRACT_32BITS(bp);
bp += sizeof(uint32_t);
- switch (EXTRACT_16BITS(bp)) {
+ nla_afnum = EXTRACT_16BITS(bp);
+ bp += (2 * sizeof(uint16_t));
+ switch (nla_afnum) {
case AFNUM_INET:
- addr_size = sizeof(struct in_addr);
- nla_af = AF_INET;
+ if (opt_len != 12 + sizeof(struct in_addr)) {
+ ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
+ return;
+ }
+ ND_TCHECK2(*bp, sizeof(struct in_addr));
+ addrtostr(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in_addr);
+ opts_len -= 12 + sizeof(struct in_addr);
break;
-#ifdef INET6
case AFNUM_INET6:
- addr_size = sizeof(struct in6_addr);
- nla_af = AF_INET6;
+ if (opt_len != 12 + sizeof(struct in6_addr)) {
+ ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
+ return;
+ }
+ ND_TCHECK2(*bp, sizeof(struct in6_addr));
+ addrtostr6(bp, nla_buf, sizeof(nla_buf));
+ bp += sizeof(struct in6_addr);
+ opts_len -= 12 + sizeof(struct in6_addr);
break;
-#endif
default:
goto trunc;
break;
}
- bp += (2 * sizeof(uint16_t));
- if (opt_len != 12 + addr_size) {
- ND_PRINT((ndo, "[Bad OPT_PGMCC_FEEDBACK option, length %u != 12 + address size]", opt_len));
- return;
- }
- ND_TCHECK2(*bp, addr_size);
- nla = bp;
- bp += addr_size;
- inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
ND_PRINT((ndo, " PGMCC FEEDBACK %u %s", offset, nla_buf));
- opts_len -= 16;
break;
default: