summaryrefslogtreecommitdiff
path: root/ev_win32.c
diff options
context:
space:
mode:
authorroot <root>2009-01-02 22:39:31 +0000
committerroot <root>2009-01-02 22:39:31 +0000
commitd78604c0330aba8e5c3def727686c2c9e88b7f62 (patch)
tree53fcbbbe533c64606ce0bde1f46db4fca7f1577a /ev_win32.c
parenta3642b17d3f1d0600d78c3178474476472230071 (diff)
*** empty log message ***
Diffstat (limited to 'ev_win32.c')
-rw-r--r--ev_win32.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/ev_win32.c b/ev_win32.c
index 2e0b300..c85c1ad 100644
--- a/ev_win32.c
+++ b/ev_win32.c
@@ -54,6 +54,8 @@ ev_pipe (int filedes [2])
{
struct sockaddr_in addr = { 0 };
int addr_size = sizeof (addr);
+ struct sockaddr_in adr2;
+ int adr2_size;
SOCKET listener;
SOCKET sock [2] = { -1, -1 };
@@ -67,7 +69,7 @@ ev_pipe (int filedes [2])
if (bind (listener, (struct sockaddr *)&addr, addr_size))
goto fail;
- if (getsockname(listener, (struct sockaddr *)&addr, &addr_size))
+ if (getsockname (listener, (struct sockaddr *)&addr, &addr_size))
goto fail;
if (listen (listener, 1))
@@ -76,10 +78,34 @@ ev_pipe (int filedes [2])
if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
goto fail;
- if (connect (sock[0], (struct sockaddr *)&addr, addr_size))
+ if (connect (sock [0], (struct sockaddr *)&addr, addr_size))
goto fail;
- if ((sock[1] = accept (listener, 0, 0)) < 0)
+ if ((sock [1] = accept (listener, 0, 0)) < 0)
+ goto fail;
+
+ /* windows vista returns fantasy port numbers for getpeername.
+ * example for two interconnected tcp sockets:
+ *
+ * (Socket::unpack_sockaddr_in getsockname $sock0)[0] == 53364
+ * (Socket::unpack_sockaddr_in getpeername $sock0)[0] == 53363
+ * (Socket::unpack_sockaddr_in getsockname $sock1)[0] == 53363
+ * (Socket::unpack_sockaddr_in getpeername $sock1)[0] == 53365
+ *
+ * wow! tridirectional sockets!
+ *
+ * this way of checking ports seems to work:
+ */
+ if (getpeername (sock [0], (struct sockaddr *)&addr, &addr_size))
+ goto fail;
+
+ if (getsockname (sock [1], (struct sockaddr *)&adr2, &adr2_size))
+ goto fail;
+
+ errno = WSAEINVAL;
+ if (addr_size != adr2_size
+ || addr.sin_addr.s_addr != adr2.sin_addr.s_addr /* just to be sure, I mean, it's windows */
+ || addr.sin_port != adr2.sin_port)
goto fail;
closesocket (listener);