diff --git a/src/pkg/net/interface.go b/src/pkg/net/interface.go index f622487ab0..f6de36f645 100644 --- a/src/pkg/net/interface.go +++ b/src/pkg/net/interface.go @@ -34,7 +34,41 @@ type Interface struct { MTU int // maximum transmission unit Name string // e.g., "en0", "lo0", "eth0.100" HardwareAddr HardwareAddr // IEEE MAC-48, EUI-48 and EUI-64 form - rawFlags int + Flags Flags // e.g., FlagUp, FlagLoopback, FlagMulticast +} + +type Flags uint + +const ( + FlagUp Flags = 1 << iota // interface is up + FlagBroadcast // interface supports broadcast access capability + FlagLoopback // interface is a loopback interface + FlagPointToPoint // interface belongs to a point-to-point link + FlagMulticast // interface supports multicast access capability +) + +var flagNames = []string{ + "up", + "broadcast", + "loopback", + "pointtopoint", + "multicast", +} + +func (f Flags) String() string { + s := "" + for i, name := range flagNames { + if f&(1< 1 { - fs = fs[:len(fs)-1] - } - fs += ">" - return fs -} - func TestInterfaces(t *testing.T) { ift, err := Interfaces() if err != nil { @@ -69,11 +45,11 @@ func TestInterfaces(t *testing.T) { if err != nil { t.Fatalf("Interface.Addrs() failed: %v", err) } - t.Logf("%s: flags %s, ifindex %v, mtu %v\n", ifi.Name, interfaceFlagsString(&ifi), ifi.Index, ifi.MTU) + t.Logf("%q: flags %q, ifindex %v, mtu %v\n", ifi.Name, ifi.Flags.String(), ifi.Index, ifi.MTU) for _, ifa := range ifat { - t.Logf("\tinterface address %s\n", ifa.String()) + t.Logf("\tinterface address %q\n", ifa.String()) } - t.Logf("\thardware address %v", ifi.HardwareAddr.String()) + t.Logf("\thardware address %q", ifi.HardwareAddr.String()) } } @@ -85,6 +61,6 @@ func TestInterfaceAddrs(t *testing.T) { t.Logf("table: len/cap = %v/%v\n", len(ifat), cap(ifat)) for _, ifa := range ifat { - t.Logf("interface address %s\n", ifa.String()) + t.Logf("interface address %q\n", ifa.String()) } }