summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-12-11 19:38:35 -0800
committerGuy Harris <guy@alum.mit.edu>2017-12-11 19:38:35 -0800
commita95802aa0d8731412a9b5e621692e594046605bd (patch)
treed8055fa7006fe5d97a23564073b562a2a44e9ef3
parente2f0616cd0079cf894391f1f1e042a9457b69beb (diff)
downloadtcpdump-a95802aa0d8731412a9b5e621692e594046605bd.tar.gz
Use nd_ types in the IPv6 structures.
And add the EXTRACT_U_1() calls as needed. Change some other EXTRACT_ calls that no longer need an & operator.
-rw-r--r--ip6.h40
-rw-r--r--print-icmp6.c18
-rw-r--r--print-ip6.c22
-rw-r--r--print-ip6opts.c4
-rw-r--r--print-pgm.c2
-rw-r--r--print-rt6.c13
-rw-r--r--print-tcp.c22
-rw-r--r--print-udp.c2
8 files changed, 63 insertions, 60 deletions
diff --git a/ip6.h b/ip6.h
index 9a24ef14..35f12e42 100644
--- a/ip6.h
+++ b/ip6.h
@@ -76,19 +76,19 @@
struct ip6_hdr {
union {
struct ip6_hdrctl {
- uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
- uint16_t ip6_un1_plen; /* payload length */
- uint8_t ip6_un1_nxt; /* next header */
- uint8_t ip6_un1_hlim; /* hop limit */
+ nd_uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
+ nd_uint16_t ip6_un1_plen; /* payload length */
+ nd_uint8_t ip6_un1_nxt; /* next header */
+ nd_uint8_t ip6_un1_hlim; /* hop limit */
} ip6_un1;
- uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
+ nd_uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
} ip6_ctlun;
struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */
} UNALIGNED;
#define ip6_vfc ip6_ctlun.ip6_un2_vfc
-#define IP6_VERSION(ip6_hdr) (((ip6_hdr)->ip6_vfc & 0xf0) >> 4)
+#define IP6_VERSION(ip6_hdr) ((EXTRACT_U_1((ip6_hdr)->ip6_vfc) & 0xf0) >> 4)
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
@@ -109,21 +109,21 @@ struct ip6_hdr {
*/
struct ip6_ext {
- uint8_t ip6e_nxt;
- uint8_t ip6e_len;
+ nd_uint8_t ip6e_nxt;
+ nd_uint8_t ip6e_len;
} UNALIGNED;
/* Hop-by-Hop options header */
struct ip6_hbh {
- uint8_t ip6h_nxt; /* next header */
- uint8_t ip6h_len; /* length in units of 8 octets */
+ nd_uint8_t ip6h_nxt; /* next header */
+ nd_uint8_t ip6h_len; /* length in units of 8 octets */
/* followed by options */
} UNALIGNED;
/* Destination options header */
struct ip6_dest {
- uint8_t ip6d_nxt; /* next header */
- uint8_t ip6d_len; /* length in units of 8 octets */
+ nd_uint8_t ip6d_nxt; /* next header */
+ nd_uint8_t ip6d_len; /* length in units of 8 octets */
/* followed by options */
} UNALIGNED;
@@ -165,10 +165,10 @@ struct ip6_dest {
/* Routing header */
struct ip6_rthdr {
- uint8_t ip6r_nxt; /* next header */
- uint8_t ip6r_len; /* length in units of 8 octets */
- uint8_t ip6r_type; /* routing type */
- uint8_t ip6r_segleft; /* segments left */
+ nd_uint8_t ip6r_nxt; /* next header */
+ nd_uint8_t ip6r_len; /* length in units of 8 octets */
+ nd_uint8_t ip6r_type; /* routing type */
+ nd_uint8_t ip6r_segleft; /* segments left */
/* followed by routing type specific data */
} UNALIGNED;
@@ -188,10 +188,10 @@ struct ip6_rthdr0 {
/* Fragment header */
struct ip6_frag {
- uint8_t ip6f_nxt; /* next header */
- uint8_t ip6f_reserved; /* reserved field */
- uint16_t ip6f_offlg; /* offset, reserved, and flag */
- uint32_t ip6f_ident; /* identification */
+ nd_uint8_t ip6f_nxt; /* next header */
+ nd_uint8_t ip6f_reserved; /* reserved field */
+ nd_uint16_t ip6f_offlg; /* offset, reserved, and flag */
+ nd_uint32_t ip6f_ident; /* identification */
} UNALIGNED;
#define IP6F_OFF_MASK 0xfff8 /* mask out offset from ip6f_offlg */
diff --git a/print-icmp6.c b/print-icmp6.c
index 594c9153..2fd9d1b4 100644
--- a/print-icmp6.c
+++ b/print-icmp6.c
@@ -875,7 +875,7 @@ icmp6_print(netdissect_options *ndo,
const struct ip6_hdr *ip;
const struct ip6_hdr *oip;
const struct udphdr *ouh;
- int dport;
+ u_int dport;
const u_char *ep;
u_int prot;
@@ -935,7 +935,7 @@ icmp6_print(netdissect_options *ndo,
== NULL)
goto trunc;
- dport = EXTRACT_BE_U_2(&ouh->uh_dport);
+ dport = EXTRACT_BE_U_2(ouh->uh_dport);
switch (prot) {
case IPPROTO_TCP:
ND_PRINT((ndo,", %s tcp port %s",
@@ -948,9 +948,9 @@ icmp6_print(netdissect_options *ndo,
udpport_string(ndo, dport)));
break;
default:
- ND_PRINT((ndo,", %s protocol %d port %d unreachable",
+ ND_PRINT((ndo,", %s protocol %u port %u unreachable",
ip6addr_string(ndo, &oip->ip6_dst),
- oip->ip6_nxt, dport));
+ prot, dport));
break;
}
break;
@@ -1179,7 +1179,7 @@ get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
if (!ND_TTEST(ip6->ip6_nxt))
return NULL;
- nh = ip6->ip6_nxt;
+ nh = EXTRACT_U_1(ip6->ip6_nxt);
hlen = sizeof(struct ip6_hdr);
while (bp < ep) {
@@ -1203,8 +1203,8 @@ get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
hbh = (const struct ip6_hbh *)bp;
if (!ND_TTEST(hbh->ip6h_len))
return(NULL);
- nh = hbh->ip6h_nxt;
- hlen = (hbh->ip6h_len + 1) << 3;
+ nh = EXTRACT_U_1(hbh->ip6h_nxt);
+ hlen = (EXTRACT_U_1(hbh->ip6h_len) + 1) << 3;
break;
case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
@@ -1212,9 +1212,9 @@ get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
if (!ND_TTEST(fragh->ip6f_offlg))
return(NULL);
/* fragments with non-zero offset are meaningless */
- if ((EXTRACT_BE_U_2(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
+ if ((EXTRACT_BE_U_2(fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
return(NULL);
- nh = fragh->ip6f_nxt;
+ nh = EXTRACT_U_1(fragh->ip6f_nxt);
hlen = sizeof(struct ip6_frag);
break;
diff --git a/print-ip6.c b/print-ip6.c
index bdc79f9c..3b63639e 100644
--- a/print-ip6.c
+++ b/print-ip6.c
@@ -58,7 +58,7 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
cp = (const u_char *)ip6;
advance = sizeof(struct ip6_hdr);
- nh = ip6->ip6_nxt;
+ nh = EXTRACT_U_1(ip6->ip6_nxt);
dst_addr = (const void *)&ip6->ip6_dst;
while (cp < ndo->ndo_snapend) {
@@ -98,8 +98,8 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
*/
dp = (const struct ip6_rthdr *)cp;
ND_TCHECK(*dp);
- len = dp->ip6r_len;
- switch (dp->ip6r_type) {
+ len = EXTRACT_U_1(dp->ip6r_len);
+ switch (EXTRACT_U_1(dp->ip6r_type)) {
case IPV6_RTHDR_TYPE_0:
case IPV6_RTHDR_TYPE_2: /* Mobile IPv6 ID-20 */
@@ -172,11 +172,13 @@ nextproto6_cksum(netdissect_options *ndo,
uint8_t ph_nxt;
} ph;
struct cksum_vec vec[2];
+ u_int nh;
/* pseudo-header */
memset(&ph, 0, sizeof(ph));
UNALIGNED_MEMCPY(&ph.ph_src, &ip6->ip6_src, sizeof (struct in6_addr));
- switch (ip6->ip6_nxt) {
+ nh = EXTRACT_U_1(ip6->ip6_nxt);
+ switch (nh) {
case IPPROTO_HOPOPTS:
case IPPROTO_DSTOPTS:
@@ -239,14 +241,15 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
return;
}
- payload_len = EXTRACT_BE_U_2(&ip6->ip6_plen);
+ payload_len = EXTRACT_BE_U_2(ip6->ip6_plen);
len = payload_len + sizeof(struct ip6_hdr);
if (length < len)
ND_PRINT((ndo, "truncated-ip6 - %u bytes missing!",
len - length));
+ nh = EXTRACT_U_1(ip6->ip6_nxt);
if (ndo->ndo_vflag) {
- flow = EXTRACT_BE_U_4(&ip6->ip6_flow);
+ flow = EXTRACT_BE_U_4(ip6->ip6_flow);
ND_PRINT((ndo, "("));
#if 0
/* rfc1883 */
@@ -263,9 +266,9 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
#endif
ND_PRINT((ndo, "hlim %u, next-header %s (%u) payload length: %u) ",
- ip6->ip6_hlim,
- tok2str(ipproto_values,"unknown",ip6->ip6_nxt),
- ip6->ip6_nxt,
+ EXTRACT_U_1(ip6->ip6_hlim),
+ tok2str(ipproto_values,"unknown",nh),
+ nh,
payload_len));
}
@@ -278,7 +281,6 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
cp = (const u_char *)ip6;
advance = sizeof(struct ip6_hdr);
- nh = ip6->ip6_nxt;
while (cp < ndo->ndo_snapend && advance > 0) {
if (len < (u_int)advance)
goto trunc;
diff --git a/print-ip6opts.c b/print-ip6opts.c
index 41b292e7..95e52e4b 100644
--- a/print-ip6opts.c
+++ b/print-ip6opts.c
@@ -177,7 +177,7 @@ hbhopt_print(netdissect_options *ndo, register const u_char *bp)
u_int hbhlen = 0;
ND_TCHECK(dp->ip6h_len);
- hbhlen = (dp->ip6h_len + 1) << 3;
+ hbhlen = (EXTRACT_U_1(dp->ip6h_len) + 1) << 3;
ND_TCHECK_LEN(dp, hbhlen);
ND_PRINT((ndo, "HBH "));
if (ndo->ndo_vflag)
@@ -197,7 +197,7 @@ dstopt_print(netdissect_options *ndo, register const u_char *bp)
u_int dstoptlen = 0;
ND_TCHECK(dp->ip6d_len);
- dstoptlen = (dp->ip6d_len + 1) << 3;
+ dstoptlen = (EXTRACT_U_1(dp->ip6d_len) + 1) << 3;
ND_TCHECK_LEN(dp, dstoptlen);
ND_PRINT((ndo, "DSTOPT "));
if (ndo->ndo_vflag) {
diff --git a/print-pgm.c b/print-pgm.c
index 16735f5d..04b654ef 100644
--- a/print-pgm.c
+++ b/print-pgm.c
@@ -181,7 +181,7 @@ pgm_print(netdissect_options *ndo,
dport = EXTRACT_BE_U_2(&pgm->pgm_dport);
if (ip6) {
- if (ip6->ip6_nxt == IPPROTO_PGM) {
+ if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_PGM) {
ND_PRINT((ndo, "%s.%s > %s.%s: ",
ip6addr_string(ndo, &ip6->ip6_src),
tcpport_string(ndo, sport),
diff --git a/print-rt6.c b/print-rt6.c
index 31da35ea..66c41758 100644
--- a/print-rt6.c
+++ b/print-rt6.c
@@ -41,7 +41,7 @@ rt6_print(netdissect_options *ndo, register const u_char *bp, const u_char *bp2
register const struct ip6_rthdr *dp;
register const struct ip6_rthdr0 *dp0;
register const u_char *ep;
- int i, len;
+ u_int i, len, type;
register const struct in6_addr *addr;
dp = (const struct ip6_rthdr *)bp;
@@ -51,12 +51,13 @@ rt6_print(netdissect_options *ndo, register const u_char *bp, const u_char *bp2
ND_TCHECK(dp->ip6r_segleft);
- len = dp->ip6r_len;
- ND_PRINT((ndo, "srcrt (len=%d", dp->ip6r_len)); /*)*/
- ND_PRINT((ndo, ", type=%d", dp->ip6r_type));
- ND_PRINT((ndo, ", segleft=%d", dp->ip6r_segleft));
+ len = EXTRACT_U_1(dp->ip6r_len);
+ ND_PRINT((ndo, "srcrt (len=%u", len)); /*)*/
+ type = EXTRACT_U_1(dp->ip6r_type);
+ ND_PRINT((ndo, ", type=%u", type));
+ ND_PRINT((ndo, ", segleft=%u", EXTRACT_U_1(dp->ip6r_segleft)));
- switch (dp->ip6r_type) {
+ switch (type) {
case IPV6_RTHDR_TYPE_0:
case IPV6_RTHDR_TYPE_2: /* Mobile IPv6 ID-20 */
dp0 = (const struct ip6_rthdr0 *)dp;
diff --git a/print-tcp.c b/print-tcp.c
index 91d8212e..70af9b61 100644
--- a/print-tcp.c
+++ b/print-tcp.c
@@ -187,11 +187,11 @@ tcp_print(netdissect_options *ndo,
return;
}
- sport = EXTRACT_BE_U_2(&tp->th_sport);
- dport = EXTRACT_BE_U_2(&tp->th_dport);
+ sport = EXTRACT_BE_U_2(tp->th_sport);
+ dport = EXTRACT_BE_U_2(tp->th_dport);
if (ip6) {
- if (ip6->ip6_nxt == IPPROTO_TCP) {
+ if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_TCP) {
ND_PRINT((ndo, "%s.%s > %s.%s: ",
ip6addr_string(ndo, &ip6->ip6_src),
tcpport_string(ndo, sport),
@@ -224,10 +224,10 @@ tcp_print(netdissect_options *ndo,
return;
}
- seq = EXTRACT_BE_U_4(&tp->th_seq);
- ack = EXTRACT_BE_U_4(&tp->th_ack);
- win = EXTRACT_BE_U_2(&tp->th_win);
- urp = EXTRACT_BE_U_2(&tp->th_urp);
+ seq = EXTRACT_BE_U_4(tp->th_seq);
+ ack = EXTRACT_BE_U_4(tp->th_ack);
+ win = EXTRACT_BE_U_2(tp->th_win);
+ urp = EXTRACT_BE_U_2(tp->th_urp);
if (ndo->ndo_qflag) {
ND_PRINT((ndo, "tcp %d", length - hlen));
@@ -372,7 +372,7 @@ tcp_print(netdissect_options *ndo,
if (IP_V(ip) == 4) {
if (ND_TTEST2(tp->th_sport, length)) {
sum = tcp_cksum(ndo, ip, tp, length);
- tcp_sum = EXTRACT_BE_U_2(&tp->th_sum);
+ tcp_sum = EXTRACT_BE_U_2(tp->th_sum);
ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum));
if (sum != 0)
@@ -384,7 +384,7 @@ tcp_print(netdissect_options *ndo,
} else if (IP_V(ip) == 6 && ip6->ip6_plen) {
if (ND_TTEST2(tp->th_sport, length)) {
sum = tcp6_cksum(ndo, ip6, tp, length);
- tcp_sum = EXTRACT_BE_U_2(&tp->th_sum);
+ tcp_sum = EXTRACT_BE_U_2(tp->th_sum);
ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum));
if (sum != 0)
@@ -871,14 +871,14 @@ tcp_verify_signature(netdissect_options *ndo,
MD5_Update(&ctx, (const char *)&ip->ip_dst, sizeof(ip->ip_dst));
MD5_Update(&ctx, (const char *)&zero_proto, sizeof(zero_proto));
MD5_Update(&ctx, (const char *)&ip->ip_p, sizeof(ip->ip_p));
- tlen = EXTRACT_BE_U_2(&ip->ip_len) - IP_HL(ip) * 4;
+ tlen = EXTRACT_BE_U_2(ip->ip_len) - IP_HL(ip) * 4;
tlen = htons(tlen);
MD5_Update(&ctx, (const char *)&tlen, sizeof(tlen));
} else if (IP_V(ip) == 6) {
ip6 = (const struct ip6_hdr *)ip;
MD5_Update(&ctx, (const char *)&ip6->ip6_src, sizeof(ip6->ip6_src));
MD5_Update(&ctx, (const char *)&ip6->ip6_dst, sizeof(ip6->ip6_dst));
- len32 = htonl(EXTRACT_BE_U_2(&ip6->ip6_plen));
+ len32 = htonl(EXTRACT_BE_U_2(ip6->ip6_plen));
MD5_Update(&ctx, (const char *)&len32, sizeof(len32));
nxt = 0;
MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt));
diff --git a/print-udp.c b/print-udp.c
index b4fcec94..c58339e9 100644
--- a/print-udp.c
+++ b/print-udp.c
@@ -324,7 +324,7 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo
ip6 = NULL;
if (ip6) {
- if (ip6->ip6_nxt == IPPROTO_UDP) {
+ if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_UDP) {
if (sport == -1) {
ND_PRINT((ndo, "%s > %s: ",
ip6addr_string(ndo, &ip6->ip6_src),