Friday, 6 September 2013

Listening to specific port in C# sockets

Listening to specific port in C# sockets

I'm have problem with listening to specified port. I have the following code:
Socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw,
ProtocolType.Unspecified);
Socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress, 1);
Socket.Bind(new IPEndPoint(localAddr, 80));
Socket.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, true);
Socket.IOControl(IOControlCode.ReceiveAll, BitConverter.GetBytes(1),
BitConverter.GetBytes(0));
Socket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new
AsyncCallback(ReadCallback), null);
and everything seems to work just fine, i capture incoming and outgoing
packets, I have all the information I need with just one exception - it
listens to all ports, not only 80 as I specified in Bind() method. Does
anyone have any ideas how can I read just these on port 80?

No comments:

Post a Comment