views:

24

answers:

1

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?

A: 

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.

harper
I am not sure it is a bug, at least on my side. The data gets received correctly, and it's not that UDP packets are malformed, but STUN packets.
Bogi