diff options
Diffstat (limited to 'src/pkg/net/interface_bsd.go')
-rw-r--r-- | src/pkg/net/interface_bsd.go | 65 |
1 files changed, 21 insertions, 44 deletions
diff --git a/src/pkg/net/interface_bsd.go b/src/pkg/net/interface_bsd.go index 141b95b38..a4c3e71fe 100644 --- a/src/pkg/net/interface_bsd.go +++ b/src/pkg/net/interface_bsd.go @@ -12,49 +12,6 @@ import ( "unsafe" ) -// IsUp returns true if ifi is up. -func (ifi *Interface) IsUp() bool { - if ifi == nil { - return false - } - return ifi.rawFlags&syscall.IFF_UP != 0 -} - -// IsLoopback returns true if ifi is a loopback interface. -func (ifi *Interface) IsLoopback() bool { - if ifi == nil { - return false - } - return ifi.rawFlags&syscall.IFF_LOOPBACK != 0 -} - -// CanBroadcast returns true if ifi supports a broadcast access -// capability. -func (ifi *Interface) CanBroadcast() bool { - if ifi == nil { - return false - } - return ifi.rawFlags&syscall.IFF_BROADCAST != 0 -} - -// IsPointToPoint returns true if ifi belongs to a point-to-point -// link. -func (ifi *Interface) IsPointToPoint() bool { - if ifi == nil { - return false - } - return ifi.rawFlags&syscall.IFF_POINTOPOINT != 0 -} - -// CanMulticast returns true if ifi supports a multicast access -// capability. -func (ifi *Interface) CanMulticast() bool { - if ifi == nil { - return false - } - return ifi.rawFlags&syscall.IFF_MULTICAST != 0 -} - // If the ifindex is zero, interfaceTable returns mappings of all // network interfaces. Otheriwse it returns a mapping of a specific // interface. @@ -106,7 +63,7 @@ func newLink(m *syscall.InterfaceMessage) ([]Interface, os.Error) { // NOTE: SockaddrDatalink.Data is minimum work area, // can be larger. m.Data = m.Data[unsafe.Offsetof(v.Data):] - ifi := Interface{Index: int(m.Header.Index), rawFlags: int(m.Header.Flags)} + ifi := Interface{Index: int(m.Header.Index), Flags: linkFlags(m.Header.Flags)} var name [syscall.IFNAMSIZ]byte for i := 0; i < int(v.Nlen); i++ { name[i] = byte(m.Data[i]) @@ -125,6 +82,26 @@ func newLink(m *syscall.InterfaceMessage) ([]Interface, os.Error) { return ift, nil } +func linkFlags(rawFlags int32) Flags { + var f Flags + if rawFlags&syscall.IFF_UP != 0 { + f |= FlagUp + } + if rawFlags&syscall.IFF_BROADCAST != 0 { + f |= FlagBroadcast + } + if rawFlags&syscall.IFF_LOOPBACK != 0 { + f |= FlagLoopback + } + if rawFlags&syscall.IFF_POINTOPOINT != 0 { + f |= FlagPointToPoint + } + if rawFlags&syscall.IFF_MULTICAST != 0 { + f |= FlagMulticast + } + return f +} + // If the ifindex is zero, interfaceAddrTable returns addresses // for all network interfaces. Otherwise it returns addresses // for a specific interface. |