简体   繁体   English

Socket.bind到所有ips-提供了无效的参数

[英]Socket.bind to all ips - An invalid argument was supplied

I want to bind the socket to all the IP addresses available on the machine using: 我想使用以下方法将套接字绑定到计算机上所有可用的IP地址:

  mainSocket.Bind(new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0)); //or IPAddress.Any

but I get an An invalid argument was supplied on 但我收到一个An invalid argument was supplied

 mainSocket.IOControl(IOControlCode.ReceiveAll, byTrue, byOut);

Instead, when I specify the IP, it works just fine. 相反,当我指定IP时,它就可以正常工作。

在此处输入图片说明

Ok maybe that's impossible to achieve. 好吧,也许这是不可能实现的。 But how about detecting which internet interface is being used to connect to internet and getting it's ip? 但是,如何检测使用哪个Internet接口连接到Internet并获取其IP? (assuming user is behind NAT / router) (假设用户位于NAT /路由器之后)

I think it's not possible. 我认为这是不可能的。 Operation with sockets has limitations according to this document TCP/IP Raw Sockets 根据本文档,使用套接字进行操作有局限性TCP / IP原始套接字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM