mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
parent
d56a439a74
commit
d2ae94f20b
|
@ -40,17 +40,26 @@ func ResolveInterface(name string) (*Interface, error) {
|
||||||
|
|
||||||
ipNets := make([]netip.Prefix, 0, len(addrs))
|
ipNets := make([]netip.Prefix, 0, len(addrs))
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
|
var pf netip.Prefix
|
||||||
|
switch addr.(type) {
|
||||||
|
case *net.IPNet:
|
||||||
ipNet := addr.(*net.IPNet)
|
ipNet := addr.(*net.IPNet)
|
||||||
ip, _ := netip.AddrFromSlice(ipNet.IP)
|
ip, _ := netip.AddrFromSlice(ipNet.IP)
|
||||||
|
|
||||||
ones, bits := ipNet.Mask.Size()
|
ones, bits := ipNet.Mask.Size()
|
||||||
if bits == 32 {
|
if bits == 32 {
|
||||||
ip = ip.Unmap()
|
ip = ip.Unmap()
|
||||||
}
|
}
|
||||||
|
pf = netip.PrefixFrom(ip, ones)
|
||||||
pf := netip.PrefixFrom(ip, ones)
|
case *net.IPAddr:
|
||||||
|
ipNet := addr.(*net.IPAddr)
|
||||||
|
ip, _ := netip.AddrFromSlice(ipNet.IP)
|
||||||
|
ip = ip.Unmap()
|
||||||
|
pf = netip.PrefixFrom(ip, ip.BitLen())
|
||||||
|
}
|
||||||
|
if pf.IsValid() {
|
||||||
ipNets = append(ipNets, pf)
|
ipNets = append(ipNets, pf)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
r[iface.Name] = &Interface{
|
r[iface.Name] = &Interface{
|
||||||
Index: iface.Index,
|
Index: iface.Index,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user