Split settings into seperate source and header files
[oweals/minetest.git] / src / socket.cpp
index 00856fb0094133890cf6754ef073d560591ef7a5..0e9183f18058c11cc645cd892a16347f1d01d462 100644 (file)
@@ -19,6 +19,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "socket.h"
 
+#include <stdio.h>
+#include <iostream>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sstream>
+#include <iomanip>
+#include "util/string.h"
+#include "util/numeric.h"
+#include "constants.h"
+#include "debug.h"
+#include "settings.h"
+#include "log.h"
+#include "main.h" // for g_settings
+
 #ifdef _WIN32
        #ifndef WIN32_LEAN_AND_MEAN
                #define WIN32_LEAN_AND_MEAN
@@ -46,20 +61,6 @@ typedef int socklen_t;
 typedef int socket_t;
 #endif
 
-#include "constants.h"
-#include "debug.h"
-#include "settings.h"
-#include "main.h" // for g_settings
-#include <stdio.h>
-#include <iostream>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <sstream>
-#include <iomanip>
-#include "util/string.h"
-#include "util/numeric.h"
-
 // Set to true to enable verbose debug output
 bool socket_enable_debug_output = false;
 
@@ -143,6 +144,15 @@ bool Address::operator!=(Address &address)
 
 void Address::Resolve(const char *name)
 {
+       if (!name || name[0] == 0) {
+               if (m_addr_family == AF_INET) {
+                       setAddress((u32) 0);
+               } else if (m_addr_family == AF_INET6) {
+                       setAddress((IPv6AddressBytes*) 0);
+               }
+               return;
+       }
+
        struct addrinfo *resolved, hints;
        memset(&hints, 0, sizeof(hints));
        
@@ -193,7 +203,8 @@ std::string Address::serializeString() const
 #ifdef _WIN32
        if(m_addr_family == AF_INET)
        {
-               u8 a, b, c, d, addr;
+               u8 a, b, c, d;
+               u32 addr;
                addr = ntohl(m_address.ipv4.sin_addr.s_addr);
                a = (addr & 0xFF000000) >> 24;
                b = (addr & 0x00FF0000) >> 16;
@@ -251,6 +262,18 @@ bool Address::isIPv6() const
        return m_addr_family == AF_INET6;
 }
 
+bool Address::isZero() const
+{
+       if (m_addr_family == AF_INET) {
+               return m_address.ipv4.sin_addr.s_addr == 0;
+       } else if (m_addr_family == AF_INET6) {
+               static const char zero[16] = {0};
+               return memcmp(m_address.ipv6.sin6_addr.s6_addr,
+                             zero, 16) == 0;
+       }
+       return false;
+}
+
 void Address::setAddress(u32 address)
 {
        m_addr_family = AF_INET;