mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-29 02:18:51 +03:00
c70f941bf8
Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage
39 lines
894 B
Go
39 lines
894 B
Go
//go:build openbsd
|
|
// +build openbsd
|
|
|
|
package aghnet
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"strings"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
|
)
|
|
|
|
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)
|
|
if len(fields) >= 2 && fields[0] == "inet" && net.ParseIP(fields[1]) != nil {
|
|
return nil, false, s.Err()
|
|
}
|
|
}
|
|
|
|
return nil, true, s.Err()
|
|
}
|
|
|
|
func ifaceSetStaticIP(string) (err error) {
|
|
return aghos.Unsupported("setting static ip")
|
|
}
|