0

Is the packing of a char IP[4] (192.168.2.1) into a uint32 detailed as part of any RSI/ISO/standards bodies (i.e. anyone here https://en.wikipedia.org/wiki/List_of_technical_standard_organisations)? I know it's standard across a range of languages and tools, but I'm wondering if it's part of any international standard, and if so which one? That should detail for example the endianness used.

Need to know as I'm writing a specification, and I don't want to re-invent the wheel by describing the technique.

James
  • 224
  • 2
  • 13

2 Answers2

1

All IP addresses (and, in fact, all multi-byte numbers used in the standard networking stack) sent on the wire are in "network order" which is big-endian.

How to represent four bytes of anything within a program depends on the programmer though they typically let the compiler decide which of course uses whatever the native hardware uses.

From Why is network-byte-order defined to be big-endian? ...


RFC1700 stated it must be so. (and defined network byte order as big-endian). It has now been superseded by RFC-3232, but this part remains the same.

The convention in the documentation of Internet Protocols is to express numbers in decimal and to picture data in "big-endian" order [COHEN]. That is, fields are described left to right, with the most significant octet on the left and the least significant octet on the right.

The reference they make is to

On Holy Wars and a Plea for Peace 
Cohen, D. 
Computer

The abstract can be found at IEN-137 or on this IEEE page.

Summary:

Which way is chosen does not make too much difference. It is more important to agree upon an order than which order is agreed upon.

It concludes that both big-endian and little-endian schemes could've been possible. There is no better/worse scheme, and either can be used in place of the other as long as it is consistent all across the system/protocol.

Community
  • 1
  • 1
Brian White
  • 8,332
  • 2
  • 43
  • 67
  • Thanks Brian. Do you know the ISO/standard which defines network order? – James Nov 13 '15 at 16:13
  • Answer updated using existing SO answer here: http://stackoverflow.com/questions/13514614/why-is-network-byte-order-defined-to-be-big-endian – Brian White Nov 13 '15 at 20:12
0

This depends on where that IPv4 address is going.

For actual IP usage, i.e. in network packets, the packing always uses network byte order, i.e. big-endian.

If you're usage is something different, then you're of course free to define the packing however you want.

unwind
  • 391,730
  • 64
  • 469
  • 606