Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: Conn cannot setsockopt before dial #6966

Closed
gopherbot opened this issue Dec 16, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@gopherbot
Copy link

commented Dec 16, 2013

by cfanfrank:

I want to use setsockopt do SO_BINDTODEVICE such things that MUST before connect() or
listen().

I cannot find any options in DialTCP.
@mikioh

This comment has been minimized.

Copy link
Contributor

commented Dec 17, 2013

Comment 1:

You can make your own platform-dependent socket creation routine like the following:
import (
        "syscall"
        "net"
)
s, err := syscall.Socket(...)
if err !- nil {
        // error handling
}
if err := syscall.Bind(s, ...); err !- nil {
        // error handling
}
if err := syscall.Connect(...); err !- nil {
        // error handling
}
c, err := net.FileConn(s)
if err !- nil {
        // error handling
}

Status changed to Retracted.

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Dec 17, 2013

Comment 2:

/amend/
1) Please don`t forget to call syscall.SetsockoptInt or other before syscall.Bind
http://golang.org/pkg/syscall/#SetsockoptInt
2) net.FileConn should take *os.File, so f := os.NewFile(s, "name"); c, err :=
net.FileConn(f)
http://golang.org/pkg/os/#NewFile
3) Please don't forget to close f after net.FileConn
http://golang.org/pkg/net/#FileConn

@gopherbot gopherbot added the retracted label Dec 17, 2013

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.