diff --git a/src/analyzer.go b/src/analyzer.go index 2760966..c978167 100644 --- a/src/analyzer.go +++ b/src/analyzer.go @@ -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() -} \ No newline at end of file + // 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) +} diff --git a/src/ethernet/ethernet.go b/src/ethernet/ethernet.go new file mode 100644 index 0000000..485267a --- /dev/null +++ b/src/ethernet/ethernet.go @@ -0,0 +1,8 @@ +package ethernet + +import "github.com/google/gopacket" + +func Analyze(source *gopacket.PacketSource) error { + // Dummy + return nil +} diff --git a/src/file.go b/src/file.go index 92e028b..4d9b952 100644 --- a/src/file.go +++ b/src/file.go @@ -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