Question

Socket socket1 = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

socket1.Bind(new IPEndPoint(ipAddress, 0));

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

byte[] byTrue = new byte[] { 1, 0, 0, 0 };
byte[] byOut = new byte[] { 1, 0, 0, 0 };

socket1.IOControl(IOControlCode.ReceiveAll, byTrue, byOut);

byte[] buffer1 = new byte[4096];

socket1.BeginReceive(buffer1, 0, buffer1.Length, SocketFlags.None, new AsyncCallback(OnReceive), new Tuple<Socket, byte[]>(socket1, buffer1));

I use this code to capture IP packets, on an adapter over all ports.

How would I modify this code to capture SMB/CIFS packets? It is not preferred to add an additional packet capture library to the project/code.

Was it helpful?

Solution

This code DOES capture SMB packets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top