Adding error handling for socket connection
This commit is contained in:
14
main.go
14
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -70,12 +71,21 @@ func sInit(os string) *targetInfo {
|
|||||||
return &tInfo
|
return &tInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func openCapture(tInfo *targetInfo) *pcap.Handle {
|
||||||
|
for {
|
||||||
|
handle, err := pcap.OpenLive(tInfo.iFace, tInfo.snaplen, true, pcap.BlockForever)
|
||||||
|
if err == nil {
|
||||||
|
return handle
|
||||||
|
}
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
tInfo := sInit(runtime.GOOS)
|
tInfo := sInit(runtime.GOOS)
|
||||||
|
|
||||||
// Read package and analze them
|
// Read package and analze them
|
||||||
handle, err := pcap.OpenLive(tInfo.iFace, tInfo.snaplen, true, pcap.BlockForever)
|
handle := openCapture(tInfo)
|
||||||
errorPrinter(err)
|
|
||||||
|
|
||||||
handle.SetBPFFilter(tInfo.filter)
|
handle.SetBPFFilter(tInfo.filter)
|
||||||
packets := gopacket.NewPacketSource(handle, handle.LinkType()).Packets()
|
packets := gopacket.NewPacketSource(handle, handle.LinkType()).Packets()
|
||||||
|
|||||||
Reference in New Issue
Block a user