Reputation: 1385
I am new to raw socket, and I am playing around with ip header.
I noticed that
ip->ip_hl = sizeof(struct ip) >> 2 //works fine;
however
ip->ip_hl = hton(sizeof(struct ip) >> 2) //will not work;
what i dont understand is that why not convert all the numbers to network order instead of host order in this case? what's the general rule to judge when to use network order/host order?
Thanks
Upvotes: 1
Views: 495
Reputation: 22251
htons
is for 16-bit values. htonl
is for 32-bit values. As for hton
(no suffix), I'm not even sure that exists.
The header length occupies only one byte (actually part of one byte). You don't need to flip any bytes to get it into the right form. Accordingly, there is no macro like htons
or htonl
for 8-bit values.
Upvotes: 1