]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/gsocket.cpp
Warning fix
[wxWidgets.git] / src / unix / gsocket.cpp
index d417f12da8bf8a6d2f1250ae711affc5c9a3ce93..8bf9517551c363ed8cdc1ef14ba2dc6111cdf8ca 100644 (file)
 #include <types.h>
 #include <netinet/in.h>
 #endif
-#ifdef __NETBSD__
-#ifndef _NETBSD_SOURCE
-#define _NETBSD_SOURCE
-#endif
-#ifndef _LIBC
-#define _LIBC
-#endif
-#endif
 #include <netdb.h>
 #include <sys/ioctl.h>
 
@@ -307,7 +299,7 @@ struct hostent * wxGethostbyaddr_r(const char *addr_buf, int buf_size,
   return he;
 }
 
-#if defined(HAVE_GETHOSTBYNAME)
+#if defined(HAVE_GETSERVBYNAME)
 static struct servent * deepCopyServent(struct servent *s,
                                        const struct servent *se,
                                        char *buffer, int size)
@@ -699,7 +691,12 @@ GSocketError GSocket::SetServer()
      state after being previously closed.
    */
   if (m_reusable)
+  {
     setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long));
+#ifdef SO_REUSEPORT
+    setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(u_long));
+#endif
+  }
 
   /* Bind to the local address,
    * retrieve the actual address bound,
@@ -898,6 +895,21 @@ GSocketError GSocket::Connect(GSocketStream stream)
   ioctl(m_fd, FIONBIO, &arg);
 #endif
 
+  // If the reuse flag is set, use the applicable socket reuse flags(s)
+  if (m_reusable)
+  {
+    setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long));
+#ifdef SO_REUSEPORT
+    setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(u_long));
+#endif
+  }
+
+  // If a local address has been set, then we need to bind to it before calling connect
+  if (m_local && m_local->m_addr)
+  {
+     bind(m_fd, m_local->m_addr, m_local->m_len);
+  }
+
   /* Connect it to the peer address, with a timeout (see below) */
   ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);