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: cannot bind network card to send data on macos #32722

Closed
weiyixuan opened this issue Jun 21, 2019 · 2 comments
Closed

net: cannot bind network card to send data on macos #32722

weiyixuan opened this issue Jun 21, 2019 · 2 comments

Comments

@weiyixuan
Copy link

@weiyixuan weiyixuan commented Jun 21, 2019

go1.11.0
macOS Mojave

I added two default routes that direct all traffic to a single virtual network card. Then I want to send the test program data directly from the physical network card. I first used bind(),but an error occured while establishing the connection: [connect: no route to host]

On Windows and Linux, I can use the bind() function to bind network cards to send data. Is there any way to do it on a MAC?

var netAddr net.Addr

netAddr = &net.TCPAddr{}
netAddr.(*net.TCPAddr).IP = net.ParseIP("xxx.xxx.xxx.xxx")
dialer := net.Dialer{LocalAddr:netAddr}
conn, err := dialer.Dial("tcp", "yyy.yyy.yyy.yyy:mm")
if err != nil {
	log.Println(err)
	return
}
defer conn.Close()
log.Println("conn successful")
@ianlancetaylor ianlancetaylor changed the title cannot bind network card to send data on macos net: cannot bind network card to send data on macos Jun 21, 2019
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 21, 2019

CC @mikioh

@dmitshur dmitshur added this to the Go1.14 milestone Jun 23, 2019
@weiyixuan

This comment has been minimized.

Copy link
Author

@weiyixuan weiyixuan commented Jun 25, 2019

Is there a temporary solution?

@weiyixuan weiyixuan closed this Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.