zrepl/util/tcpsock/tcpsock_freebind_linux.go
Juergen Hoetzel d35e2400b2 transport/{TCP,TLS}: optional IP_FREEBIND / IP_BINDANY bind socketops
Allows to bind to an address even if it is not actually (yet or ever)
configured. Fixes #238

Rationale:
https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/#whatdoesthismeanformeadeveloper
2020-01-04 17:21:48 +01:00

20 lines
372 B
Go

// +build linux
package tcpsock
import (
"syscall"
)
func freeBind(network, address string, c syscall.RawConn) error {
var err, sockerr error
err = c.Control(func(fd uintptr) {
// apparently, this works for both IPv4 and IPv6
sockerr = syscall.SetsockoptInt(int(fd), syscall.SOL_IP, syscall.IP_FREEBIND, 1)
})
if err != nil {
return err
}
return sockerr
}