Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Big endian or Little endian on net?

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 ?

like image 422
TwiggedToday Avatar asked Jun 15 '09 18:06

TwiggedToday


2 Answers

"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.

like image 51
brian-brazil Avatar answered Oct 21 '22 17:10

brian-brazil


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.

like image 27
Matthias Wandel Avatar answered Oct 21 '22 18:10

Matthias Wandel