Daily bump.
[official-gcc.git] / libgo / go / net / iprawsock.go
blob5cc361390ff56a94ba0ea3d8ab5bafbe1489c908
1 // Copyright 2010 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 // IPAddr represents the address of an IP end point.
8 type IPAddr struct {
9 IP IP
10 Zone string // IPv6 scoped addressing zone
13 // Network returns the address's network name, "ip".
14 func (a *IPAddr) Network() string { return "ip" }
16 func (a *IPAddr) String() string {
17 if a == nil {
18 return "<nil>"
20 if a.Zone != "" {
21 return a.IP.String() + "%" + a.Zone
23 return a.IP.String()
26 func (a *IPAddr) toAddr() Addr {
27 if a == nil {
28 return nil
30 return a
33 // ResolveIPAddr parses addr as an IP address of the form "host" or
34 // "ipv6-host%zone" and resolves the domain name on the network net,
35 // which must be "ip", "ip4" or "ip6".
36 func ResolveIPAddr(net, addr string) (*IPAddr, error) {
37 if net == "" { // a hint wildcard for Go 1.0 undocumented behavior
38 net = "ip"
40 afnet, _, err := parseNetwork(net)
41 if err != nil {
42 return nil, err
44 switch afnet {
45 case "ip", "ip4", "ip6":
46 default:
47 return nil, UnknownNetworkError(net)
49 a, err := resolveInternetAddr(afnet, addr, noDeadline)
50 if err != nil {
51 return nil, err
53 return a.toAddr().(*IPAddr), nil