Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
9b66129f
Commit
9b66129f
authored
Feb 16, 2011
by
Mikio Hara
Committed by
Russ Cox
Feb 16, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: more accurate IPv4-in-IPv6 API test
R=rsc CC=golang-dev
https://golang.org/cl/4172045
parent
df4b22fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
8 deletions
+23
-8
iprawsock.go
src/pkg/net/iprawsock.go
+1
-1
ipsock.go
src/pkg/net/ipsock.go
+22
-7
No files found.
src/pkg/net/iprawsock.go
View file @
9b66129f
...
...
@@ -245,7 +245,7 @@ func hostToIP(host string) (ip IP, err os.Error) {
err
=
err1
goto
Error
}
addr
=
ParseIP
(
addrs
[
0
]
)
addr
=
firstSupportedAddr
(
addrs
)
if
addr
==
nil
{
// should not happen
err
=
&
AddrError
{
"LookupHost returned invalid address"
,
addrs
[
0
]}
...
...
src/pkg/net/ipsock.go
View file @
9b66129f
...
...
@@ -18,19 +18,34 @@ import (
// Unfortunately, we need to run on kernels built without IPv6 support too.
// So probe the kernel to figure it out.
func
kernelSupportsIPv6
()
bool
{
// FreeBSD does not support this sort of interface.
if
syscall
.
OS
==
"freebsd"
{
s
,
err
:=
syscall
.
Socket
(
syscall
.
AF_INET6
,
syscall
.
SOCK_STREAM
,
syscall
.
IPPROTO_TCP
)
if
err
!=
0
{
return
false
}
fd
,
e
:=
syscall
.
Socket
(
syscall
.
AF_INET6
,
syscall
.
SOCK_STREAM
,
syscall
.
IPPROTO_TCP
)
if
fd
>=
0
{
closesocket
(
fd
)
defer
closesocket
(
s
)
la
:=
&
TCPAddr
{
IP
:
IPv4
(
127
,
0
,
0
,
1
)}
sa
,
oserr
:=
la
.
toAddr
()
.
sockaddr
(
syscall
.
AF_INET6
)
if
oserr
!=
nil
{
return
false
}
return
e
==
0
return
syscall
.
Bind
(
s
,
sa
)
==
0
}
var
preferIPv4
=
!
kernelSupportsIPv6
()
func
firstSupportedAddr
(
addrs
[]
string
)
(
addr
IP
)
{
for
_
,
s
:=
range
addrs
{
addr
=
ParseIP
(
s
)
if
!
preferIPv4
||
addr
.
To4
()
!=
nil
{
break
}
addr
=
nil
}
return
addr
}
// TODO(rsc): if syscall.OS == "linux", we're supposd to read
// /proc/sys/net/core/somaxconn,
// to take advantage of kernels that have raised the limit.
...
...
@@ -208,7 +223,7 @@ func hostPortToIP(net, hostport string) (ip IP, iport int, err os.Error) {
err
=
err1
goto
Error
}
addr
=
ParseIP
(
addrs
[
0
]
)
addr
=
firstSupportedAddr
(
addrs
)
if
addr
==
nil
{
// should not happen
err
=
&
AddrError
{
"LookupHost returned invalid address"
,
addrs
[
0
]}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment