sources/network/ipaddress.cpp

branch
protocol5
changeset 106
7b156b764d11
parent 88
08ccaf26cffd
child 109
e4966d7e615d
--- a/sources/network/ipaddress.cpp	Sat Jan 09 02:35:00 2016 +0200
+++ b/sources/network/ipaddress.cpp	Sat Jan 09 17:41:21 2016 +0200
@@ -38,15 +38,12 @@
 # include <ws2tcpip.h>
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+BEGIN_ZFC_NAMESPACE
 
 #ifdef _WIN32
-using AddrInfo = ADDRINFOA;
+typedef ADDRINFOA AddrInfo;
 #else
-using AddrInfo = struct addrinfo;
+typedef struct addrinfo AddrInfo;
 #endif
 
 // -----------------------------------------------------------------------------
@@ -69,12 +66,11 @@
 
 // -----------------------------------------------------------------------------
 //
-METHOD
-IPAddress::to_string (WithPort withport) const -> String
+String IPAddress::to_string (WithPort withport) const
 {
 	String val;
 
-	if (withport == IP_WITH_PORT)
+	if (withport == WITH_PORT)
 		val.sprintf ("%u.%u.%u.%u:%u", octet (0), octet (1), octet (2), octet (3), port);
 	else
 		val.sprintf ("%u.%u.%u.%u", octet (0), octet (1), octet (2), octet (3));
@@ -84,16 +80,14 @@
 
 // -----------------------------------------------------------------------------
 //
-METHOD
-IPAddress::octet (int n) const -> unsigned char
+unsigned char IPAddress::octet (int n) const
 {
 	return (host >> ((3 - n) * 8)) & 0xFF;
 }
 
 // -----------------------------------------------------------------------------
 //
-METHOD
-IPAddress::set_octet (int n, unsigned char oct) -> void
+void IPAddress::set_octet (int n, unsigned char oct)
 {
 	// TODO: make a big-endian version
 	host &= ~(0xFF << (3 - n) * 8);
@@ -102,8 +96,7 @@
 
 // -----------------------------------------------------------------------------
 //
-METHOD
-IPAddress::compare (const IPAddress& other) const -> bool
+bool IPAddress::compare (const IPAddress& other) const
 {
 	for (int i = 0; i < 4; ++i)
 	{
@@ -123,8 +116,7 @@
 
 // -----------------------------------------------------------------------------
 //
-METHOD
-IPAddress::operator< (const IPAddress& other) const -> bool
+bool IPAddress::operator< (const IPAddress& other) const
 {
 	for (int i = 0; i < 4; ++i)
 	{
@@ -137,8 +129,7 @@
 
 // -----------------------------------------------------------------------------
 //
-METHOD
-IPAddress::to_sockaddr_in() const -> sockaddr_in
+sockaddr_in IPAddress::to_sockaddr_in() const
 {
 	sockaddr_in claddr;
 	memset (&claddr, 0, sizeof claddr);
@@ -150,8 +141,7 @@
 
 // -----------------------------------------------------------------------------
 //
-STATIC METHOD
-IPAddress::from_string (String input) -> IPAddress
+IPAddress IPAddress::from_string (String input)
 {
 	unsigned int parts[4];
 	int colonpos = input.find (":");
@@ -171,15 +161,14 @@
 	}
 
 	if (colonpos != -1)
-		value.port = input.mid (colonpos + 1, -1).to_int();
+		value.port = (unsigned short) input.mid (colonpos + 1, -1).to_int();
 
 	return value;
 }
 
 // -----------------------------------------------------------------------------
 //
-STATIC METHOD
-IPAddress::resolve (String node) -> IPAddress
+IPAddress IPAddress::resolve (String node)
 {
 	AddrInfo hints;
 	AddrInfo* lookup;
@@ -197,3 +186,5 @@
 	freeaddrinfo (lookup);
 	return result;
 }
+
+END_ZFC_NAMESPACE
\ No newline at end of file

mercurial