platform: Add link flags

This commit is contained in:
世界 2024-10-29 15:28:58 +08:00
parent b702d0b67a
commit 1d517b6ca5
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
4 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,30 @@
package libbox
import (
"net"
"syscall"
)
// copied from net.linkFlags
func linkFlags(rawFlags uint32) net.Flags {
var f net.Flags
if rawFlags&syscall.IFF_UP != 0 {
f |= net.FlagUp
}
if rawFlags&syscall.IFF_RUNNING != 0 {
f |= net.FlagRunning
}
if rawFlags&syscall.IFF_BROADCAST != 0 {
f |= net.FlagBroadcast
}
if rawFlags&syscall.IFF_LOOPBACK != 0 {
f |= net.FlagLoopback
}
if rawFlags&syscall.IFF_POINTOPOINT != 0 {
f |= net.FlagPointToPoint
}
if rawFlags&syscall.IFF_MULTICAST != 0 {
f |= net.FlagMulticast
}
return f
}

View file

@ -0,0 +1,11 @@
//go:build !linux
package libbox
import (
"net"
)
func linkFlags(rawFlags uint32) net.Flags {
panic("stub!")
}

View file

@ -38,6 +38,7 @@ type NetworkInterface struct {
MTU int32 MTU int32
Name string Name string
Addresses StringIterator Addresses StringIterator
Flags int32
} }
type WIFIState struct { type WIFIState struct {

View file

@ -181,6 +181,7 @@ func (w *platformInterfaceWrapper) Interfaces() ([]control.Interface, error) {
MTU: int(netInterface.MTU), MTU: int(netInterface.MTU),
Name: netInterface.Name, Name: netInterface.Name,
Addresses: common.Map(iteratorToArray[string](netInterface.Addresses), netip.MustParsePrefix), Addresses: common.Map(iteratorToArray[string](netInterface.Addresses), netip.MustParsePrefix),
Flags: linkFlags(uint32(netInterface.Flags)),
}) })
} }
return interfaces, nil return interfaces, nil