Game Development Community

T3D 1.1 Final - Torque expects ip address in big endian, port in little endian

by Dan Keller · in Torque 3D Professional · 02/13/2012 (7:09 am) · 1 replies

Build: All
Platform: All
Target: Network code
Issues:

In serverQuery.cpp

stream->read( &netNum[0] );
      stream->read( &netNum[1] );
      stream->read( &netNum[2] );
      stream->read( &netNum[3] );
      stream->read( &port );

      dSprintf( addressBuffer, sizeof( addressBuffer ), "IP:%d.%d.%d.%d:%d", netNum[0], netNum[1], netNum[2], netNum[3], port );
      Net::stringToAddress( addressBuffer, &addr );

Notice how the address is read first byte first (big endian) while the (2 byte) port is read directly (little endian). This is not a bug per se but is an inconsistency which causes problems when building a master server.

Steps to repeat:
Create a master server using htonl and ntohl like you're supposed to. Wonder why the ip addresses come out backwards.

Suggested fix:
Read the address as a long and use htonl. Or use ntohs on the port so they're both in net order.

#1
02/13/2012 (8:20 am)
Interesting that I didn't notice this when I was redoing the pushbutton master server internals to fix several problems, good catch. Unfortunately, this cannot be changed now as it would then make newer Torque engines incompatible with existing master server and game server implementations. This would especially effect GarageGames's master server as they run one for the community to help test multiplayer Torque games.

I am however planning on redoing the query protocol for master and game servers in order to move toward IPv6 support as the existing protocol cannot possibly use IPv6 addresses at all as you've seen for yourself the IP addresses are fixed sized. When I do this I'll be sure to keep all the integers endianness consistent during packet creation and parsing. I'm hoping to have this side project of mine finished a week before this upcoming World IPv6 Day.