2014-07-08 01:16:42 +10:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2014-07-08 18:42:02 +10:00
|
|
|
// Linux implementation for preparing the socket for sessions
|
|
|
|
// Based on http://stackoverflow.com/questions/3062205/setting-the-source-ip-for-a-udp-socket
|
|
|
|
// and http://blog.powerdns.com/2012/10/08/on-binding-datagram-udp-sockets-to-the-any-addresses/
|
2014-07-08 01:16:42 +10:00
|
|
|
func udpSocketOobData(conn *net.UDPConn) (err error) {
|
|
|
|
file, err := conn.File()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:42:02 +10:00
|
|
|
// IPv4 support
|
2014-07-08 01:16:42 +10:00
|
|
|
err = syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IP, syscall.IP_PKTINFO, 1)
|
2014-07-08 07:19:51 +10:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:42:02 +10:00
|
|
|
// IPv6 support
|
2014-07-08 07:19:51 +10:00
|
|
|
err = syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_RECVPKTINFO, 1)
|
2014-07-08 01:16:42 +10:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|