Raw Socket 遇到错误 求大神指点啊

Ailn Ailn 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近几天在研究Raw Socket 编程
小弟用vs 2008 c#实现的 socket.IOControl() 报错 提供了无效的参数,台式机用的无线网卡。
代码如下


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace rawsocket
{
class Program
{
static void Main(string[] args)
{
// const int SIO_RCVALL = unchecked((int)0x98000001);//监听所有的数据包
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);//creat a socket
socket.Blocking = false;
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
socket.Bind(new IPEndPoint(IPAddress.Parse("192.168.1.111"),0)); //绑定套接字

//set
try
{
// socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);

byte[] IN = new byte[4]{1,0,0,0};
byte[] OUT = new byte[4];
int ret_code = socket.IOControl(IOControlCode.ReceiveAll, IN, OUT);
Console.Write(Convert.ToString(ret_code)+"\r\n");
ret_code = OUT[0] + OUT[1] + OUT[2] + OUT[3];
Console.Write(Convert.ToString(ret_code)+"\r\n");


}
catch (SocketException e)
{
Console.Write(e.ToString()+"\r\n");
Console.Write(Convert.ToString(e.ErrorCode));
}


while (true)
{ }
}
}
}



运行后报错截图如下


请大神指点
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
Ailn
C# 111,129 成员 642,540 内容