I have a TCPConn* that I've accepted from a TCPListener.acceptTCP. I'd like to get only the IP address (no port information) as a string or IP. What is the correct (i.e. minimal casting/string manipulation) way to accomplish that?
To get the IP, as an IP object, the most straightforward way should be
tcpconn.RemoteAddr().(*net.TCPAddr).IP
There is nothing wrong with using type assertions, and in cases like this it's actually expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With