MCPcopy Index your code
hub / github.com/subtrace/subtrace / newTempBindSocket

Function newTempBindSocket

cmd/run/socket/socket.go:837–854  ·  view source on GitHub ↗

newTempBindSocket creates a temporary socket to use as a parking spot for an address bind. The returned socket has SO_REUSEADDR and SO_REUSEPORT set to 1.

(domain int)

Source from the content-addressed store, hash-verified

835// newTempBindSocket creates a temporary socket to use as a parking spot for an
836// address bind. The returned socket has SO_REUSEADDR and SO_REUSEPORT set to 1.
837func newTempBindSocket(domain int) (*fd.FD, error) {
838 ret, err := unix.Socket(domain, unix.SOCK_STREAM, unix.IPPROTO_TCP)
839 if err != nil {
840 return nil, fmt.Errorf("create temp bind socket: %w", err)
841 }
842 fd := fd.NewFD(ret)
843 defer fd.DecRef()
844
845 if err := unix.SetsockoptInt(fd.FD(), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {
846 unix.Close(fd.FD())
847 return nil, fmt.Errorf("set SO_REUSEADDR: %w", err)
848 }
849 if err := unix.SetsockoptInt(fd.FD(), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
850 unix.Close(fd.FD())
851 return nil, fmt.Errorf("set SO_REUSEPORT: %w", err)
852 }
853 return fd, nil
854}
855
856func getEphemeralLoopbackAddr(domain int) ([]byte, error) {
857 arr, err := net.Interfaces()

Callers 2

ConnectMethod · 0.85
BindMethod · 0.85

Calls 3

DecRefMethod · 0.95
FDMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected