And add the EXTRACT_U_1() calls as needed.
Change some other EXTRACT_ calls that no longer need an & operator.
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
*/
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;
/* 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;
/* 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 */
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;
== 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",
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;
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) {
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 */
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;
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) {
*/
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 */
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:
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 */
#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));
}
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;
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)
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) {
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),
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;
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;
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),
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));
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)
} 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)
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));
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),