Monday, March 19, 2007

Byte Order

For a while now I've been running some code I wrote in the FreeBSD kernel that has been returning stupid values for the sizes of packets when I print out the payload length field from the ip6_hdr struct as any ipv6 packet leaves the system. Every time I was getting stupid values such as 4096 for a 16 Byte payload, I had a quick think about it at the time and couldn't figure it out. Of course, it is ridiculously stupid now I've thought about it again, and also ridiculously obvious.

NETWORK BYTE ORDER AND HOST BYTE ORDER ARE DIFFERENT.

Hopefully putting this post on here should stop me making the same stupidly obvious mistake in the future, the ntohs() and htons() functions are there for a damn good reason, use them, I am now getting the correct output values on the original FreeBSD code and on my new Linux code. F'ing idiot.....

0 Comments:

Post a Comment

<< Home