From e528522ad51b4c1357b9d6a4f0c592176745c077 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 31 Jan 2020 13:24:18 +0300 Subject: [PATCH] linter --- dhcpd/network_utils.go | 74 ------------------------------------------ 1 file changed, 74 deletions(-) diff --git a/dhcpd/network_utils.go b/dhcpd/network_utils.go index 16a3c7dd..30180df2 100644 --- a/dhcpd/network_utils.go +++ b/dhcpd/network_utils.go @@ -5,13 +5,9 @@ import ( "fmt" "io/ioutil" "net" - "os" "os/exec" "runtime" - "strconv" "strings" - "syscall" - "time" "github.com/AdguardTeam/golibs/file" "github.com/AdguardTeam/golibs/log" @@ -174,24 +170,6 @@ func getFullIP(ifaceName string) string { return fields[3] } -// Get interface name by its IP address. -func getInterfaceByIP(ip string) string { - ifaces, err := getValidNetInterfacesForWeb() - if err != nil { - return "" - } - - for _, iface := range ifaces { - for _, addr := range iface.Addresses { - if ip == addr { - return iface.Name - } - } - } - - return "" -} - // Get gateway IP address func getGatewayIP(ifaceName string) string { cmd := exec.Command("ip", "route", "show", "dev", ifaceName) @@ -263,55 +241,3 @@ func setStaticIPDhcpcdConf(ifaceName, ip, gatewayIP, dnsIP string) string { return string(body) } - -// checkPortAvailable is not a cheap test to see if the port is bindable, because it's actually doing the bind momentarily -func checkPortAvailable(host string, port int) error { - ln, err := net.Listen("tcp", net.JoinHostPort(host, strconv.Itoa(port))) - if err != nil { - return err - } - ln.Close() - - // It seems that net.Listener.Close() doesn't close file descriptors right away. - // We wait for some time and hope that this fd will be closed. - time.Sleep(100 * time.Millisecond) - return nil -} - -func checkPacketPortAvailable(host string, port int) error { - ln, err := net.ListenPacket("udp", net.JoinHostPort(host, strconv.Itoa(port))) - if err != nil { - return err - } - ln.Close() - - // It seems that net.Listener.Close() doesn't close file descriptors right away. - // We wait for some time and hope that this fd will be closed. - time.Sleep(100 * time.Millisecond) - return err -} - -// check if error is "address already in use" -func errorIsAddrInUse(err error) bool { - errOpError, ok := err.(*net.OpError) - if !ok { - return false - } - - errSyscallError, ok := errOpError.Err.(*os.SyscallError) - if !ok { - return false - } - - errErrno, ok := errSyscallError.Err.(syscall.Errno) - if !ok { - return false - } - - if runtime.GOOS == "windows" { - const WSAEADDRINUSE = 10048 - return errErrno == WSAEADDRINUSE - } - - return errErrno == syscall.EADDRINUSE -}