-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for known network layers
- Loading branch information
Showing
1 changed file
with
22 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
buger
Author
Owner
|
||
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 { | ||
|
1 comment
on commit 51860e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
How was the offset of 13 chosen? Just checking.
The other interfaces offset rational are pretty straightforward (I can google them quickly).