不知道为什么我得到错误代码10022在我的C#嗅探器设置套接字选项时(参数无效) [英] Don't know why I'm getting Error Code 10022 (Invalid Argument) when setting socket options in my C# sniffer

查看:662
本文介绍了不知道为什么我得到错误代码10022在我的C#嗅探器设置套接字选项时(参数无效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习上的C#.NET 4插槽的发展写数据包嗅探器作为一个练习。我的目标是嗅出出入我的电脑的IP数据包。



我的问题是我收到的错误代码10022,无效的参数,我呼吁SetSocketOption 。我看不出在那里我有一个无效的参数。我有我的计算机上的一些管理PRIVS,但也许我没有足够的。这是我的工作电脑和IT部门是相当严格的。随着中说,如果这是一个权限问题我希望一个不同的异常。



我不知道我的下一个步骤应该是调试这个问题。 ?人有一个想法



下面的代码如下:

 公开嗅探器()
{

{
插座=新的Socket(
AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.IP);

ip地址[] = ipAddresses Dns.GetHostEntry(
Dns.GetHostName())AddressList中。

socket.Bind(新IPEndPoint(ipAddresses [0],0));

socket.SetSocketOption(
SocketOptionLevel.IP,SocketOptionName.HeaderIncluded,真正的);

字节[] inputData =新的字节[4] {1,0,0,0};
字节[] = outValue新的字节[4];

socket.IOControl(IOControlCode.ReceiveAll,inputData,outValue);
}
赶上(SocketException前)
{
串的ErrorMessage = ex.Message;
}
}


解决方案

这对我来说是非常非常大的问题,但我解决了这个问题设置应用程序池大小值。在PostgreSQL设置为池=假; 就可以解决这个


I'm writing a packet sniffer as an exercise in learning .Net 4 socket development on in C#. My goal is to sniff IP packets coming in and out out my computer.

My problem is that I'm getting error code 10022, invalid argument, on my call to SetSocketOption. I don't see where I have an invalid argument. I have some admin privs on my computer, but perhaps I don't have enough. It's my work computer and the IT department is pretty strict. With that said, if it was a permissions problem I would expect a different exception.

I'm not sure what my next step should be to debug this problem. Anyone have an idea?

Here's the code follows:

public Sniffer()
{
    try
    {
        socket = new Socket(
            AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

        IPAddress[] ipAddresses = Dns.GetHostEntry(
            Dns.GetHostName()).AddressList;

        socket.Bind(new IPEndPoint(ipAddresses[0], 0));

        socket.SetSocketOption(
            SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);

        byte[] inputData = new byte[4] { 1, 0, 0, 0 };
        byte[] outValue = new byte[4];

        socket.IOControl(IOControlCode.ReceiveAll, inputData, outValue);
    }
    catch (SocketException ex)
    {
        string ErrorMessage = ex.Message;
    }
}

解决方案

This is very very big problem for me but i solved this issue with set the application pool size value. In postgresql set to Pooling=false; can you solve this.

这篇关于不知道为什么我得到错误代码10022在我的C#嗅探器设置套接字选项时(参数无效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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