network_utils.go (AdGuardHome-0.104.1) | : | network_utils.go (AdGuardHome-0.104.3) | ||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
"runtime" | "runtime" | |||
"strings" | "strings" | |||
"github.com/AdguardTeam/AdGuardHome/internal/util" | "github.com/AdguardTeam/AdGuardHome/internal/util" | |||
"github.com/AdguardTeam/golibs/file" | "github.com/AdguardTeam/golibs/file" | |||
"github.com/AdguardTeam/golibs/log" | "github.com/AdguardTeam/golibs/log" | |||
) | ) | |||
// Check if network interface has a static IP configured | // HasStaticIP check if the network interface has a static IP configured | |||
// | ||||
// Supports: Raspbian. | // Supports: Raspbian. | |||
func HasStaticIP(ifaceName string) (bool, error) { | func HasStaticIP(ifaceName string) (bool, error) { | |||
if runtime.GOOS == "linux" { | if runtime.GOOS == "linux" { | |||
body, err := ioutil.ReadFile("/etc/dhcpcd.conf") | body, err := ioutil.ReadFile("/etc/dhcpcd.conf") | |||
if err != nil { | if err != nil { | |||
return false, err | return false, err | |||
} | } | |||
return hasStaticIPDhcpcdConf(string(body), ifaceName), nil | return hasStaticIPDhcpcdConf(string(body), ifaceName), nil | |||
} | } | |||
if runtime.GOOS == "darwin" { | if runtime.GOOS == "darwin" { | |||
return hasStaticIPDarwin(ifaceName) | return hasStaticIPDarwin(ifaceName) | |||
} | } | |||
return false, fmt.Errorf("cannot check if IP is static: not supported on %s", runtime.GOOS) | return false, fmt.Errorf("cannot check if IP is static: not supported on %s", runtime.GOOS) | |||
} | } | |||
// Set a static IP for the specified network interface | // SetStaticIP sets a static IP for the network interface. | |||
func SetStaticIP(ifaceName string) error { | func SetStaticIP(ifaceName string) error { | |||
if runtime.GOOS == "linux" { | if runtime.GOOS == "linux" { | |||
return setStaticIPDhcpdConf(ifaceName) | return setStaticIPDhcpdConf(ifaceName) | |||
} | } | |||
if runtime.GOOS == "darwin" { | if runtime.GOOS == "darwin" { | |||
return setStaticIPDarwin(ifaceName) | return setStaticIPDarwin(ifaceName) | |||
} | } | |||
return fmt.Errorf("cannot set static IP on %s", runtime.GOOS) | return fmt.Errorf("cannot set static IP on %s", runtime.GOOS) | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 3 lines changed or added |