15

What is the byte ordering of the 4-byte array returned by the GetAddressBytes() method of IPAddress class?

More on the GetAddressBytes method.

Is it big or little endian? I need to put some IP addresses to the message body, so it is important to me.

svick
  • 225,720
  • 49
  • 378
  • 501

3 Answers3

12

Network byte order ( = big endian). See:

Mauricio Scheffer
  • 97,551
  • 22
  • 191
  • 275
  • 1
    This is correct according to my tests. But it would be nice if there was an official doc to confirm, or at least a .NET framework source code sample. – Jordan Rieger May 12 '17 at 19:08
  • 1
    @JordanRieger: https://referencesource.microsoft.com/#System/net/System/Net/IPAddress.cs,004b582eb374555f – Robert Harvey Jul 24 '18 at 19:38
6

Big-Endian: 127.0.0.1 -> [127, 0, 0, 1]

Vinay Sajip
  • 90,050
  • 14
  • 168
  • 180
4

The same as the address you would read it if you had it as a normal dotted string.

Ie. "127.0.0.1" will give you 127, 0, 0, 1, in that order.

Lasse V. Karlsen
  • 366,661
  • 96
  • 610
  • 798