Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I've found something very strange.

 

Based on this information:

Reply Format

The reply always starts with FF FF FF FF 66 0A.

The format is then a series of these server address blocks:
Type 	Data
Byte 	First octet of IP address
Byte 	Second octet of IP address
Byte 	Third octect of IP address
Byte 	Fourth octet of IP address
[b]Unsigned Short 	Port number - usually 27015 (69 87) - this is network ordered, which is unlike every other Steam protocol.[/b]

Some of the servers may be unreachable, so query each server directly to find out. Note also that this list is not exhaustive, so if you're looking for a particular type of server make sure that you specify a filter with the query, rather than filtering client side. 

 

http://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol

 

But when I do this:

System.Windows.Forms.MessageBox.Show(BitConverter.ToUInt16(new byte[] { 0x69, 0x87 }, 0).ToString());

 

I get as result this:

34665

 

And as the information said, 69 87 should be 27015 (which is the default port for steam servers).

 

Am I using the wrong function for a Unsigned short or is an other problem?

 

Fixed, I used IPAddress.HostToNetworkOrder() :)

Edited by MrLucky
  • Leaders
Posted
Just to clarify, you are using the wrong byte order. When you write a hex number, you write in most signifigant byte first order, whereas (I believe) in the computer's internal representation (which is what bit converter deals with) numbers are represented as least signifigant byte first, which means that {0x69, 0x87} would actually represent the hex value 0x8769, or 34665.
[sIGPIC]e[/sIGPIC]
Posted (edited)

That requires going via a string, to avoid that step you can just move the high byte into position in a new short, and Or with the low byte:

Dim bytes As Byte() = {&H69, &H87}
' little endian conversion, big endian byte order:
Console.WriteLine(BitConverter.IsLittleEndian)
Console.WriteLine(BitConverter.ToUInt16(bytes, 0))
' Bitconverter is fine, if you reverse the byte order
' (could use array.reverse) 
Console.WriteLine(BitConverter.ToUInt16(New Byte() {bytes(1), bytes(0)}, 0)) 
' or manipulate the bits.
Console.WriteLine((CType((bytes(0)), UInt16) << 8) Or bytes(1))

byte[] bytes = {0x69, 0x87};
Console.WriteLine(BitConverter.IsLittleEndian);
Console.WriteLine(BitConverter.ToUInt16(bytes, 0));
Console.WriteLine(BitConverter.ToUInt16(new byte[] {bytes[1], bytes[0]}, 0));
Console.WriteLine(((UInt16)(bytes[0] << 8) | bytes[1]));

 

or you could use:

System.Net.IPAddress.NetworkToHostOrder

to switch the endian-ness, but only for int16, int32, int64

Edited by jo0ls

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...