2010-05-21 18:30:40 -06:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
net, cmd/fix: add IPv6 scoped addressing zone to INET, INET6 address structs
This CL starts to introduce IPv6 scoped addressing capability
into the net package.
The Public API changes are:
+pkg net, type IPAddr struct, Zone string
+pkg net, type IPNet struct, Zone string
+pkg net, type TCPAddr struct, Zone string
+pkg net, type UDPAddr struct, Zone string
Update #4234.
R=rsc, bradfitz, iant
CC=golang-dev
https://golang.org/cl/6849045
2012-11-26 08:45:42 -07:00
|
|
|
// Raw IP sockets
|
2010-05-21 18:30:40 -06:00
|
|
|
|
|
|
|
package net
|
|
|
|
|
2012-07-19 17:32:25 -06:00
|
|
|
// IPAddr represents the address of an IP end point.
|
2010-05-21 18:30:40 -06:00
|
|
|
type IPAddr struct {
|
net, cmd/fix: add IPv6 scoped addressing zone to INET, INET6 address structs
This CL starts to introduce IPv6 scoped addressing capability
into the net package.
The Public API changes are:
+pkg net, type IPAddr struct, Zone string
+pkg net, type IPNet struct, Zone string
+pkg net, type TCPAddr struct, Zone string
+pkg net, type UDPAddr struct, Zone string
Update #4234.
R=rsc, bradfitz, iant
CC=golang-dev
https://golang.org/cl/6849045
2012-11-26 08:45:42 -07:00
|
|
|
IP IP
|
|
|
|
Zone string // IPv6 scoped addressing zone
|
2010-05-21 18:30:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Network returns the address's network name, "ip".
|
|
|
|
func (a *IPAddr) Network() string { return "ip" }
|
|
|
|
|
2010-07-27 01:22:22 -06:00
|
|
|
func (a *IPAddr) String() string {
|
|
|
|
if a == nil {
|
|
|
|
return "<nil>"
|
|
|
|
}
|
|
|
|
return a.IP.String()
|
|
|
|
}
|
2010-05-21 18:30:40 -06:00
|
|
|
|
2012-07-19 17:32:25 -06:00
|
|
|
// ResolveIPAddr parses addr as an IP address and resolves domain
|
2011-05-16 15:03:06 -06:00
|
|
|
// names to numeric addresses on the network net, which must be
|
|
|
|
// "ip", "ip4" or "ip6". A literal IPv6 host address must be
|
2010-05-21 18:30:40 -06:00
|
|
|
// enclosed in square brackets, as in "[::]".
|
2011-11-01 20:05:34 -06:00
|
|
|
func ResolveIPAddr(net, addr string) (*IPAddr, error) {
|
2012-11-27 14:36:05 -07:00
|
|
|
afnet, _, err := parseDialNetwork(net)
|
2010-05-21 18:30:40 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2012-11-27 14:36:05 -07:00
|
|
|
switch afnet {
|
|
|
|
case "ip", "ip4", "ip6":
|
|
|
|
default:
|
|
|
|
return nil, UnknownNetworkError(net)
|
2010-05-21 18:30:40 -06:00
|
|
|
}
|
2012-11-27 14:36:05 -07:00
|
|
|
a, err := resolveInternetAddr(afnet, addr, noDeadline)
|
|
|
|
return a.(*IPAddr), nil
|
2010-05-21 18:30:40 -06:00
|
|
|
}
|