Revert r215321.
[official-gcc.git] / libgo / go / net / udpsock.go
blob4c99ae4af6837e8c01ae03dcec0ca2111b2f0ac2
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.
5 package net
7 // UDPAddr represents the address of a UDP end point.
8 type UDPAddr struct {
9 IP IP
10 Port int
11 Zone string // IPv6 scoped addressing zone
14 // Network returns the address's network name, "udp".
15 func (a *UDPAddr) Network() string { return "udp" }
17 func (a *UDPAddr) String() string {
18 if a == nil {
19 return "<nil>"
21 ip := ipEmptyString(a.IP)
22 if a.Zone != "" {
23 return JoinHostPort(ip+"%"+a.Zone, itoa(a.Port))
25 return JoinHostPort(ip, itoa(a.Port))
28 func (a *UDPAddr) toAddr() Addr {
29 if a == nil {
30 return nil
32 return a
35 // ResolveUDPAddr parses addr as a UDP address of the form "host:port"
36 // or "[ipv6-host%zone]:port" and resolves a pair of domain name and
37 // port name on the network net, which must be "udp", "udp4" or
38 // "udp6". A literal address or host name for IPv6 must be enclosed
39 // in square brackets, as in "[::1]:80", "[ipv6-host]:http" or
40 // "[ipv6-host%zone]:80".
41 func ResolveUDPAddr(net, addr string) (*UDPAddr, error) {
42 switch net {
43 case "udp", "udp4", "udp6":
44 case "": // a hint wildcard for Go 1.0 undocumented behavior
45 net = "udp"
46 default:
47 return nil, UnknownNetworkError(net)
49 a, err := resolveInternetAddr(net, addr, noDeadline)
50 if err != nil {
51 return nil, err
53 return a.toAddr().(*UDPAddr), nil