ipaddr
ipaddr copied to clipboard
Iteration over a prefix with a single IP does not work
If you call ipaddr.Parse with input that is only a single IP (127.0.0.1, 127.0.0.1/32) the supplied cursor will not return any entries via Next(). Getting the value via First() works fine.
I believe Next() should return the first, and only entry, and then return nil.
I am parsing a mix of single hosts and networks both in CIDR notation and noticed that anything with a /32 prefix was being dropped because of Next() returning nil immediately.
Here is an example program to show the issue.
https://play.golang.org/p/xZEOyiLCXYN
`package main
import ( "fmt" "github.com/mikioh/ipaddr" )
func printIPs(ip string) { cursor, err := ipaddr.Parse(ip) if err != nil { fmt.Println(err) } else { fmt.Println(cursor.Pos(), cursor.First(), cursor.Last(), cursor.List()) fmt.Println("First is: ", cursor.First().IP.String()) fmt.Println("All Members:") for pos := cursor.Next(); pos != nil; pos = cursor.Next() { fmt.Println(pos.IP.String()) } } }
func main() { printIPs("192.168.168.77/32") printIPs("127.0.0.1/32") printIPs("127.0.0.0/29") } `