问题
Let's say we have two machines on a network MA and MB,
MA considers little endian the order of the bits in a byte,
on the contrary MB cosiders big endian the order of the bits in a byte.
How do MA and MB agree on what "endianess" to use for the bits in a byte during the communication over the network ?
Is there a standard "network endianess" or what ?
Do socket programmers have to take any actions in ensuring a correct communication ?
For example HTTP is a text protocol, that means that machines send and receive bytes wich represent characters,what if the encoding of the characters is different in the endianess of the bits ?
thanks
回答1:
Yes, the hardware protocols specify the bit order of bytes on all network links. This is generally handled automatically by the NIC hardware.
See, for example, this description of Ethernet frame format.
Ethernet transmission is strange, in that the byte order is big-endian (leftmost byte is sent first), but bit order little-endian (rigthmost, or LSB (Least Significant Bit) of the byte is sent first).
回答2:
Check this page: http://www.comptechdoc.org/independent/networking/protocol/protlayers.html It suggests that byte ordering is done at the Presentation Layer which is quite high up. This however will relate specifically to the application that you are using. I suspect data at lower levels (wrapping the higher levels) has a predetermined byte and bit order.
来源:https://stackoverflow.com/questions/25055714/bit-ordering-in-a-byte-does-it-matter