Changeset - r11599:60558ee2245d
[Not reviewed]
master
0 2 0
rubidium - 16 years ago 2009-04-08 01:22:57
rubidium@openttd.org
(svn r15978) -Codechange: support parsing [] enclosed IPv6 addresses.
2 files changed with 12 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/network/core/address.h
Show inline comments
 
@@ -87,25 +87,25 @@ public:
 
	 * Create a network address based on a unresolved host and port
 
	 * @param ip the unresolved hostname
 
	 * @param port the port
 
	 * @param family the address family
 
	 */
 
	NetworkAddress(const char *hostname = "0.0.0.0", uint16 port = 0, int family = AF_INET) :
 
		address_length(0)
 
	{
 
		/* Also handle IPv6 bracket enclosed hostnames */
 
		if (StrEmpty(hostname)) hostname = "";
 
		if (*hostname == '[') hostname++;
 
		strecpy(this->hostname, StrEmpty(hostname) ? "" : hostname, lastof(this->hostname));
 
		char *tmp = strrchr(hostname, ']');
 
		char *tmp = strrchr(this->hostname, ']');
 
		if (tmp != NULL) *tmp = '\0';
 

	
 
		memset(&this->address, 0, sizeof(this->address));
 
		this->address.ss_family = family;
 
		this->SetPort(port);
 
	}
 

	
 
	/**
 
	 * Make a clone of another address
 
	 * @param address the address to clone
 
	 */
 
	NetworkAddress(const NetworkAddress &address)
src/network/network.cpp
Show inline comments
 
@@ -365,32 +365,43 @@ static void CheckMinActiveClients()
 
		NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "", CLIENT_ID_SERVER, NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_PLAYERS);
 
	}
 
}
 

	
 
/** Converts a string to ip/port/company
 
 *  Format: IP#company:port
 
 *
 
 * connection_string will be re-terminated to seperate out the hostname, and company and port will
 
 * be set to the company and port strings given by the user, inside the memory area originally
 
 * occupied by connection_string. */
 
void ParseConnectionString(const char **company, const char **port, char *connection_string)
 
{
 
	bool ipv6 = false;
 
	char *p;
 
	for (p = connection_string; *p != '\0'; p++) {
 
		switch (*p) {
 
			case '[':
 
				ipv6 = true;
 
				break;
 

	
 
			case ']':
 
				ipv6 = false;
 
				break;
 

	
 
			case '#':
 
				*company = p + 1;
 
				*p = '\0';
 
				break;
 

	
 
			case ':':
 
				if (ipv6) break;
 
				*port = p + 1;
 
				*p = '\0';
 
				break;
 
		}
 
	}
 
}
 

	
 
/* Creates a new client from a socket
 
 *   Used both by the server and the client */
 
static NetworkClientSocket *NetworkAllocClient(SOCKET s)
 
{
 
	if (_network_server) {
0 comments (0 inline, 0 general)