golang - net ListenIP network type

It can be difficult to get right. Perhaps the docs should be better.

If you try to use net.ListenIP and since the network is a string parameter, it should be what listed in the code below but it can also just be "ip4" - and i guess that's what trip alot of developers. 


ipServer, err := net.ResolveIPAddr(CONN_TYPE, CONN_HOST)

    if err != nil {
        fmt.Println("unable to resolve ip address", err.Error())
        os.Exit(1)
    }

    l, err := net.ListenIP("ip4:icmp", ipServer)
    if err != nil {
        fmt.Println("Error listening:", err.Error())
        os.Exit(1)
    }
    defer l.Close()

For a complete list of options available, you can check this link out

https://github.com/golang/go/blob/9341fe073e6f7742c9d61982084874560dac2014/src/net/lookup.go#L22

 




Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm