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
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.
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.
About the author
Torque Owner Nathan Martin
TRON 2001 Network
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.