diff --git a/ipnet.go b/ipnet.go index 62b3403..74b5c0b 100644 --- a/ipnet.go +++ b/ipnet.go @@ -289,6 +289,7 @@ func NewIPNetwork(ipnet string) (IPNetwork, error) { var mask int index := strings.IndexByte(ipnet, '/') if index == -1 { + index = len(ipnet) if strings.IndexByte(ipnet, ':') == -1 { mask = 32 } else { diff --git a/ipnet_test.go b/ipnet_test.go index 48b6343..ff7ff71 100644 --- a/ipnet_test.go +++ b/ipnet_test.go @@ -16,8 +16,21 @@ package netaddr import ( "fmt" + "testing" ) +func TestNewIPNetwork(t *testing.T) { + net := MustNewIPNetwork("192.168.10.10/24") + if net.String() != "192.168.10.10/24" { + t.Error(net.String()) + } + + net = MustNewIPNetwork("192.168.10.10") + if net.String() != "192.168.10.10/32" { + t.Error(net.String()) + } +} + func ExampleIPNetwork_Network() { net := MustNewIPNetwork("192.168.10.10/24") fmt.Println(net.Network())