- fixed some problems with the ip address

Thu, 11 Dec 2014 06:13:32 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 11 Dec 2014 06:13:32 +0200
changeset 7
01e4e9ae323a
parent 6
c709bb1a08e4
child 8
8b697d30c49f

- fixed some problems with the ip address

sources/network/ipaddress.cpp file | annotate | diff | comparison | revisions
sources/network/ipaddress.h file | annotate | diff | comparison | revisions
--- a/sources/network/ipaddress.cpp	Thu Dec 11 05:59:43 2014 +0200
+++ b/sources/network/ipaddress.cpp	Thu Dec 11 06:13:32 2014 +0200
@@ -118,8 +118,7 @@
 	String addressString = colonpos == -1 ? input : input.mid (0, colonpos);
 	IPAddress value;
 
-	// Try scanf the IPv4 host first. If it's not an IP string, it could
-	// be a hostname; thus try resolve it.
+	// Try scanf the IPv4 host first
 	if (sscanf (addressString, "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3]))
 	{
 		for (short i = 0; i < 4; ++i)
@@ -127,12 +126,15 @@
 	}
 	else
 	{
-		// try resolve it
-		return IPAddress::resolve (addressString, ok);
+		// Possibly a hostname, try resolve it
+		value = IPAddress::resolve (addressString, ok);
+
+		if (*ok == false)
+			return value;
 	}
 
 	if (colonpos != -1)
-		value.port = atoi (input.mid (colonpos + 1, -1));
+		value.port = input.mid (colonpos + 1, -1).to_int();
 
 	return value;
 }
--- a/sources/network/ipaddress.h	Thu Dec 11 05:59:43 2014 +0200
+++ b/sources/network/ipaddress.h	Thu Dec 11 06:13:32 2014 +0200
@@ -2,6 +2,7 @@
 #include "../main.h"
 
 struct sockaddr;
+struct sockaddr_in;
 
 enum WithPort { IP_WITH_PORT, IP_NO_PORT };
 

mercurial