|
@@ -173,22 +173,27 @@ func liveCapture() {
|
|
|
func processPacket(packet gopacket.Packet) {
|
|
|
count++
|
|
|
|
|
|
- ipLayer := packet.Layer(layers.LayerTypeIPv4)
|
|
|
- if ipLayer == nil {
|
|
|
- log.Println("No IPv4 Layer!")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- ip, _ := ipLayer.(*layers.IPv4)
|
|
|
-
|
|
|
- if ip.Protocol != layers.IPProtocolTCP {
|
|
|
- log.Println("No TCP Protocol!")
|
|
|
- return
|
|
|
+ hasIPv4 := false
|
|
|
+ var ipSrc, ipDst string
|
|
|
+
|
|
|
+ // IPv4
|
|
|
+ if ipLayer := packet.Layer(layers.LayerTypeIPv4); ipLayer != nil {
|
|
|
+ ip := ipLayer.(*layers.IPv4)
|
|
|
+ ipSrc = ip.SrcIP.String()
|
|
|
+ ipDst = ip.DstIP.String()
|
|
|
+ hasIPv4 = true
|
|
|
+ }
|
|
|
+
|
|
|
+ // IPv6
|
|
|
+ if !hasIPv4 {
|
|
|
+ if ipLayer := packet.Layer(layers.LayerTypeIPv6); ipLayer != nil {
|
|
|
+ ip := ipLayer.(*layers.IPv6)
|
|
|
+ ipSrc = ip.SrcIP.String()
|
|
|
+ ipDst = ip.DstIP.String()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- ipSrc := ip.SrcIP.String()
|
|
|
- ipDst := ip.DstIP.String()
|
|
|
-
|
|
|
+ // TCP
|
|
|
tcpLayer := packet.Layer(layers.LayerTypeTCP)
|
|
|
if tcpLayer == nil {
|
|
|
return
|