Replacement for dup() on Windows

It doesn't work on sockets, which require a bit more care.
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx
index bd9971c..1ed6df0 100644
--- a/common/network/TcpSocket.cxx
+++ b/common/network/TcpSocket.cxx
@@ -120,6 +120,23 @@
 }
 
 
+// -=- Socket duplication help for Windows
+static int dupsocket(int fd)
+{
+#ifdef WIN32
+  int ret;
+  WSAPROTOCOL_INFO info;
+  ret = WSADuplicateSocket(fd, GetCurrentProcessId(), &info);
+  if (ret != 0)
+    throw SocketException("unable to duplicate socket", errorNumber);
+  return WSASocket(info.iAddressFamily, info.iSocketType, info.iProtocol,
+                   &info, 0, 0);
+#else
+  return dup(fd);
+#endif
+}
+
+
 // -=- TcpSocket
 
 TcpSocket::TcpSocket(int sock, bool close)
@@ -432,7 +449,7 @@
 
 TcpListener::TcpListener(const TcpListener& other)
 {
-  fd = dup (other.fd);
+  fd = dupsocket (other.fd);
   // Hope TcpListener::shutdown(other) doesn't get called...
 }
 
@@ -441,7 +458,7 @@
   if (this != &other)
   {
     closesocket (fd);
-    fd = dup (other.fd);
+    fd = dupsocket (other.fd);
     // Hope TcpListener::shutdown(other) doesn't get called...
   }
   return *this;