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
15057e47
Commit
15057e47
authored
Nov 06, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SOCK_ and IPPROTO_ conversions
parent
e3ab4df5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
net/net.go
net/net.go
+53
-0
No files found.
net/net.go
View file @
15057e47
...
...
@@ -6,6 +6,59 @@ import (
"syscall"
)
// NetAddrIPPROTO returns the syscall IPPROTO_* type for a given net.Addr
// returns -1 if protocol unknown
func
NetAddrIPPROTO
(
addr
net
.
Addr
)
int
{
switch
addr
:=
addr
.
(
type
)
{
default
:
return
-
1
case
*
net
.
IPAddr
:
switch
{
default
:
return
syscall
.
IPPROTO_IP
case
addr
.
IP
.
To4
()
!=
nil
:
return
syscall
.
IPPROTO_IPV4
case
addr
.
IP
.
To16
()
!=
nil
:
return
syscall
.
IPPROTO_IPV6
}
case
*
net
.
TCPAddr
:
return
syscall
.
IPPROTO_TCP
case
*
net
.
UDPAddr
:
return
syscall
.
IPPROTO_UDP
}
}
// NetAddrSOCK returns the syscall SOCK_* type for a given net.Addr
// returns 0 if type unknown
func
NetAddrSOCK
(
addr
net
.
Addr
)
int
{
switch
addr
:=
addr
.
(
type
)
{
default
:
return
0
case
*
net
.
IPAddr
:
return
syscall
.
SOCK_DGRAM
case
*
net
.
TCPAddr
:
return
syscall
.
SOCK_STREAM
case
*
net
.
UDPAddr
:
return
syscall
.
SOCK_DGRAM
case
*
net
.
UnixAddr
:
switch
addr
.
Net
{
default
:
return
0
case
"unix"
:
return
syscall
.
SOCK_STREAM
case
"unixgram"
:
return
syscall
.
SOCK_DGRAM
case
"unixpacket"
:
return
syscall
.
SOCK_SEQPACKET
}
}
}
// NetAddrToSockaddr converts a net.Addr to a syscall.Sockaddr.
// Returns nil if the input is invalid or conversion is not possible.
func
NetAddrToSockaddr
(
addr
net
.
Addr
)
syscall
.
Sockaddr
{
...
...
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