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
  • 236,525
  • 50
  • 385
  • 514

3 Answers3

13

Network byte order ( = big endian). See:

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 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
  • 95,872
  • 14
  • 179
  • 191
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
  • 380,855
  • 102
  • 628
  • 825