Skip to content

Commit bf6289d

Browse files
author
Brandon Carpenter
committed
Fixed copying packet data for SOCK_RAW.
RAW socket packet capture happens at a different location in the network stack where the sk_buff data pointer has been moved. This fix calculates the offset between the data pointer and network header and adjusts the data copy accordingly. Thank you to Peter Moody and Marc Bevand for the original patch.
1 parent 6ba37d1 commit bf6289d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/pcapng.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ static size_t format_packet_block(struct packet_event *event,
414414
unsigned int snaplen, struct timestamp *tstamp, char *buf, size_t buflen)
415415
{
416416
char *pos = buf;
417+
int offset;
417418
unsigned int *length_top, *length_end, *length_cap;
418419
struct sk_buff *skb = event->skb;
419420

@@ -431,10 +432,11 @@ static size_t format_packet_block(struct packet_event *event,
431432
pos += block_set(pos, uint32_t, skb->len); // packet length
432433

433434
// packet data
435+
offset = skb_network_header(skb) - skb->data; // offset should be <= 0
434436
if ((*length_cap = maxoptlen(buflen - (pos - buf),
435-
(snaplen ? min(skb->len, snaplen) : skb->len)))) {
437+
(snaplen ? min(skb->len - offset, snaplen) : skb->len - offset)))) {
436438
unsigned int n = *length_cap & 3 ? 4 - (*length_cap & 3) : 0;
437-
if (skb_copy_bits(skb, 0, pos, *length_cap))
439+
if (skb_copy_bits(skb, offset, pos, *length_cap))
438440
BUG();
439441
pos += *length_cap;
440442
memset(pos, 0, n);

0 commit comments

Comments
 (0)