diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-07-11 10:45:30 +0900 |
---|---|---|
committer | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-07-18 15:11:01 +0900 |
commit | 178e65f8f113da82f8dfcc56b5fa7682da1bd932 (patch) | |
tree | 52b423ccf52b64d14b278fb39d8e6a3e399488b2 /server/util.go | |
parent | eb95f000bf4ab70c2dad7589e58045fbce1addf1 (diff) |
server: Set outgoing TTL before dialing
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'server/util.go')
-rw-r--r-- | server/util.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server/util.go b/server/util.go index 951d712c..92f73504 100644 --- a/server/util.go +++ b/server/util.go @@ -16,7 +16,13 @@ package server import ( + "net" + "os" + "strings" + "syscall" + "github.com/eapache/channels" + "github.com/osrg/gobgp/packet/bgp" ) @@ -59,3 +65,28 @@ func decodeAdministrativeCommunication(data []byte) (string, []byte) { } return string(data[1 : communicationLen+1]), data[communicationLen+1:] } + +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. + fi, err := conn.File() + if err != nil { + return nil, 0, err + } + + // Note #2: Call net.FileConn() to put the original socket back into + // non-blocking mode. + fc, err := net.FileConn(fi) + if err != nil { + fi.Close() + return nil, 0, err + } + fc.Close() + + family := syscall.AF_INET + if strings.Contains(conn.RemoteAddr().String(), "[") { + family = syscall.AF_INET6 + } + + return fi, family, nil +} |