diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-11-11 23:26:44 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-11-11 23:26:44 +0100 |
commit | 566269275ed97812ec909b10ec77c7c037d9e2ea (patch) | |
tree | a5cf35234f15728dee85918088502ad5653a9513 /src/conn_linux.go | |
parent | 892276aa64ca9b14d2e96186b83145ab2f5ce25a (diff) | |
download | wireguard-go-566269275ed97812ec909b10ec77c7c037d9e2ea.tar.gz wireguard-go-566269275ed97812ec909b10ec77c7c037d9e2ea.zip |
Fixed blocking reader on closed socket
Diffstat (limited to 'src/conn_linux.go')
-rw-r--r-- | src/conn_linux.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/conn_linux.go b/src/conn_linux.go index 05f9347..383ff7e 100644 --- a/src/conn_linux.go +++ b/src/conn_linux.go @@ -84,9 +84,15 @@ func (bind NativeBind) SetMark(value uint32) error { ) } +func closeUnblock(fd int) error { + // shutdown to unblock readers + unix.Shutdown(fd, unix.SHUT_RD) + return unix.Close(fd) +} + func (bind NativeBind) Close() error { - err1 := unix.Close(bind.sock6) - err2 := unix.Close(bind.sock4) + err1 := closeUnblock(bind.sock6) + err2 := closeUnblock(bind.sock4) if err1 != nil { return err1 } @@ -125,13 +131,13 @@ func sockaddrToString(addr unix.RawSockaddrInet6) string { switch addr.Family { case unix.AF_INET6: - udpAddr.Port = int(addr.Port) + udpAddr.Port = int(ntohs(addr.Port)) udpAddr.IP = addr.Addr[:] return udpAddr.String() case unix.AF_INET: ptr := (*unix.RawSockaddrInet4)(unsafe.Pointer(&addr)) - udpAddr.Port = int(ptr.Port) + udpAddr.Port = int(ntohs(ptr.Port)) udpAddr.IP = net.IPv4( ptr.Addr[0], ptr.Addr[1], |