mirror of
https://github.com/maride/pancap.git
synced 2024-12-22 20:27:29 +00:00
Move statistics to file.go, add dummy ethernet analyzer
This commit is contained in:
parent
daa3cfd812
commit
187e80b972
@ -1,20 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
"log"
|
||||
"./ethernet"
|
||||
)
|
||||
|
||||
// Analyzes the given packet source
|
||||
func analyzePCAP(source *gopacket.PacketSource, linkType layers.LinkType) error {
|
||||
log.Printf("PCAP capture link type is %s (ID %d)", getNameOfLinkType(linkType), linkType)
|
||||
// TODO: maybe, just maybe, we wanna print more here than just the link type :)
|
||||
_, _ = source, linkType
|
||||
return nil
|
||||
}
|
||||
// Switch over link type to determine correct module to ask for analysis
|
||||
switch linkType {
|
||||
case layers.LinkTypeEthernet:
|
||||
// Ethernet
|
||||
return ethernet.Analyze(source)
|
||||
}
|
||||
|
||||
// Returns the name of the LinkType constant handed over
|
||||
func getNameOfLinkType(lt layers.LinkType) string {
|
||||
return lt.String()
|
||||
}
|
||||
// if we reach this point, the given PCAP contains a link type we can't handle (yet).
|
||||
errorMsg := fmt.Sprintf("Asked for link type %s (ID %d), but not supported by pancap. :( sorry!", linkType.String(), linkType)
|
||||
return errors.New(errorMsg)
|
||||
}
|
||||
|
8
src/ethernet/ethernet.go
Normal file
8
src/ethernet/ethernet.go
Normal file
@ -0,0 +1,8 @@
|
||||
package ethernet
|
||||
|
||||
import "github.com/google/gopacket"
|
||||
|
||||
func Analyze(source *gopacket.PacketSource) error {
|
||||
// Dummy
|
||||
return nil
|
||||
}
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
"github.com/google/gopacket/pcap"
|
||||
"log"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -25,6 +26,9 @@ func openPCAP() (*gopacket.PacketSource, layers.LinkType, error) {
|
||||
return nil, 0, openErr
|
||||
}
|
||||
|
||||
// Output basic information about this PCAP
|
||||
log.Printf("PCAP capture link type is %s (ID %d)", handle.LinkType().String(), handle.LinkType())
|
||||
|
||||
// Open given handle as packet source and return it
|
||||
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
|
||||
return packetSource, handle.LinkType(), nil
|
||||
|
Loading…
Reference in New Issue
Block a user