I just started with some C ++ network software programs and compiled my raspberry Pi itself (without cross-compiling). It makes everything a little endian.
After creating my IP header, I calculate the IP checksum, but it always turned out incorrectly (for example, here http://www.thegeekstuff.com/2012/05/ip-header-checksum/ ).
By flipping gdb, I handled my problem to the order of the first 32 bits in the IP header. The example uses 0x4500003C , which means version 4 ( 0x4 ), IHL 5 ( 0x5 ), TOS 0 ( 0x00 ) and tot_length 60 ( 0x003C ). So I installed my package the same.
struct iphdr* ip;
Now in gdb I reviewed the first 32 bits, expecting 0x3C000045 due to endianness, but instead I get the following:
(gdb) print ip $1 = (iphdr *) 0x11018 (gdb) x/1xw 0x11018 0x11018: 0x003c0045
The first 16 bits have a small value ( 0x0045 ), but the second one containing a decimal 60 seems to have a large size ( 0x003C )!
What does it give? I'm crazy? Am I completely mistaken in byte order inside structures? (This is a definite opportunity)
source share