在特定的网络适配器上执行connect() [英] perform connect() on specific network adapter

查看:81
本文介绍了在特定的网络适配器上执行connect()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Winsock2编程.我在系统中有两个网络适配器,一个用于本地连接(LAN),一个用于外部连接(PPPOE).当我执行connect()调用以连接到本地地址时,它使用PPPOE适配器而不是LAN.我知道我可以使用指标进行调整,但是我不能仅仅使用一些硬代码来强制使用LAN适配器吗?预先感谢!

I'm programming with Winsock2. I have two network adapters in system, one for local connections (LAN), one for outer connections (PPPOE). When I perform a connect() call to connect to local address, it uses PPPOE adapter instead of LAN. I know I could tweak this using metrics, but can't I just use some hard-code to forcibly use LAN adapter? Thanks in advance!

推荐答案

在连接()之前,需要将()绑定到LAN适配器的IP地址.只需指定IP地址,并保持端口开放(即0),以便系统仍可以选择一个.

Before you connect(), you need to bind() to the IP address of the LAN adapter. Just specify the IP address, and leave the port open (i.e. 0), so that the system can still chose one.

这篇关于在特定的网络适配器上执行connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆