是否有可能使Socket不接收来自某些应用程序的数据包? [英] Is it possible to make Socket don't recieve packets from certain application?

查看:115
本文介绍了是否有可能使Socket不接收来自某些应用程序的数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我制作了从本地ip上所有端口接收tcp数据包的应用程序.就像嗅探器.
但是结果是我也监听"了我自己的应用程序.问题是是否可以将套接字配置为不接收来自我的应用程序的tcp数据包?.

我已经在此处阅读了tcp标头定义,并且没有任何关于例如发送数据包的过程PID的消息.或者其他的东西.这是一段代码

Hello,

I made application which receives tcp packets from all ports on local ip. It''s like sniffer.
But as result I "listen" my own application too. The question is it possible to configure socket to don''t receive tcp packets from my application?.

I''ve read tcp header definition here and there is no word about for example process PID from which packet was sent or something. Here is piece of code

Socket socket = null;

try
{
    socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
    socket.Bind(new IPEndPoint(IPAddress.Parse(MonitoredIPAddress), 0));
    socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);
    socket.IOControl(unchecked((int)0x98000001), new byte[4] { 1, 0, 0, 0 }, new byte[4]);

    while (IsMonitoringTurnedOn)
    {
        IAsyncResult ar = socket.BeginReceive(PacketBuffer, 0, PacketBufferSize,
                          SocketFlags.None, new AsyncCallback(CallPacketReceive), this);

        while (socket.Available == 0)
        {
            Thread.Sleep(1);
            if (!IsMonitoringTurnedOn)
            {
                break;
            }
        }
        int size = socket.EndReceive(ar);

        ExtractPacketBuffer(); //Extract buffer with saving queue
     }
}

推荐答案



抱歉地说,不是,关心它来自的应用程序不在IP协议范围内.应该对数据包的端口,IP或内容做出任何决定.

如果您在处理自己的应用程序中的数据时遇到麻烦,那么应该走一小步,从接收到的数据中排除该IP/端口;如果您确实想处理可能与您共享端口的其他人的数据,则必须调查数据包数据,看看它是否属于您的数据包.

希望这会有所帮助,

干杯,AT
Hi,

Sorry to say but no, it is not in the scope of the IP protocol to care about the application it came from. Any decisions should be made on either the Port, IP or content of the data packet.

If you are having the trouble that you are handling data from your own app it should be a small step to exclude that IP/port from the received data; if you do want to handle the data from others which may share your port you''ll have to investigate the packet data and see if it is one of yours.

Hope this helps,

Cheers, AT


这篇关于是否有可能使Socket不接收来自某些应用程序的数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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