8 // Extracts the port as an integer from an address string.
9 func addrPortOrZero(addr net.Addr) int {
10 switch raw := addr.(type) {
16 // Consider a unix socket on Windows with a name like "C:notanint".
17 _, port, err := net.SplitHostPort(addr.String())
21 i64, err := strconv.ParseUint(port, 0, 16)
29 func addrIpOrNil(addr net.Addr) net.IP {
33 switch raw := addr.(type) {
39 host, _, err := net.SplitHostPort(addr.String())
43 return net.ParseIP(host)
47 type ipPortAddr struct {
52 func (ipPortAddr) Network() string {
56 func (me ipPortAddr) String() string {
57 return net.JoinHostPort(me.IP.String(), strconv.FormatInt(int64(me.Port), 10))
60 func tryIpPortFromNetAddr(addr PeerRemoteAddr) (ipPortAddr, bool) {
62 host, port, err := net.SplitHostPort(addr.String())
66 portI64, err := strconv.ParseInt(port, 10, 0)
70 return ipPortAddr{net.ParseIP(host), int(portI64)}, ok