Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convenient access to IP, TCP and UDP headers.

These are really common and having a pointer to them vs. digging
through a bag of headers and doing type matching makes things a lot
easier.
  • Loading branch information...
commit 2803ae2e9094cfbb33f2729332fb804cab9ff838 1 parent f83c6d1
@dustin dustin authored
Showing with 7 additions and 0 deletions.
  1. +3 −0  decode.go
  2. +4 −0 io.go
View
3  decode.go
@@ -236,6 +236,7 @@ func (p *Packet) decodeIp() {
}
p.Payload = pkt[ip.Ihl*4 : pEnd]
p.Headers = append(p.Headers, ip)
+ p.IP = ip
switch ip.Protocol {
case IP_TCP:
@@ -300,6 +301,7 @@ func (p *Packet) decodeTcp() {
tcp.Urgent = decodeuint16(pkt[18:20])
p.Payload = pkt[tcp.DataOffset*4:]
p.Headers = append(p.Headers, tcp)
+ p.TCP = tcp
}
func (tcp *Tcphdr) String(hdr addrHdr) string {
@@ -355,6 +357,7 @@ func (p *Packet) decodeUdp() {
udp.Length = decodeuint16(pkt[4:6])
udp.Checksum = decodeuint16(pkt[6:8])
p.Headers = append(p.Headers, udp)
+ p.UDP = udp
p.Payload = pkt[8:]
}
View
4 io.go
@@ -35,6 +35,10 @@ type Packet struct {
Headers []interface{} // decoded headers, in order
Payload []byte // remaining non-header bytes
+
+ IP *Iphdr // IP header (for IP packets, after decoding)
+ TCP *Tcphdr // TCP header (for TCP packets, after decoding)
+ UDP *Udphdr // UDP header (for UDP packets after decoding)
}
// Reader parses pcap files.
Please sign in to comment.
Something went wrong with that request. Please try again.