2011-08-17 11:28:29 -06:00
|
|
|
// Copyright 2009 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.
|
|
|
|
|
all: merge NaCl branch (part 1)
See golang.org/s/go13nacl for design overview.
This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come.
CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately.
The exact change lists included are
15050047: syscall: support for Native Client
15360044: syscall: unzip implementation for Native Client
15370044: syscall: Native Client SRPC implementation
15400047: cmd/dist, cmd/go, go/build, test: support for Native Client
15410048: runtime: support for Native Client
15410049: syscall: file descriptor table for Native Client
15410050: syscall: in-memory file system for Native Client
15440048: all: update +build lines for Native Client port
15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client
15570045: os: support for Native Client
15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32
15690044: net: support for Native Client
15690048: runtime: support for fake time like on Go Playground
15690051: build: disable various tests on Native Client
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68150047
2014-02-25 07:47:42 -07:00
|
|
|
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
|
build: add build comments to core packages
The go/build package already recognizes
system-specific file names like
mycode_darwin.go
mycode_darwin_386.go
mycode_386.s
However, it is also common to write files that
apply to multiple architectures, so a recent CL added
to go/build the ability to process comments
listing a set of conditions for building. For example:
// +build darwin freebsd openbsd/386
says that this file should be compiled only on
OS X, FreeBSD, or 32-bit x86 OpenBSD systems.
These conventions are not yet documented
(hence this long CL description).
This CL adds build comments to the multi-system
files in the core library, a step toward making it
possible to use go/build to build them.
With this change go/build can handle crypto/rand,
exec, net, path/filepath, os/user, and time.
os and syscall need additional adjustments.
R=golang-dev, r, gri, r, gustavo
CC=golang-dev
https://golang.org/cl/5011046
2011-09-15 14:48:57 -06:00
|
|
|
|
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
|
|
|
// Internet protocol family sockets for POSIX
|
|
|
|
|
2011-08-17 11:28:29 -06:00
|
|
|
package net
|
|
|
|
|
2012-11-08 09:35:16 -07:00
|
|
|
import (
|
2015-05-13 19:18:10 -06:00
|
|
|
"runtime"
|
2012-11-08 09:35:16 -07:00
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
2011-08-17 11:28:29 -06:00
|
|
|
|
2015-05-13 19:18:10 -06:00
|
|
|
// BUG(rsc,mikio): On DragonFly BSD and OpenBSD, listening on the
|
|
|
|
// "tcp" and "udp" networks does not listen for both IPv4 and IPv6
|
|
|
|
// connections. This is due to the fact that IPv4 traffic will not be
|
|
|
|
// routed to an IPv6 socket - two separate sockets are required if
|
|
|
|
// both address families are to be supported.
|
|
|
|
// See inet6(4) for details.
|
|
|
|
|
2013-08-02 21:17:01 -06:00
|
|
|
func probeIPv4Stack() bool {
|
net: add socket system call hooks for testing
This change adds socket system call hooks to existing test cases for
simulating a bit complicated network conditions to help making timeout
and dual IP stack test cases work more properly in followup changes.
Also test cases print debugging information in non-short mode like the
following:
Leaked goroutines:
net.TestWriteTimeout.func2(0xc20802a5a0, 0xc20801d000, 0x1000, 0x1000, 0xc2081d2ae0)
/go/src/net/timeout_test.go:170 +0x98
created by net.TestWriteTimeout
/go/src/net/timeout_test.go:173 +0x745
net.runDatagramPacketConnServer(0xc2080730e0, 0x2bd270, 0x3, 0x2c1770, 0xb, 0xc2081d2ba0, 0xc2081d2c00)
/go/src/net/server_test.go:398 +0x667
created by net.TestTimeoutUDP
/go/src/net/timeout_test.go:247 +0xc9
(snip)
Leaked sockets:
3: {Cookie:615726511685632 Err:<nil> SocketErr:0}
5: {Cookie:7934075906097152 Err:<nil> SocketErr:0}
Socket statistical information:
{Family:1 Type:805306370 Protocol:0 Opened:17 Accepted:0 Connected:5 Closed:17}
{Family:2 Type:805306369 Protocol:0 Opened:450 Accepted:234 Connected:279 Closed:636}
{Family:1 Type:805306369 Protocol:0 Opened:11 Accepted:5 Connected:5 Closed:16}
{Family:28 Type:805306369 Protocol:0 Opened:95 Accepted:22 Connected:16 Closed:116}
{Family:2 Type:805306370 Protocol:0 Opened:84 Accepted:0 Connected:34 Closed:83}
{Family:28 Type:805306370 Protocol:0 Opened:52 Accepted:0 Connected:4 Closed:52}
Change-Id: I0e84be59a0699bc31245c78e2249423459b8cdda
Reviewed-on: https://go-review.googlesource.com/6390
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-28 20:27:01 -07:00
|
|
|
s, err := socketFunc(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
|
2013-08-02 21:17:01 -06:00
|
|
|
switch err {
|
|
|
|
case syscall.EAFNOSUPPORT, syscall.EPROTONOSUPPORT:
|
|
|
|
return false
|
|
|
|
case nil:
|
net: add socket system call hooks for testing
This change adds socket system call hooks to existing test cases for
simulating a bit complicated network conditions to help making timeout
and dual IP stack test cases work more properly in followup changes.
Also test cases print debugging information in non-short mode like the
following:
Leaked goroutines:
net.TestWriteTimeout.func2(0xc20802a5a0, 0xc20801d000, 0x1000, 0x1000, 0xc2081d2ae0)
/go/src/net/timeout_test.go:170 +0x98
created by net.TestWriteTimeout
/go/src/net/timeout_test.go:173 +0x745
net.runDatagramPacketConnServer(0xc2080730e0, 0x2bd270, 0x3, 0x2c1770, 0xb, 0xc2081d2ba0, 0xc2081d2c00)
/go/src/net/server_test.go:398 +0x667
created by net.TestTimeoutUDP
/go/src/net/timeout_test.go:247 +0xc9
(snip)
Leaked sockets:
3: {Cookie:615726511685632 Err:<nil> SocketErr:0}
5: {Cookie:7934075906097152 Err:<nil> SocketErr:0}
Socket statistical information:
{Family:1 Type:805306370 Protocol:0 Opened:17 Accepted:0 Connected:5 Closed:17}
{Family:2 Type:805306369 Protocol:0 Opened:450 Accepted:234 Connected:279 Closed:636}
{Family:1 Type:805306369 Protocol:0 Opened:11 Accepted:5 Connected:5 Closed:16}
{Family:28 Type:805306369 Protocol:0 Opened:95 Accepted:22 Connected:16 Closed:116}
{Family:2 Type:805306370 Protocol:0 Opened:84 Accepted:0 Connected:34 Closed:83}
{Family:28 Type:805306370 Protocol:0 Opened:52 Accepted:0 Connected:4 Closed:52}
Change-Id: I0e84be59a0699bc31245c78e2249423459b8cdda
Reviewed-on: https://go-review.googlesource.com/6390
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-28 20:27:01 -07:00
|
|
|
closeFunc(s)
|
2013-08-02 21:17:01 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2011-08-17 11:28:29 -06:00
|
|
|
// Should we try to use the IPv4 socket interface if we're
|
|
|
|
// only dealing with IPv4 sockets? As long as the host system
|
|
|
|
// understands IPv6, it's okay to pass IPv4 addresses to the IPv6
|
|
|
|
// interface. That simplifies our code and is most general.
|
|
|
|
// Unfortunately, we need to run on kernels built without IPv6
|
|
|
|
// support too. So probe the kernel to figure it out.
|
|
|
|
//
|
|
|
|
// probeIPv6Stack probes both basic IPv6 capability and IPv6 IPv4-
|
|
|
|
// mapping capability which is controlled by IPV6_V6ONLY socket
|
|
|
|
// option and/or kernel state "net.inet6.ip6.v6only".
|
|
|
|
// It returns two boolean values. If the first boolean value is
|
|
|
|
// true, kernel supports basic IPv6 functionality. If the second
|
|
|
|
// boolean value is true, kernel supports IPv6 IPv4-mapping.
|
|
|
|
func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
|
|
|
|
var probes = []struct {
|
2013-07-25 04:29:20 -06:00
|
|
|
laddr TCPAddr
|
2014-03-27 22:27:51 -06:00
|
|
|
value int
|
2011-08-17 11:28:29 -06:00
|
|
|
}{
|
|
|
|
// IPv6 communication capability
|
2014-03-27 22:27:51 -06:00
|
|
|
{laddr: TCPAddr{IP: ParseIP("::1")}, value: 1},
|
2011-08-17 11:28:29 -06:00
|
|
|
// IPv6 IPv4-mapped address communication capability
|
2014-03-27 22:27:51 -06:00
|
|
|
{laddr: TCPAddr{IP: IPv4(127, 0, 0, 1)}, value: 0},
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2015-05-13 19:18:10 -06:00
|
|
|
var supps [2]bool
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "dragonfly", "openbsd":
|
|
|
|
// Some released versions of DragonFly BSD pretend to
|
|
|
|
// accept IPV6_V6ONLY=0 successfully, but the state
|
|
|
|
// still stays IPV6_V6ONLY=1. Eventually DragonFly BSD
|
|
|
|
// stops preteding, but the transition period would
|
|
|
|
// cause unpredictable behavior and we need to avoid
|
|
|
|
// it.
|
|
|
|
//
|
|
|
|
// OpenBSD also doesn't support IPV6_V6ONLY=0 but it
|
|
|
|
// never pretends to accept IPV6_V6OLY=0. It always
|
|
|
|
// returns an error and we don't need to probe the
|
|
|
|
// capability.
|
|
|
|
probes = probes[:1]
|
|
|
|
}
|
2011-08-17 11:28:29 -06:00
|
|
|
|
|
|
|
for i := range probes {
|
net: add socket system call hooks for testing
This change adds socket system call hooks to existing test cases for
simulating a bit complicated network conditions to help making timeout
and dual IP stack test cases work more properly in followup changes.
Also test cases print debugging information in non-short mode like the
following:
Leaked goroutines:
net.TestWriteTimeout.func2(0xc20802a5a0, 0xc20801d000, 0x1000, 0x1000, 0xc2081d2ae0)
/go/src/net/timeout_test.go:170 +0x98
created by net.TestWriteTimeout
/go/src/net/timeout_test.go:173 +0x745
net.runDatagramPacketConnServer(0xc2080730e0, 0x2bd270, 0x3, 0x2c1770, 0xb, 0xc2081d2ba0, 0xc2081d2c00)
/go/src/net/server_test.go:398 +0x667
created by net.TestTimeoutUDP
/go/src/net/timeout_test.go:247 +0xc9
(snip)
Leaked sockets:
3: {Cookie:615726511685632 Err:<nil> SocketErr:0}
5: {Cookie:7934075906097152 Err:<nil> SocketErr:0}
Socket statistical information:
{Family:1 Type:805306370 Protocol:0 Opened:17 Accepted:0 Connected:5 Closed:17}
{Family:2 Type:805306369 Protocol:0 Opened:450 Accepted:234 Connected:279 Closed:636}
{Family:1 Type:805306369 Protocol:0 Opened:11 Accepted:5 Connected:5 Closed:16}
{Family:28 Type:805306369 Protocol:0 Opened:95 Accepted:22 Connected:16 Closed:116}
{Family:2 Type:805306370 Protocol:0 Opened:84 Accepted:0 Connected:34 Closed:83}
{Family:28 Type:805306370 Protocol:0 Opened:52 Accepted:0 Connected:4 Closed:52}
Change-Id: I0e84be59a0699bc31245c78e2249423459b8cdda
Reviewed-on: https://go-review.googlesource.com/6390
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-28 20:27:01 -07:00
|
|
|
s, err := socketFunc(syscall.AF_INET6, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
|
2011-11-13 20:44:52 -07:00
|
|
|
if err != nil {
|
2011-08-17 11:28:29 -06:00
|
|
|
continue
|
|
|
|
}
|
net: add socket system call hooks for testing
This change adds socket system call hooks to existing test cases for
simulating a bit complicated network conditions to help making timeout
and dual IP stack test cases work more properly in followup changes.
Also test cases print debugging information in non-short mode like the
following:
Leaked goroutines:
net.TestWriteTimeout.func2(0xc20802a5a0, 0xc20801d000, 0x1000, 0x1000, 0xc2081d2ae0)
/go/src/net/timeout_test.go:170 +0x98
created by net.TestWriteTimeout
/go/src/net/timeout_test.go:173 +0x745
net.runDatagramPacketConnServer(0xc2080730e0, 0x2bd270, 0x3, 0x2c1770, 0xb, 0xc2081d2ba0, 0xc2081d2c00)
/go/src/net/server_test.go:398 +0x667
created by net.TestTimeoutUDP
/go/src/net/timeout_test.go:247 +0xc9
(snip)
Leaked sockets:
3: {Cookie:615726511685632 Err:<nil> SocketErr:0}
5: {Cookie:7934075906097152 Err:<nil> SocketErr:0}
Socket statistical information:
{Family:1 Type:805306370 Protocol:0 Opened:17 Accepted:0 Connected:5 Closed:17}
{Family:2 Type:805306369 Protocol:0 Opened:450 Accepted:234 Connected:279 Closed:636}
{Family:1 Type:805306369 Protocol:0 Opened:11 Accepted:5 Connected:5 Closed:16}
{Family:28 Type:805306369 Protocol:0 Opened:95 Accepted:22 Connected:16 Closed:116}
{Family:2 Type:805306370 Protocol:0 Opened:84 Accepted:0 Connected:34 Closed:83}
{Family:28 Type:805306370 Protocol:0 Opened:52 Accepted:0 Connected:4 Closed:52}
Change-Id: I0e84be59a0699bc31245c78e2249423459b8cdda
Reviewed-on: https://go-review.googlesource.com/6390
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-28 20:27:01 -07:00
|
|
|
defer closeFunc(s)
|
2014-03-27 22:27:51 -06:00
|
|
|
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, probes[i].value)
|
2013-07-25 04:29:20 -06:00
|
|
|
sa, err := probes[i].laddr.sockaddr(syscall.AF_INET6)
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2013-07-25 04:29:20 -06:00
|
|
|
if err := syscall.Bind(s, sa); err != nil {
|
2011-08-17 11:28:29 -06:00
|
|
|
continue
|
|
|
|
}
|
2015-05-13 19:18:10 -06:00
|
|
|
supps[i] = true
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
2015-05-13 19:18:10 -06:00
|
|
|
return supps[0], supps[1]
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// favoriteAddrFamily returns the appropriate address family to
|
2012-02-14 09:59:18 -07:00
|
|
|
// the given net, laddr, raddr and mode. At first it figures
|
2011-08-17 11:28:29 -06:00
|
|
|
// address family out from the net. If mode indicates "listen"
|
2012-03-05 08:13:10 -07:00
|
|
|
// and laddr is a wildcard, it assumes that the user wants to
|
|
|
|
// make a passive connection with a wildcard address family, both
|
|
|
|
// AF_INET and AF_INET6, and a wildcard address like following:
|
|
|
|
//
|
|
|
|
// 1. A wild-wild listen, "tcp" + ""
|
|
|
|
// If the platform supports both IPv6 and IPv6 IPv4-mapping
|
|
|
|
// capabilities, we assume that the user want to listen on
|
|
|
|
// both IPv4 and IPv6 wildcard address over an AF_INET6
|
|
|
|
// socket with IPV6_V6ONLY=0. Otherwise we prefer an IPv4
|
|
|
|
// wildcard address listen over an AF_INET socket.
|
|
|
|
//
|
|
|
|
// 2. A wild-ipv4wild listen, "tcp" + "0.0.0.0"
|
|
|
|
// Same as 1.
|
|
|
|
//
|
|
|
|
// 3. A wild-ipv6wild listen, "tcp" + "[::]"
|
|
|
|
// Almost same as 1 but we prefer an IPv6 wildcard address
|
|
|
|
// listen over an AF_INET6 socket with IPV6_V6ONLY=0 when
|
|
|
|
// the platform supports IPv6 capability but not IPv6 IPv4-
|
|
|
|
// mapping capability.
|
|
|
|
//
|
|
|
|
// 4. A ipv4-ipv4wild listen, "tcp4" + "" or "0.0.0.0"
|
|
|
|
// We use an IPv4 (AF_INET) wildcard address listen.
|
|
|
|
//
|
|
|
|
// 5. A ipv6-ipv6wild listen, "tcp6" + "" or "[::]"
|
|
|
|
// We use an IPv6 (AF_INET6, IPV6_V6ONLY=1) wildcard address
|
|
|
|
// listen.
|
|
|
|
//
|
|
|
|
// Otherwise guess: if the addresses are IPv4 then returns AF_INET,
|
|
|
|
// or else returns AF_INET6. It also returns a boolean value what
|
|
|
|
// designates IPV6_V6ONLY option.
|
|
|
|
//
|
|
|
|
// Note that OpenBSD allows neither "net.inet6.ip6.v6only=1" change
|
|
|
|
// nor IPPROTO_IPV6 level IPV6_V6ONLY socket option setting.
|
|
|
|
func favoriteAddrFamily(net string, laddr, raddr sockaddr, mode string) (family int, ipv6only bool) {
|
2011-08-17 11:28:29 -06:00
|
|
|
switch net[len(net)-1] {
|
|
|
|
case '4':
|
2012-03-05 08:13:10 -07:00
|
|
|
return syscall.AF_INET, false
|
2011-08-17 11:28:29 -06:00
|
|
|
case '6':
|
2012-03-05 08:13:10 -07:00
|
|
|
return syscall.AF_INET6, true
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
2012-04-24 21:29:14 -06:00
|
|
|
if mode == "listen" && (laddr == nil || laddr.isWildcard()) {
|
2012-03-05 08:13:10 -07:00
|
|
|
if supportsIPv4map {
|
|
|
|
return syscall.AF_INET6, false
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2012-04-24 21:29:14 -06:00
|
|
|
if laddr == nil {
|
|
|
|
return syscall.AF_INET, false
|
|
|
|
}
|
2012-03-05 08:13:10 -07:00
|
|
|
return laddr.family(), false
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (laddr == nil || laddr.family() == syscall.AF_INET) &&
|
|
|
|
(raddr == nil || raddr.family() == syscall.AF_INET) {
|
2012-03-05 08:13:10 -07:00
|
|
|
return syscall.AF_INET, false
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2012-03-05 08:13:10 -07:00
|
|
|
return syscall.AF_INET6, false
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
2012-03-05 08:13:10 -07:00
|
|
|
// Internet sockets (TCP, UDP, IP)
|
2011-08-17 11:28:29 -06:00
|
|
|
|
2014-08-04 15:10:46 -06:00
|
|
|
func internetSocket(net string, laddr, raddr sockaddr, deadline time.Time, sotype, proto int, mode string) (fd *netFD, err error) {
|
2012-03-05 08:13:10 -07:00
|
|
|
family, ipv6only := favoriteAddrFamily(net, laddr, raddr, mode)
|
2014-08-04 15:10:46 -06:00
|
|
|
return socket(net, family, sotype, proto, ipv6only, laddr, raddr, deadline)
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
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
|
|
|
func ipToSockaddr(family int, ip IP, port int, zone string) (syscall.Sockaddr, error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
switch family {
|
|
|
|
case syscall.AF_INET:
|
|
|
|
if len(ip) == 0 {
|
|
|
|
ip = IPv4zero
|
|
|
|
}
|
|
|
|
if ip = ip.To4(); ip == nil {
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return nil, &AddrError{Err: "non-IPv4 address", Addr: ip.String()}
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
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
|
|
|
sa := new(syscall.SockaddrInet4)
|
2011-08-17 11:28:29 -06:00
|
|
|
for i := 0; i < IPv4len; i++ {
|
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
|
|
|
sa.Addr[i] = ip[i]
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
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
|
|
|
sa.Port = port
|
|
|
|
return sa, nil
|
2011-08-17 11:28:29 -06:00
|
|
|
case syscall.AF_INET6:
|
|
|
|
if len(ip) == 0 {
|
|
|
|
ip = IPv6zero
|
|
|
|
}
|
|
|
|
// IPv4 callers use 0.0.0.0 to mean "announce on any available address".
|
|
|
|
// In IPv6 mode, Linux treats that as meaning "announce on 0.0.0.0",
|
2012-03-05 08:13:10 -07:00
|
|
|
// which it refuses to do. Rewrite to the IPv6 unspecified address.
|
2011-08-17 11:28:29 -06:00
|
|
|
if ip.Equal(IPv4zero) {
|
|
|
|
ip = IPv6zero
|
|
|
|
}
|
|
|
|
if ip = ip.To16(); ip == nil {
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return nil, &AddrError{Err: "non-IPv6 address", Addr: ip.String()}
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
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
|
|
|
sa := new(syscall.SockaddrInet6)
|
2011-08-17 11:28:29 -06:00
|
|
|
for i := 0; i < IPv6len; i++ {
|
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
|
|
|
sa.Addr[i] = ip[i]
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
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
|
|
|
sa.Port = port
|
|
|
|
sa.ZoneId = uint32(zoneToInt(zone))
|
|
|
|
return sa, nil
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return nil, &AddrError{Err: "invalid address family", Addr: ip.String()}
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|