mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-14 18:51:34 +03:00
edfa8c147f
Squashed commit of the following: commit 8d83eebba851e8e09bb08b1c94a247cb049a1b75 Merge:c6574a33c
b6ed76965
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Aug 5 16:59:50 2024 +0300 Merge branch 'master' into AGDNS-2280-upd-golibs commitc6574a33c6
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Jul 31 19:56:58 2024 +0300 all: upd proxy, golibs
45 lines
955 B
Go
45 lines
955 B
Go
//go:build openbsd
|
|
|
|
package aghnet
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
|
"github.com/AdguardTeam/golibs/netutil"
|
|
)
|
|
|
|
func ifaceHasStaticIP(ifaceName string) (ok bool, err error) {
|
|
filename := fmt.Sprintf("etc/hostname.%s", ifaceName)
|
|
|
|
return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename)
|
|
}
|
|
|
|
// hostnameIfStaticConfig checks if the interface is configured by
|
|
// /etc/hostname.* to have a static IP.
|
|
func hostnameIfStaticConfig(r io.Reader) (_ []string, ok bool, err error) {
|
|
s := bufio.NewScanner(r)
|
|
for s.Scan() {
|
|
line := strings.TrimSpace(s.Text())
|
|
fields := strings.Fields(line)
|
|
switch {
|
|
case
|
|
len(fields) < 2,
|
|
fields[0] != "inet",
|
|
!netutil.IsValidIPString(fields[1]):
|
|
continue
|
|
default:
|
|
return nil, false, s.Err()
|
|
}
|
|
}
|
|
|
|
return nil, true, s.Err()
|
|
}
|
|
|
|
func ifaceSetStaticIP(string) (err error) {
|
|
return aghos.Unsupported("setting static ip")
|
|
}
|