Suppose A is a BE machine and is sending 0x44332211 sending data to B which is LE. By default A will be using htonl of 0x44332211 which is nothing but 0x44332211.
Now when 0x44332211 reaches B,B knows that its a BE format, so B will flip by using htonl function and change it to 0x11223344.
What does this flipping meeans? I read this concept from internet. Why flipping is required before storing?
Because in that case flipped value 0x11223344 will be stored in LE like 0x44332211,which is different from what A send because B interprets it differently though they look alike?
/* Conversion from BE to LE */
i am summarising from the inputs you have given.What ever the machine is always the data is stored as byte 0 1st,byte 2 second and so on.Since B is a LE,it needs to store in the reverse order of A.so we are using htons(), so that byte 0 will be 11 byte1 will be 22 ,byte2 will be 33 and byte 4 will 44.Am i right?no need to worry about the internal representations in LE and BE.
– Subi Suresh Apr 22 '13 at 18:01