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();
}
}