Further fix receive_packet() by using BPF_WORDALIGN to insure the offset

is properly aligned when we move to the next packet.

Obtained from:	ISC dhclient via krw at OpenBSD
This commit is contained in:
brooks 2005-07-28 15:30:19 +00:00
parent 0336212d34
commit f45086ab80

View File

@ -325,7 +325,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_caplen;
interface->rbuf_offset =
BPF_WORDALIGN(interface->rbuf_offset +
hdr.bh_caplen);
continue;
}
@ -339,7 +341,9 @@ 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;
@ -351,7 +355,9 @@ 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;
@ -363,14 +369,18 @@ 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);