diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-07-12 11:54:15 +0900 |
---|---|---|
committer | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-07-18 15:11:05 +0900 |
commit | c3d98dac4df7d55fc6aceb4558707f252bbbd765 (patch) | |
tree | 795c27dca84473172484c237209f67e60510b63b /server/util.go | |
parent | 178e65f8f113da82f8dfcc56b5fa7682da1bd932 (diff) |
server: Set incoming TTL before accepting connection
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'server/util.go')
-rw-r--r-- | server/util.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/server/util.go b/server/util.go index 92f73504..b122fbdb 100644 --- a/server/util.go +++ b/server/util.go @@ -66,6 +66,31 @@ func decodeAdministrativeCommunication(data []byte) (string, []byte) { return string(data[1 : communicationLen+1]), data[communicationLen+1:] } +func extractFileAndFamilyFromTCPListener(l *net.TCPListener) (*os.File, int, error) { + // Note #1: TCPListener.File() has the unexpected side-effect of putting + // the original socket into blocking mode. See Note #2. + fi, err := l.File() + if err != nil { + return nil, 0, err + } + + // Note #2: Call net.FileListener() to put the original socket back into + // non-blocking mode. + fl, err := net.FileListener(fi) + if err != nil { + fi.Close() + return nil, 0, err + } + fl.Close() + + family := syscall.AF_INET + if strings.Contains(l.Addr().String(), "[") { + family = syscall.AF_INET6 + } + + return fi, family, nil +} + func extractFileAndFamilyFromTCPConn(conn *net.TCPConn) (*os.File, int, error) { // Note #1: TCPConn.File() has the unexpected side-effect of putting // the original socket into blocking mode. See Note #2. |