When I use following statement in the code which runs on ARM9, it does not correctly parse the IP address. I am using standard function for sscanf().
main() { unsigned char ip[16]; sscanf("255.1.1.1","%u.%u.%u.%u",&ip[0],&ip[1],&ip[2],&ip[3]); }
thanks in advance, -pjs
Many things are wrong with the code
Assume the ip is aligned on a 32-bit boundry and littel endian
The first %u puts
255 into ip 0 0 into ip 1 0 into ip 2 0 into ip 3
The second %u tries to put startig at ip 1's address, but sing it is not 32-bit aligned, it "rounds down"
The second %u puts 1 into ip 0 0 into ip 1 0 into ip 2 0 into ip 3
The 3rd (this is also rounded down)
puts 1 into ip 0 0 into ip 1 0 into ip 2 0 into ip 3
4th
which is what happens.
This is what I would expect to happen
The only reason it runs on the PC is because it allows 32 bit access that are not 32-bit aligned.