Move more syscall function into their own impl.
Windows is stupid
This commit is contained in:
parent
907e91be57
commit
e571f699d2
6
udp.go
6
udp.go
|
@ -19,15 +19,13 @@ func (s *sessionUDP) RemoteAddr() net.Addr { return s.raddr }
|
||||||
// setUDPSocketOptions sets the UDP socket options.
|
// setUDPSocketOptions sets the UDP socket options.
|
||||||
// This function is implemented on a per platform basis. See udp_*.go for more details
|
// This function is implemented on a per platform basis. See udp_*.go for more details
|
||||||
func setUDPSocketOptions(conn *net.UDPConn) error {
|
func setUDPSocketOptions(conn *net.UDPConn) error {
|
||||||
file, err := conn.File()
|
sa, err := getUDPSocketName(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sa, err := syscall.Getsockname(int(file.Fd()))
|
|
||||||
switch sa.(type) {
|
switch sa.(type) {
|
||||||
case *syscall.SockaddrInet6:
|
case *syscall.SockaddrInet6:
|
||||||
v6only, err := getUDPSocketOption6Only(conn)
|
v6only, err := getUDPSocketOptions6Only(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
28
udp_linux.go
28
udp_linux.go
|
@ -21,8 +21,10 @@ import (
|
||||||
|
|
||||||
// setUDPSocketOptions4 prepares the v4 socket for sessions.
|
// setUDPSocketOptions4 prepares the v4 socket for sessions.
|
||||||
func setUDPSocketOptions4(conn *net.UDPConn) error {
|
func setUDPSocketOptions4(conn *net.UDPConn) error {
|
||||||
// We got the .File() in NewUDPConn, this this will work.
|
file, err := conn.File()
|
||||||
file, _ := conn.File()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IP, syscall.IP_PKTINFO, 1); err != nil {
|
if err := syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IP, syscall.IP_PKTINFO, 1); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -31,8 +33,10 @@ func setUDPSocketOptions4(conn *net.UDPConn) error {
|
||||||
|
|
||||||
// setUDPSocketOptions6 prepares the v6 socket for sessions.
|
// setUDPSocketOptions6 prepares the v6 socket for sessions.
|
||||||
func setUDPSocketOptions6(conn *net.UDPConn) error {
|
func setUDPSocketOptions6(conn *net.UDPConn) error {
|
||||||
// We got the .File() in NewUDPConn, this this will work.
|
file, err := conn.File()
|
||||||
file, _ := conn.File()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_RECVPKTINFO, 1); err != nil {
|
if err := syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_RECVPKTINFO, 1); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -41,9 +45,11 @@ func setUDPSocketOptions6(conn *net.UDPConn) error {
|
||||||
|
|
||||||
// getUDPSocketOption6Only return true if the socket is v6 only and false when it is v4/v6 combined
|
// getUDPSocketOption6Only return true if the socket is v6 only and false when it is v4/v6 combined
|
||||||
// (dualstack).
|
// (dualstack).
|
||||||
func getUDPSocketOption6Only(conn *net.UDPConn) (bool, error) {
|
func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) {
|
||||||
// We got the .File() in NewUDPConn, this this will work.
|
file, err := conn.File()
|
||||||
file, _ := conn.File()
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
// dual stack. See http://stackoverflow.com/questions/1618240/how-to-support-both-ipv4-and-ipv6-connections
|
// dual stack. See http://stackoverflow.com/questions/1618240/how-to-support-both-ipv4-and-ipv6-connections
|
||||||
v6only, err := syscall.GetsockoptInt(int(file.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY)
|
v6only, err := syscall.GetsockoptInt(int(file.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,3 +57,11 @@ func getUDPSocketOption6Only(conn *net.UDPConn) (bool, error) {
|
||||||
}
|
}
|
||||||
return v6only == 1, nil
|
return v6only == 1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUDPSocketName(conn *net.UDPConn) (syscall.Sockaddr, error) {
|
||||||
|
file, err := conn.File()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return syscall.Getsockname(int(file.Fd()))
|
||||||
|
}
|
||||||
|
|
|
@ -12,7 +12,9 @@ import (
|
||||||
|
|
||||||
// These do nothing. See udp_linux.go for an example of how to implement this.
|
// These do nothing. See udp_linux.go for an example of how to implement this.
|
||||||
|
|
||||||
func setUDPSocketOptions4(conn *net.UDPConn) error { return nil }
|
// We tried to adhire to some kind of naming scheme.
|
||||||
func setUDPSocketOptions6(conn *net.UDPConn) error { return nil }
|
|
||||||
|
|
||||||
func getUDPSocketOption6Only(conn *net.UDPConn) (bool, error) { return false, nil }
|
func setUDPSocketOptions4(conn *net.UDPConn) error { return nil }
|
||||||
|
func setUDPSocketOptions6(conn *net.UDPConn) error { return nil }
|
||||||
|
func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) { return false, nil }
|
||||||
|
func getUDPSocketName(conn *net.UDPConn) (syscal.Sockaddr, error) { return nil, nil }
|
||||||
|
|
Loading…
Reference in New Issue