Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
33907d13
Commit
33907d13
authored
Dec 19, 2008
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow Listen on ":9999" as an alias for "0.0.0.0:9999"
R=r DELTA=21 (12 added, 0 deleted, 9 changed) OCL=21653 CL=21653
parent
4f3506b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
9 deletions
+21
-9
src/lib/net/net.go
src/lib/net/net.go
+20
-9
src/lib/net/tcpserver_test.go
src/lib/net/tcpserver_test.go
+1
-0
No files found.
src/lib/net/net.go
View file @
33907d13
...
...
@@ -41,7 +41,7 @@ func SplitHostPort(hostport string) (host, port string, err *os.Error) {
port
=
hostport
[
i
+
1
:
len
(
hostport
)];
// Can put brackets around host ...
if
host
[
0
]
==
'['
&&
host
[
len
(
host
)
-
1
]
==
']'
{
if
len
(
host
)
>
0
&&
host
[
0
]
==
'['
&&
host
[
len
(
host
)
-
1
]
==
']'
{
host
=
host
[
1
:
len
(
host
)
-
1
]
}
else
{
// ... but if there are no brackets, no colons.
...
...
@@ -65,15 +65,26 @@ func JoinHostPort(host, port string) string {
// Convert "host:port" into IP address and port.
// For now, host and port must be numeric literals.
// Eventually, we'll have name resolution.
func
HostPortToIP
(
net
string
,
hostport
string
)
(
ip
[]
byte
,
iport
int
,
err
*
os
.
Error
)
{
func
HostPortToIP
(
net
,
hostport
,
mode
string
)
(
ip
[]
byte
,
iport
int
,
err
*
os
.
Error
)
{
var
host
,
port
string
;
host
,
port
,
err
=
SplitHostPort
(
hostport
);
if
err
!=
nil
{
return
nil
,
0
,
err
}
var
addr
[]
byte
;
if
host
==
""
{
if
mode
==
"listen"
{
addr
=
IPnoaddr
;
// wildcard - listen to all
}
else
{
return
nil
,
0
,
MissingAddress
;
}
}
// Try as an IP address.
addr
:=
ParseIP
(
host
);
if
addr
==
nil
{
addr
=
ParseIP
(
host
);
}
if
addr
==
nil
{
// Not an IP address. Try as a DNS name.
hostname
,
addrs
,
err
:=
LookupHost
(
host
);
...
...
@@ -279,20 +290,20 @@ func (c *ConnBase) SetLinger(sec int) *os.Error {
// PreferIPv4 here should fall back to the IPv4 socket interface when possible.
const
PreferIPv4
=
false
func
InternetSocket
(
net
,
laddr
,
raddr
string
,
proto
int64
)
(
fd
*
FD
,
err
*
os
.
Error
)
{
func
InternetSocket
(
net
,
laddr
,
raddr
string
,
proto
int64
,
mode
string
)
(
fd
*
FD
,
err
*
os
.
Error
)
{
// Parse addresses (unless they are empty).
var
lip
,
rip
[]
byte
;
var
lport
,
rport
int
;
var
lerr
,
rerr
*
os
.
Error
;
if
laddr
!=
""
{
lip
,
lport
,
lerr
=
HostPortToIP
(
net
,
laddr
);
lip
,
lport
,
lerr
=
HostPortToIP
(
net
,
laddr
,
mode
);
if
lerr
!=
nil
{
return
nil
,
lerr
}
}
if
raddr
!=
""
{
rip
,
rport
,
rerr
=
HostPortToIP
(
net
,
raddr
);
rip
,
rport
,
rerr
=
HostPortToIP
(
net
,
raddr
,
mode
);
if
rerr
!=
nil
{
return
nil
,
rerr
}
...
...
@@ -370,7 +381,7 @@ export func DialTCP(net, laddr, raddr string) (c *ConnTCP, err *os.Error) {
if
raddr
==
""
{
return
nil
,
MissingAddress
}
fd
,
e
:=
InternetSocket
(
net
,
laddr
,
raddr
,
syscall
.
SOCK_STREAM
);
fd
,
e
:=
InternetSocket
(
net
,
laddr
,
raddr
,
syscall
.
SOCK_STREAM
,
"dial"
);
if
e
!=
nil
{
return
nil
,
e
}
...
...
@@ -397,7 +408,7 @@ export func DialUDP(net, laddr, raddr string) (c *ConnUDP, err *os.Error) {
if
raddr
==
""
{
return
nil
,
MissingAddress
}
fd
,
e
:=
InternetSocket
(
net
,
laddr
,
raddr
,
syscall
.
SOCK_DGRAM
);
fd
,
e
:=
InternetSocket
(
net
,
laddr
,
raddr
,
syscall
.
SOCK_DGRAM
,
"dial"
);
if
e
!=
nil
{
return
nil
,
e
}
...
...
@@ -477,7 +488,7 @@ export type ListenerTCP struct {
}
export
func
ListenTCP
(
net
,
laddr
string
)
(
l
*
ListenerTCP
,
err
*
os
.
Error
)
{
fd
,
e
:=
InternetSocket
(
net
,
laddr
,
""
,
syscall
.
SOCK_STREAM
);
fd
,
e
:=
InternetSocket
(
net
,
laddr
,
""
,
syscall
.
SOCK_STREAM
,
"listen"
);
if
e
!=
nil
{
return
nil
,
e
}
...
...
src/lib/net/tcpserver_test.go
View file @
33907d13
...
...
@@ -79,6 +79,7 @@ export func TestTcpServer(t *testing.T) {
DoTest
(
t
,
"tcp"
,
"0.0.0.0:9997"
,
"127.0.0.1:9997"
);
DoTest
(
t
,
"tcp"
,
"[::]:9997"
,
"[::ffff:127.0.0.1]:9997"
);
DoTest
(
t
,
"tcp"
,
"[::]:9997"
,
"127.0.0.1:9997"
);
DoTest
(
t
,
"tcp"
,
":9997"
,
"127.0.0.1:9997"
);
DoTest
(
t
,
"tcp"
,
"0.0.0.0:9997"
,
"[::ffff:127.0.0.1]:9997"
);
}
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