diff options
-rw-r--r-- | sbin/dhclient/bpf.c | 20 | ||||
-rw-r--r-- | usr.sbin/dhcpd/bpf.c | 20 |
2 files changed, 26 insertions, 14 deletions
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index 131a88f743d..eedaeb4a057 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.13 2004/05/05 14:28:58 deraadt Exp $ */ +/* $OpenBSD: bpf.c,v 1.14 2005/07/29 17:26:28 krw Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -285,7 +285,7 @@ receive_packet(struct interface_info *interface, unsigned char *buf, if (length <= 0) return (length); interface->rbuf_offset = 0; - interface->rbuf_len = length; + interface->rbuf_len = BPF_WORDALIGN(length); } /* @@ -319,7 +319,9 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * do is drop it. */ if (hdr.bh_caplen != hdr.bh_datalen) { - interface->rbuf_offset += hdr.bh_hdrlen = hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_hdrlen + + hdr.bh_caplen); continue; } @@ -336,7 +338,8 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * this packet. */ if (offset < 0) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } interface->rbuf_offset += offset; @@ -348,7 +351,8 @@ receive_packet(struct interface_info *interface, unsigned char *buf, /* If the IP or UDP checksum was bad, skip the packet... */ if (offset < 0) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } interface->rbuf_offset += offset; @@ -360,14 +364,16 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * life, though). */ if (hdr.bh_caplen > len) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } /* Copy out the data in the packet... */ memcpy(buf, interface->rbuf + interface->rbuf_offset, hdr.bh_caplen); - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN(interface->rbuf_offset + + hdr.bh_caplen); return (hdr.bh_caplen); } while (!length); return (0); diff --git a/usr.sbin/dhcpd/bpf.c b/usr.sbin/dhcpd/bpf.c index ca0088f235c..cdc4e78cde5 100644 --- a/usr.sbin/dhcpd/bpf.c +++ b/usr.sbin/dhcpd/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.5 2004/09/16 18:35:42 deraadt Exp $ */ +/* $OpenBSD: bpf.c,v 1.6 2005/07/29 17:26:28 krw Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -276,7 +276,7 @@ receive_packet(struct interface_info *interface, unsigned char *buf, if (length <= 0) return (length); interface->rbuf_offset = 0; - interface->rbuf_len = length; + interface->rbuf_len = BPF_WORDALIGN(length); } /* @@ -310,7 +310,9 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * do is drop it. */ if (hdr.bh_caplen != hdr.bh_datalen) { - interface->rbuf_offset += hdr.bh_hdrlen = hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_hdrlen + + hdr.bh_caplen); continue; } @@ -327,7 +329,8 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * this packet. */ if (offset < 0) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } interface->rbuf_offset += offset; @@ -339,7 +342,8 @@ receive_packet(struct interface_info *interface, unsigned char *buf, /* If the IP or UDP checksum was bad, skip the packet... */ if (offset < 0) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } interface->rbuf_offset += offset; @@ -351,14 +355,16 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * life, though). */ if (hdr.bh_caplen > len) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } /* Copy out the data in the packet... */ memcpy(buf, interface->rbuf + interface->rbuf_offset, hdr.bh_caplen); - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN(interface->rbuf_offset + + hdr.bh_caplen); return (hdr.bh_caplen); } while (!length); return (0); |