Skip to content

Commit

Permalink
Set pcap.BlockForever
Browse files Browse the repository at this point in the history
  • Loading branch information
negbie committed Sep 18, 2017
1 parent bf79336 commit 604989b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Packet struct {
Host string
Tsec uint32
Tmsec uint32
Version uint8
Protocol uint8
Srcip uint32
Dstip uint32
Sport uint16
Expand Down Expand Up @@ -80,6 +82,8 @@ func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error
}
}

pkt.Version = ip4.Version
pkt.Protocol = uint8(ip4.Protocol)
pkt.Srcip = ip2int(ip4.SrcIP)
pkt.Dstip = ip2int(ip4.DstIP)

Expand All @@ -102,6 +106,8 @@ func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error
packet, string(packet.ApplicationLayer().Payload()), string(ip4New.Payload[8:]), ip4New.Length,
)

pkt.Version = ip4New.Version
pkt.Protocol = uint8(ip4New.Protocol)
pkt.Srcip = ip2int(ip4New.SrcIP)
pkt.Dstip = ip2int(ip4New.DstIP)

Expand Down
4 changes: 2 additions & 2 deletions publish/hep.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ func makeChunck(chunckVen uint16, chunckType uint16, h *decoder.Packet) []byte {
// Chunk IP protocol family (0x02=IPv4)
case 0x0001:
chunck = make([]byte, 6+1)
chunck[6] = 0x02
chunck[6] = h.Version

// Chunk IP protocol ID (0x11=UDP)
case 0x0002:
chunck = make([]byte, 6+1)
chunck[6] = 0x11
chunck[6] = h.Protocol

// Chunk IPv4 source address
case 0x0003:
Expand Down
6 changes: 3 additions & 3 deletions sniffer/sniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (sniffer *SnifferSetup) setFromConfig(cfg *config.InterfacesConfig) error {
sniffer.DataSource = gopacket.PacketDataSource(sniffer.pcapHandle)

case "pcap":
sniffer.pcapHandle, err = pcap.OpenLive(sniffer.config.Device, int32(sniffer.config.Snaplen), true, 12*time.Hour)
sniffer.pcapHandle, err = pcap.OpenLive(sniffer.config.Device, int32(sniffer.config.Snaplen), true, pcap.BlockForever)
if err != nil {
return fmt.Errorf("setting pcap live mode: %v", err)
}
Expand All @@ -141,7 +141,7 @@ func (sniffer *SnifferSetup) setFromConfig(cfg *config.InterfacesConfig) error {
return fmt.Errorf("setting af_packet computesize: %v", err)
}

sniffer.afpacketHandle, err = newAfpacketHandle(sniffer.config.Device, szFrame, szBlock, numBlocks, 12*time.Hour)
sniffer.afpacketHandle, err = newAfpacketHandle(sniffer.config.Device, szFrame, szBlock, numBlocks, pcap.BlockForever)
if err != nil {
return fmt.Errorf("setting af_packet handle: %v", err)
}
Expand Down Expand Up @@ -324,7 +324,7 @@ func (sniffer *SnifferSetup) Close() error {
func (sniffer *SnifferSetup) Reopen() error {
var err error

if sniffer.config.Type != "file" || sniffer.config.ReadFile == "" {
if sniffer.config.Type != "file" {
return fmt.Errorf("Reopen is only possible for files")
}

Expand Down

0 comments on commit 604989b

Please sign in to comment.