开发者

UDP malformed packets

开发者 https://www.devze.com 2023-01-13 00:50 出处:网络
I use C# program for client UDP application. Application listens for a connection, and then communicates.

I use C# program for client UDP application. Application listens for a connection, and then communicates.

Socket udpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
udpClient.Bind(new IPEndPoint(IPAddress.Any, ListenPort));
udpClient.Blocking = true;
int count = 0;

while (count == 0) udpClient.ReceiveFrom(receiveBuffer, ref ePoint);
udpClient.SendTo(data, endPoint);
udpClient.ReceiveFrom(receiveBuffer, ref ep);
...

I use Wireshark to debug开发者_开发技巧 the application. The problem is that after sometime my application starts sending malformed STUN packets, and I think that because of that they get rejected by a router on the internet.

The question: is it possible to prevent sending malformed UDP/STUN packets?


When your application sends malformed UDP packets, it has a bug. The minimal fragment of your code has only one SendTo call. You can add a check function for the content/length of data.

BTW: UDP is connectionless. I would say, your application waits for a request or a kind of start command not for a connection.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号