UDP Checksum problem

Hello sir,,

i m doing network programming in C
could u plzz let me know...at the time of udp checksum calculation does htons() or ntohs() play some role..??
i mean will there be any difference if some values are added in network form and other is in the host form...

Thnx 4 ur time..

Waiting for the reply...

I'm sorry, but I've no idea what you're asking. Maybe I'm just having an off day and missing something, but could you please clarify your question? Maybe with a quick example?

thnx a lot sir 4 ur reply..
sir,in the udp checksum computation part one has to add all the 16-bit fields of udp header,pseudo header and data payload...and the fileds can be either in network format or in host format..sir, i want to know whether it is required to convert all the fileds in network format or in host format..!1

thnx once again..

Any arithmetic (such as computing checksums) must be done after the fields have been converted to host format. Network byte order is only for transporting over the network.

If you did the computations without changing from network to host order first, then two machines with different endianness would compute different checksums. For example, one would see 0x00ff as decimal 255 and the other would see it as decimal 65280. If the checksum merely required doubling this number as an unsigned 16-bit integer with overflow (for example) then the first machine would yield 510 (0x01fe) and the second 130560 (0x1fe00; note the overflow).

thnx a lot sir....with help of your suggestions i corrected my code... :slight_smile: :slight_smile: