]> The Tcpdump Group git mirrors - tcpdump/commitdiff
No need for casting back and forth.
authorGuy Harris <[email protected]>
Sat, 18 Jan 2014 20:06:36 +0000 (12:06 -0800)
committerGuy Harris <[email protected]>
Sat, 18 Jan 2014 20:06:36 +0000 (12:06 -0800)
That might also convince the compiler that it can "helpfully" optimize
the copy into something that assumes 4-byte alignment, which we don't
want it to do on platforms where the optimized code will trap if the IP
header *isn't* aligned on a 4-byte boundary, given that there's no
guarantee that it *is* aligned on a 4-byte boundary.

print-ip.c

index eeaee9ae30714fdaff4035e10c8c942b9d50e4d0..22bd80054775e055fce7555b4f0d5f27c0c4cfc7 100644 (file)
@@ -669,14 +669,13 @@ ip_print(netdissect_options *ndo,
 void
 ipN_print(register const u_char *bp, register u_int length)
 {
-       struct ip *ip, hdr;
+       struct ip hdr;
 
-       ip = (struct ip *)bp;
        if (length < 4) {
                (void)printf("truncated-ip %d", length);
                return;
        }
-       memcpy (&hdr, (char *)ip, 4);
+       memcpy (&hdr, bp, 4);
        switch (IP_V(&hdr)) {
        case 4:
                ip_print (gndo, bp, length);