Commit d23064d0 authored by Mikio Hara's avatar Mikio Hara

net: update documentation on Resolve{TCP,UDP,IP,Unix}Addr

This change clarifies the documentation on
Resolve{TCP,UDP,IP,Unix}Addr to avoid unnecessary confusion about how
the arguments are used to make end point addresses.

Also replaces "name" or "hostname" with "host name" when the term
implies the use of DNS.

Updates #17613.

Change-Id: Id6be87fe2e4666eecd5b92f18ad8b9a6c50a2bd6
Reviewed-on: https://go-review.googlesource.com/34879Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent e25fa61b
...@@ -61,26 +61,33 @@ func (a *IPAddr) opAddr() Addr { ...@@ -61,26 +61,33 @@ func (a *IPAddr) opAddr() Addr {
return a return a
} }
// ResolveIPAddr parses addr as an IP address of the form "host" or // ResolveIPAddr returns an address of IP end point.
// "ipv6-host%zone" and resolves the domain name on the network net,
// which must be "ip", "ip4" or "ip6".
// //
// Resolving a hostname is not recommended because this returns at most // The network must be an IP network name.
// one of its IP addresses. //
func ResolveIPAddr(net, addr string) (*IPAddr, error) { // If the host in the address parameter is not a literal IP address,
if net == "" { // a hint wildcard for Go 1.0 undocumented behavior // ResolveIPAddr resolves the address to an address of IP end point.
net = "ip" // Otherwise, it parses the address as a literal IP address.
// The address parameter can use a host name, but this is not
// recommended, because it will return at most one of the host name's
// IP addresses.
//
// See func Dial for a description of the network and address
// parameters.
func ResolveIPAddr(network, address string) (*IPAddr, error) {
if network == "" { // a hint wildcard for Go 1.0 undocumented behavior
network = "ip"
} }
afnet, _, err := parseNetwork(context.Background(), net, false) afnet, _, err := parseNetwork(context.Background(), network, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
switch afnet { switch afnet {
case "ip", "ip4", "ip6": case "ip", "ip4", "ip6":
default: default:
return nil, UnknownNetworkError(net) return nil, UnknownNetworkError(network)
} }
addrs, err := DefaultResolver.internetAddrList(context.Background(), afnet, addr) addrs, err := DefaultResolver.internetAddrList(context.Background(), afnet, address)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -50,24 +50,30 @@ func (a *TCPAddr) opAddr() Addr { ...@@ -50,24 +50,30 @@ func (a *TCPAddr) opAddr() Addr {
return a return a
} }
// ResolveTCPAddr parses addr as a TCP address of the form "host:port" // ResolveTCPAddr returns an address of TCP end point.
// or "[ipv6-host%zone]:port" and resolves a pair of domain name and
// port name on the network net, which must be "tcp", "tcp4" or
// "tcp6". A literal address or host name for IPv6 must be enclosed
// in square brackets, as in "[::1]:80", "[ipv6-host]:http" or
// "[ipv6-host%zone]:80".
// //
// Resolving a hostname is not recommended because this returns at most // The network must be a TCP network name.
// one of its IP addresses. //
func ResolveTCPAddr(net, addr string) (*TCPAddr, error) { // If the host in the address parameter is not a literal IP address or
switch net { // the port is not a literal port number, ResolveTCPAddr resolves the
// address to an address of TCP end point.
// Otherwise, it parses the address as a pair of literal IP address
// and port number.
// The address parameter can use a host name, but this is not
// recommended, because it will return at most one of the host name's
// IP addresses.
//
// See func Dial for a description of the network and address
// parameters.
func ResolveTCPAddr(network, address string) (*TCPAddr, error) {
switch network {
case "tcp", "tcp4", "tcp6": case "tcp", "tcp4", "tcp6":
case "": // a hint wildcard for Go 1.0 undocumented behavior case "": // a hint wildcard for Go 1.0 undocumented behavior
net = "tcp" network = "tcp"
default: default:
return nil, UnknownNetworkError(net) return nil, UnknownNetworkError(network)
} }
addrs, err := DefaultResolver.internetAddrList(context.Background(), net, addr) addrs, err := DefaultResolver.internetAddrList(context.Background(), network, address)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -53,24 +53,30 @@ func (a *UDPAddr) opAddr() Addr { ...@@ -53,24 +53,30 @@ func (a *UDPAddr) opAddr() Addr {
return a return a
} }
// ResolveUDPAddr parses addr as a UDP address of the form "host:port" // ResolveUDPAddr returns an address of UDP end point.
// or "[ipv6-host%zone]:port" and resolves a pair of domain name and
// port name on the network net, which must be "udp", "udp4" or
// "udp6". A literal address or host name for IPv6 must be enclosed
// in square brackets, as in "[::1]:80", "[ipv6-host]:http" or
// "[ipv6-host%zone]:80".
// //
// Resolving a hostname is not recommended because this returns at most // The network must be a UDP network name.
// one of its IP addresses. //
func ResolveUDPAddr(net, addr string) (*UDPAddr, error) { // If the host in the address parameter is not a literal IP address or
switch net { // the port is not a literal port number, ResolveUDPAddr resolves the
// address to an address of UDP end point.
// Otherwise, it parses the address as a pair of literal IP address
// and port number.
// The address parameter can use a host name, but this is not
// recommended, because it will return at most one of the host name's
// IP addresses.
//
// See func Dial for a description of the network and address
// parameters.
func ResolveUDPAddr(network, address string) (*UDPAddr, error) {
switch network {
case "udp", "udp4", "udp6": case "udp", "udp4", "udp6":
case "": // a hint wildcard for Go 1.0 undocumented behavior case "": // a hint wildcard for Go 1.0 undocumented behavior
net = "udp" network = "udp"
default: default:
return nil, UnknownNetworkError(net) return nil, UnknownNetworkError(network)
} }
addrs, err := DefaultResolver.internetAddrList(context.Background(), net, addr) addrs, err := DefaultResolver.internetAddrList(context.Background(), network, address)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -42,15 +42,18 @@ func (a *UnixAddr) opAddr() Addr { ...@@ -42,15 +42,18 @@ func (a *UnixAddr) opAddr() Addr {
return a return a
} }
// ResolveUnixAddr parses addr as a Unix domain socket address. // ResolveUnixAddr returns an address of Unix domain socket end point.
// The string net gives the network name, "unix", "unixgram" or //
// "unixpacket". // The network must be a Unix network name.
func ResolveUnixAddr(net, addr string) (*UnixAddr, error) { //
switch net { // See func Dial for a description of the network and address
// parameters.
func ResolveUnixAddr(network, address string) (*UnixAddr, error) {
switch network {
case "unix", "unixgram", "unixpacket": case "unix", "unixgram", "unixpacket":
return &UnixAddr{Name: addr, Net: net}, nil return &UnixAddr{Name: address, Net: network}, nil
default: default:
return nil, UnknownNetworkError(net) return nil, UnknownNetworkError(network)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment