Skip to content

Commit

Permalink
Add support for known network layers
Browse files Browse the repository at this point in the history
Fix #310
Close #311
  • Loading branch information
buger committed Jun 20, 2016
1 parent 2c49556 commit 51860e1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions raw_socket_listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,30 @@ func (t *Listener) readPcap() {
continue
}

if decoder == layers.LinkTypeEthernet {
// Skip ethernet layer, 14 bytes
data = packet.Data()[14:]
} else if decoder == layers.LinkTypeNull || decoder == layers.LinkTypeLoop {
data = packet.Data()[4:]
} else {
log.Println("Unknown packet layer", packet)
break
// We should remove network layer before parsing TCP/IP data
var of int
switch decoder {
case layers.LinkTypeEthernet:
of = 14
case layers.LinkTypePPP:
of = 1
case layers.LinkTypeFDDI:
of = 13

This comment has been minimized.

Copy link
@joekiller

joekiller Jul 5, 2016

Contributor

How was the offset of 13 chosen? Just checking.

The other interfaces offset rational are pretty straightforward (I can google them quickly).

This comment has been minimized.

Copy link
@buger

buger Jul 5, 2016

Author Owner

From gopacket https://github.com/google/gopacket/tree/master/layers, enter each layer and check how it decoded.

case layers.LinkTypeNull:
of = 4
case layers.LinkTypeLoop:
of = 4
case layers.LinkTypeRaw:
of = 0
case layers.LinkTypeLinuxSLL:
of = 16
default:
log.Println("Unknown packet layer", packet)
break
}

data = packet.Data()[of:]

version := uint8(data[0]) >> 4

if version == 4 {
Expand Down

1 comment on commit 51860e1

@joekiller
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Please sign in to comment.