mirror of
				https://github.com/maride/pancap.git
				synced 2025-10-10 19:36:51 +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
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"github.com/google/gopacket"
 | 
						"github.com/google/gopacket"
 | 
				
			||||||
	"github.com/google/gopacket/layers"
 | 
						"github.com/google/gopacket/layers"
 | 
				
			||||||
	"log"
 | 
						"./ethernet"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Analyzes the given packet source
 | 
					// Analyzes the given packet source
 | 
				
			||||||
func analyzePCAP(source *gopacket.PacketSource, linkType layers.LinkType) error {
 | 
					func analyzePCAP(source *gopacket.PacketSource, linkType layers.LinkType) error {
 | 
				
			||||||
	log.Printf("PCAP capture link type is %s (ID %d)", getNameOfLinkType(linkType), linkType)
 | 
						// Switch over link type to determine correct module to ask for analysis
 | 
				
			||||||
	// TODO: maybe, just maybe, we wanna print more here than just the link type :)
 | 
						switch linkType {
 | 
				
			||||||
	_, _ = source, linkType
 | 
						case layers.LinkTypeEthernet:
 | 
				
			||||||
	return nil
 | 
							// Ethernet
 | 
				
			||||||
}
 | 
							return ethernet.Analyze(source)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Returns the name of the LinkType constant handed over
 | 
						// if we reach this point, the given PCAP contains a link type we can't handle (yet).
 | 
				
			||||||
func getNameOfLinkType(lt layers.LinkType) string {
 | 
						errorMsg := fmt.Sprintf("Asked for link type %s (ID %d), but not supported by pancap. :( sorry!", linkType.String(), linkType)
 | 
				
			||||||
	return lt.String()
 | 
						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"
 | 
				
			||||||
	"github.com/google/gopacket/layers"
 | 
						"github.com/google/gopacket/layers"
 | 
				
			||||||
	"github.com/google/gopacket/pcap"
 | 
						"github.com/google/gopacket/pcap"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
@ -25,6 +26,9 @@ func openPCAP() (*gopacket.PacketSource, layers.LinkType, error) {
 | 
				
			|||||||
		return nil, 0, openErr
 | 
							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
 | 
						// Open given handle as packet source and return it
 | 
				
			||||||
	packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
 | 
						packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
 | 
				
			||||||
	return packetSource, handle.LinkType(), nil
 | 
						return packetSource, handle.LinkType(), nil
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user