The Raw socket cannot use the Bind function of Socket class to bind the port.

tian zhou 1 Reputation point
2022-12-11T04:49:54.093+00:00

I want to create a raw socket and bind it to the specified port, but it is always bound to port 0. Why?
Here's my code.
{
Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Raw);
receiveSocket.Bind(new IPEndPoint(IPAddress.Parse("10.21.1.101"), 20000));

}

Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.