开发者

What is the right approach to checksumming UDP packets

开发者 https://www.devze.com 2022-12-22 13:14 出处:网络
I\'m building UDP server application in C#. I\'ve come across a packet checksum problem. As you probably know, each packet should carry some simple way of telling receiver if开发者_运维百科 packet da

I'm building UDP server application in C#. I've come across a packet checksum problem.

As you probably know, each packet should carry some simple way of telling receiver if开发者_运维百科 packet data is intact.

Now, UDP already has 2-byte checksum as part of header, which is optional, at least in IPv4 world. Alternative method is to have custom checksum as part of data section in each packet, and to verify it on receiver.

My question boils down to: is it better to rely on (optional) checksum in UDP packet header, or to make a custom checksum implementation as part of packet data section?

Perhaps the right answer depends on circumstances (as usual), so one circumstance here is that, even though code is written and developed in .NET on Windows, it might have to run under platform-independent Mono.NET, so eventual solution should be compatible with other platforms. I believe that custom checksum algorithm would be easily portable, but I'm not so sure about the first one.

Any thoughts?

Also, shouts about packet checksumming in general are welcome.


Do you need to count errors? If the UDP checksum is wrong then any router could just throw the packet away and you'd never get anything.

Of course, if there's an error in the header (such as destination IP address) you also wouldn't get it.

Also, the UDP checksum algorithm is completely standardized, although the function call to turn checksums on or off does vary by platform, although it usually involves setsockopt.

0

精彩评论

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

关注公众号