Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket ReceiveAll

Tags:

c#

sockets

I am trying to capture ip packets in c#. Everything is working fine, except that i only get outgoing packets.

My Code:

using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP))
{
    sock.Bind(new IPEndPoint(MYADDRESS, 0));
    sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);
    sock.IOControl(IOControlCode.ReceiveAll, BitConverter.GetBytes(1), null);

    while (true)
    {
        byte[] buffer = new byte[sock.ReceiveBufferSize];
        int count = sock.Receive(buffer);

        // ...
    }
}

The problem is definitely my pc! But maybe there is a workaround ...

like image 631
user330841 Avatar asked Dec 18 '22 01:12

user330841


1 Answers

It is likely that that the Windows firewall is blocking incoming packets. Add your program to the firewall exclusions.

like image 148
MEF2A Avatar answered Dec 24 '22 02:12

MEF2A