【发布时间】:2020-03-26 20:08:00
【问题描述】:
我正在尝试在 linux-arm 平台 (raspberry pi) 上与 net-core 3.0 建立 IPV6 套接字连接。
当我尝试将套接字绑定到本地以太网适配器时,抛出异常 ((22): Invalid argument [fe80::211c:bf90:fbbf:9800]:5400)。
当我在我的 Windows 开发机器上尝试相同的操作(使用不同的链接本地 ip)时,一切正常。 IPV4 套接字连接也可以在我的 Windows 开发机器和目标 linux-arm 平台上进行。
到源代码: 我以microsoft的socket示例为基础,将IPV4改为IPV6地址。 在“Bind”方法之后抛出异常。
这是客户端代码:
//definet the target endpoint
IPAddress ipAddress;
IPAddress.TryParse("fe80::211c:bf90:fbbf:9800", out ipAddress);
IPEndPoint remoteEP = new IPEndPoint(ipAddress, 5400);
// Create a TCP/IP socket.
Socket sender = new Socket(ipAddress.AddressFamily ,SocketType.Stream, ProtocolType.Tcp);
//bind to the local network interface
IPAddress localIp;
IPAddress.TryParse("fe80::833:e68b:32ee:4c39", out localIp);
EndPoint localEndPoint = new IPEndPoint(IPAddress.IPv6Any, 0);
sender.Bind(localEndPoint);
// Connect the socket to the remote endpoint. Catch any errors.
try
{
sender.Connect(remoteEP);
Console.WriteLine("Socket connected to {0}",
sender.RemoteEndPoint.ToString());
【问题讨论】:
-
您在哪里提供区域 ID?链路本地地址需要一个区域 ID 来确定应该使用的接口,因为所有接口都使用相同的链路本地网络。
-
嗯,好点。基本上这是我的第一个 ipv6 工作,所以我对所有设置都不太熟悉(看起来)。那么,我是否必须将本地区域 ID 传递给远程链接本地的地址?为什么这在 Windows 和 linux 平台上有所不同? windows是否有更智能的方式来确定网卡?