In what byte order does data transfer occur on net? Is it Little Endian or big endian? How is it converted to the respective byte order once the data reaches the host ?
相关问题
- How to run tcp and udp on a single port at same ti
- Sending the array of arbitrary length through a so
- Emulatin Big Endian ARM system with QEMU
- cURL Error 1: Unsupported protocol: https
- Cross-platform definition of _byteswap_uint64 and
相关文章
- Is it possible to send LDAP “requests” via telnet?
- What should I #include to use 'htonl'?
- Difference between Internal IP Address and Externa
- Platform independent storage of signed integers
- Why do inet_ntoa and inet_ntop “reverse” the bytes
- what is the benefit of detecting endian at runtime
- Android phone development - UDP services
- why endianess matters among bits inside a byte?
if you are using tcp using htons((short)port) enables you to use network safe protocol(basically big endian) and dont care about little vs. big endian.
if you do need to convert use http://www.codeguru.com/forum/showthread.php?t=292902
Its explained well
"Network byte order" is Big Endian, and protocols such as TCP use this for integer fields (e.g. port numbers). Functions such as htons and ntohs can be used to do conversion.
The data itself doesn't have any endianness it's entirely application defined, unless you're using a Presentation Layer such as XDR.
Its transferred in whatever order you send it.
Traditionally, internet protocols use big endian, because the machines doing most of the communication were big endian.
However, if you define your own structures to send across the net, there is no need to follow that convention.
With C programming, typically, one often uses the htons or ntohs macros to do the conversion.