Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing spurious log #21

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ image:
./scripts/image.sh
launch:
./scripts/launch.sh
exe:
build:
go build l2discovery.go
# Install golangci-lint
install-lint:
Expand Down
10 changes: 6 additions & 4 deletions l2discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func RunLocalCommand(command string) (outStr, errStr string, err error) {
}

func main() {
logrus.SetLevel(logrus.FatalLevel)
macs, macExist, _ := getIfs()
MacsPerIface = make(map[string]map[string]*exports.Neighbors)
for _, iface := range macs {
Expand All @@ -169,7 +170,7 @@ func sendProbe(iface *exports.Iface) {
fd, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_RAW, syscall.ETH_P_ALL)
defer syscall.Close(fd)
if err != nil {
fmt.Println("Error: " + err.Error())
logrus.Errorf("Error: " + err.Error())
return
}
err = syscall.BindToDevice(fd, iface.IfName)
Expand All @@ -182,7 +183,7 @@ func sendProbe(iface *exports.Iface) {
logrus.Tracef("Size : %d", size)
interf, err := net.InterfaceByName(iface.IfName)
if err != nil {
fmt.Println("Could not find " + iface.IfName + " interface")
logrus.Errorf("Could not find " + iface.IfName + " interface")
return
}
logrus.Tracef("Interface hw address: %s", iface.IfMac)
Expand All @@ -199,7 +200,7 @@ func sendProbe(iface *exports.Iface) {
err = syscall.Sendto(fd, packet, 0, &addr)

if err != nil {
fmt.Println("Error: ", err)
logrus.Errorf("error: %s", err)
}
logrus.Tracef("Sent packet")
}
Expand Down Expand Up @@ -271,8 +272,9 @@ func PrintLog() {
mu.Lock()
aString, err := json.Marshal(MacsPerIface)
if err != nil {
fmt.Println("Cannot marshall MacsPerIface")
logrus.Errorf("Cannot marshall MacsPerIface")
}
// Only log printed
fmt.Printf("JSON_REPORT%s\n", string(aString))
mu.Unlock()
time.Sleep(time.Second * logPrintPeriod)
Expand Down