]> The Tcpdump Group git mirrors - tcpdump/commitdiff
ICMP: Replace a 'struct in_addr' member type with a 'nd_ipv4' one
authorFrancois-Xavier Le Bail <[email protected]>
Tue, 30 Jan 2018 14:51:20 +0000 (15:51 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 30 Jan 2018 15:38:48 +0000 (16:38 +0100)
In 'struct icmp'.
This avoid some 'undefined-behavior' warnings with clang and option
-fsanitize=undefined enabled.

Moreover:
Remove unneeded '&' when getting a pointer to a nd_ipv4 type.
Fix indentation.

The warnings were like:
print-icmp.c:355:2: runtime error: member access within misaligned address
0x61d00001eabe for type 'const struct icmp', which requires 4 byte alignment
0x61d00001eabe: note: pointer points here
 ef 01 02 03 08 00  90 e1 00 03 00 00 00 00  00 00 00 05 ed 60 ab cd  ab cd ab cd ab cd ab cd  ab cd
             ^
SUMMARY: AddressSanitizer: undefined-behavior print-icmp.c:355:2 in

print-icmp.c

index 269b14fbd8f7e86bc02321dbc52bf706419ef0a7..a5b94d63031309ffd4b05dbba8502b5a81b6fe6d 100644 (file)
@@ -52,8 +52,8 @@ struct icmp {
        nd_uint8_t  icmp_code;          /* type sub code */
        nd_uint16_t icmp_cksum;         /* ones complement cksum of struct */
        union {
        nd_uint8_t  icmp_code;          /* type sub code */
        nd_uint16_t icmp_cksum;         /* ones complement cksum of struct */
        union {
-               nd_uint8_t ih_pptr;             /* ICMP_PARAMPROB */
-               struct in_addr ih_gwaddr;       /* ICMP_REDIRECT */
+               nd_uint8_t ih_pptr;     /* ICMP_PARAMPROB */
+               nd_ipv4 ih_gwaddr;      /* ICMP_REDIRECT */
                struct ih_idseq {
                        nd_uint16_t icd_id;
                        nd_uint16_t icd_seq;
                struct ih_idseq {
                        nd_uint16_t icd_id;
                        nd_uint16_t icd_seq;
@@ -375,7 +375,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                        ND_TCHECK_1(dp->icmp_ip.ip_p);
                        (void)nd_snprintf(buf, sizeof(buf),
                            "%s protocol %u unreachable",
                        ND_TCHECK_1(dp->icmp_ip.ip_p);
                        (void)nd_snprintf(buf, sizeof(buf),
                            "%s protocol %u unreachable",
-                           ipaddr_string(ndo, &dp->icmp_ip.ip_dst),
+                           ipaddr_string(ndo, dp->icmp_ip.ip_dst),
                            EXTRACT_U_1(dp->icmp_ip.ip_p));
                        break;
 
                            EXTRACT_U_1(dp->icmp_ip.ip_p));
                        break;
 
@@ -392,21 +392,21 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                        case IPPROTO_TCP:
                                (void)nd_snprintf(buf, sizeof(buf),
                                        "%s tcp port %s unreachable",
                        case IPPROTO_TCP:
                                (void)nd_snprintf(buf, sizeof(buf),
                                        "%s tcp port %s unreachable",
-                                       ipaddr_string(ndo, &oip->ip_dst),
+                                       ipaddr_string(ndo, oip->ip_dst),
                                        tcpport_string(ndo, dport));
                                break;
 
                        case IPPROTO_UDP:
                                (void)nd_snprintf(buf, sizeof(buf),
                                        "%s udp port %s unreachable",
                                        tcpport_string(ndo, dport));
                                break;
 
                        case IPPROTO_UDP:
                                (void)nd_snprintf(buf, sizeof(buf),
                                        "%s udp port %s unreachable",
-                                       ipaddr_string(ndo, &oip->ip_dst),
+                                       ipaddr_string(ndo, oip->ip_dst),
                                        udpport_string(ndo, dport));
                                break;
 
                        default:
                                (void)nd_snprintf(buf, sizeof(buf),
                                        "%s protocol %u port %u unreachable",
                                        udpport_string(ndo, dport));
                                break;
 
                        default:
                                (void)nd_snprintf(buf, sizeof(buf),
                                        "%s protocol %u port %u unreachable",
-                                       ipaddr_string(ndo, &oip->ip_dst),
+                                       ipaddr_string(ndo, oip->ip_dst),
                                        ip_proto, dport);
                                break;
                        }
                                        ip_proto, dport);
                                break;
                        }
@@ -420,11 +420,11 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                        if (mtu) {
                                (void)nd_snprintf(buf, sizeof(buf),
                                    "%s unreachable - need to frag (mtu %u)",
                        if (mtu) {
                                (void)nd_snprintf(buf, sizeof(buf),
                                    "%s unreachable - need to frag (mtu %u)",
-                                   ipaddr_string(ndo, &dp->icmp_ip.ip_dst), mtu);
+                                   ipaddr_string(ndo, dp->icmp_ip.ip_dst), mtu);
                        } else {
                                (void)nd_snprintf(buf, sizeof(buf),
                                    "%s unreachable - need to frag",
                        } else {
                                (void)nd_snprintf(buf, sizeof(buf),
                                    "%s unreachable - need to frag",
-                                   ipaddr_string(ndo, &dp->icmp_ip.ip_dst));
+                                   ipaddr_string(ndo, dp->icmp_ip.ip_dst));
                        }
                    }
                        break;
                        }
                    }
                        break;
@@ -433,7 +433,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                        fmt = tok2str(unreach2str, "#%u %%s unreachable",
                            icmp_code);
                        (void)nd_snprintf(buf, sizeof(buf), fmt,
                        fmt = tok2str(unreach2str, "#%u %%s unreachable",
                            icmp_code);
                        (void)nd_snprintf(buf, sizeof(buf), fmt,
-                           ipaddr_string(ndo, &dp->icmp_ip.ip_dst));
+                           ipaddr_string(ndo, dp->icmp_ip.ip_dst));
                        break;
                }
                break;
                        break;
                }
                break;
@@ -443,8 +443,8 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                fmt = tok2str(type2str, "redirect-#%u %%s to net %%s",
                    icmp_code);
                (void)nd_snprintf(buf, sizeof(buf), fmt,
                fmt = tok2str(type2str, "redirect-#%u %%s to net %%s",
                    icmp_code);
                (void)nd_snprintf(buf, sizeof(buf), fmt,
-                   ipaddr_string(ndo, &dp->icmp_ip.ip_dst),
-                   ipaddr_string(ndo, &dp->icmp_gwaddr));
+                   ipaddr_string(ndo, dp->icmp_ip.ip_dst),
+                   ipaddr_string(ndo, dp->icmp_gwaddr));
                break;
 
        case ICMP_ROUTERADVERT:
                break;
 
        case ICMP_ROUTERADVERT:
@@ -490,7 +490,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                while (num-- > 0) {
                        ND_TCHECK_SIZE(idp);
                        (void)nd_snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}",
                while (num-- > 0) {
                        ND_TCHECK_SIZE(idp);
                        (void)nd_snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}",
-                           ipaddr_string(ndo, &idp->ird_addr),
+                           ipaddr_string(ndo, idp->ird_addr),
                            EXTRACT_BE_U_4(idp->ird_pref));
                        cp = buf + strlen(buf);
                        ++idp;
                            EXTRACT_BE_U_4(idp->ird_pref));
                        cp = buf + strlen(buf);
                        ++idp;