Loading tdmbs/tdmbs.go +39 −3 Original line number Diff line number Diff line package tdmbs import "errors" import ( "errors" "net" ) const ( DefaultPortCommands = 31285 Loading @@ -15,8 +18,41 @@ func New() *Server { return &Server{} } func (s *Server) FindLocalNetworkAdresses() error { return errors.New("not implemented") func (s *Server) ScanForNetworkAdresses() ([]net.Addr, error) { addrs := []net.Addr{} ifaces, err := net.Interfaces() if err != nil { return addrs, err } for _, ifc := range ifaces { if (ifc.Flags & net.FlagLoopback) == net.FlagLoopback { continue } if (ifc.Flags & net.FlagUp) != net.FlagUp { continue } if (ifc.Flags & net.FlagPointToPoint) == net.FlagPointToPoint { continue } if (ifc.Flags & net.FlagBroadcast) != net.FlagBroadcast { continue } as, err := ifc.Addrs() if err != nil { continue } if len(as) < 1 { continue } addrs = append(addrs, as...) } return addrs, nil } func (s *Server) FindWithBroadcast() error { Loading tdmbs/tdmbs_test.go +5 −31 Original line number Diff line number Diff line package tdmbs import ( "net" "testing" ) func TestFindLocalNetworks(t *testing.T) { ifaces, err := net.Interfaces() s := New() addrs, err := s.ScanForNetworkAdresses() if err != nil { t.Fatalf("net.Interfaces() failed with: %s", err) t.Fatalf("ScanForNetworkAdresses() failed with: %s", err) } for _, ifc := range ifaces { if (ifc.Flags & net.FlagLoopback) == net.FlagLoopback { continue } if (ifc.Flags & net.FlagUp) != net.FlagUp { continue } if (ifc.Flags & net.FlagPointToPoint) == net.FlagPointToPoint { continue } if (ifc.Flags & net.FlagBroadcast) != net.FlagBroadcast { continue } addrs, err := ifc.Addrs() if err != nil { t.Errorf("ifc.Addrs() failed with: %s", err) continue } if len(addrs) < 1 { continue } t.Logf("- %#v", ifc) for _, addr := range addrs { t.Logf(" - %s", addr) } } } Loading
tdmbs/tdmbs.go +39 −3 Original line number Diff line number Diff line package tdmbs import "errors" import ( "errors" "net" ) const ( DefaultPortCommands = 31285 Loading @@ -15,8 +18,41 @@ func New() *Server { return &Server{} } func (s *Server) FindLocalNetworkAdresses() error { return errors.New("not implemented") func (s *Server) ScanForNetworkAdresses() ([]net.Addr, error) { addrs := []net.Addr{} ifaces, err := net.Interfaces() if err != nil { return addrs, err } for _, ifc := range ifaces { if (ifc.Flags & net.FlagLoopback) == net.FlagLoopback { continue } if (ifc.Flags & net.FlagUp) != net.FlagUp { continue } if (ifc.Flags & net.FlagPointToPoint) == net.FlagPointToPoint { continue } if (ifc.Flags & net.FlagBroadcast) != net.FlagBroadcast { continue } as, err := ifc.Addrs() if err != nil { continue } if len(as) < 1 { continue } addrs = append(addrs, as...) } return addrs, nil } func (s *Server) FindWithBroadcast() error { Loading
tdmbs/tdmbs_test.go +5 −31 Original line number Diff line number Diff line package tdmbs import ( "net" "testing" ) func TestFindLocalNetworks(t *testing.T) { ifaces, err := net.Interfaces() s := New() addrs, err := s.ScanForNetworkAdresses() if err != nil { t.Fatalf("net.Interfaces() failed with: %s", err) t.Fatalf("ScanForNetworkAdresses() failed with: %s", err) } for _, ifc := range ifaces { if (ifc.Flags & net.FlagLoopback) == net.FlagLoopback { continue } if (ifc.Flags & net.FlagUp) != net.FlagUp { continue } if (ifc.Flags & net.FlagPointToPoint) == net.FlagPointToPoint { continue } if (ifc.Flags & net.FlagBroadcast) != net.FlagBroadcast { continue } addrs, err := ifc.Addrs() if err != nil { t.Errorf("ifc.Addrs() failed with: %s", err) continue } if len(addrs) < 1 { continue } t.Logf("- %#v", ifc) for _, addr := range addrs { t.Logf(" - %s", addr) } } }