Source file src/pkg/net/tcpsock.go
1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // TCP sockets 6 7 package net 8 9 import ( 10 "os" 11 ) 12 13 // TCPAddr represents the address of a TCP end point. 14 type TCPAddr struct { 15 IP IP 16 Port int 17 } 18 19 // Network returns the address's network name, "tcp". 20 func (a *TCPAddr) Network() string { return "tcp" } 21 22 func (a *TCPAddr) String() string { 23 if a == nil { 24 return "<nil>" 25 } 26 return JoinHostPort(a.IP.String(), itoa(a.Port)) 27 } 28 29 // ResolveTCPAddr parses addr as a TCP address of the form 30 // host:port and resolves domain names or port names to 31 // numeric addresses on the network net, which must be "tcp", 32 // "tcp4" or "tcp6". A literal IPv6 host address must be 33 // enclosed in square brackets, as in "[::]:80". 34 func ResolveTCPAddr(net, addr string) (*TCPAddr, os.Error) { 35 ip, port, err := hostPortToIP(net, addr) 36 if err != nil { 37 return nil, err 38 } 39 return &TCPAddr{ip, port}, nil 40 }