Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-sockaddr
Commits
813e7b44
Commit
813e7b44
authored
Nov 06, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AF_ types
parent
9d764b20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
net/net.go
net/net.go
+36
-0
No files found.
net/net.go
View file @
813e7b44
...
...
@@ -6,6 +6,42 @@ import (
"syscall"
)
// NetAddrAF returns the syscall AF_* type for a given net.Addr
// returns syscall.AF_UNSPEC if unknown
func
NetAddrAF
(
addr
net
.
Addr
)
int
{
switch
addr
:=
addr
.
(
type
)
{
default
:
return
syscall
.
AF_UNSPEC
case
*
net
.
IPAddr
:
return
IPAF
(
addr
.
IP
)
case
*
net
.
TCPAddr
:
return
IPAF
(
addr
.
IP
)
case
*
net
.
UDPAddr
:
return
IPAF
(
addr
.
IP
)
case
*
net
.
UnixAddr
:
return
syscall
.
AF_UNIX
}
}
// IPAF returns the syscall AF_* type for a given IP address
// returns syscall.AF_UNSPEC if unknown
func
IPAF
(
ip
net
.
IP
)
int
{
switch
{
default
:
return
syscall
.
AF_UNSPEC
case
ip
.
To4
()
!=
nil
:
return
syscall
.
AF_INET
case
ip
.
To16
()
!=
nil
:
return
syscall
.
AF_INET6
}
}
// NetAddrIPPROTO returns the syscall IPPROTO_* type for a given net.Addr
// returns -1 if protocol unknown
func
NetAddrIPPROTO
(
addr
net
.
Addr
)
int
{
...
...
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