Vanilla Development Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS update: Vanilla/ntserv



Date:	Friday July 23, 1999 @ 17:09
Author:	ahn

Update of /home/netrek/cvsroot/Vanilla/ntserv
In directory cvs.castle.real-time.com:/var/tmp/cvs-serv15097/ntserv

Modified Files:
	socket.c 
Log Message:
Changes by Ahn.  See ChangeLog for details.


****************************************

Index: Vanilla/ntserv/socket.c
diff -u Vanilla/ntserv/socket.c:1.16 Vanilla/ntserv/socket.c:1.17
--- Vanilla/ntserv/socket.c:1.16	Fri Jun 25 16:50:11 1999
+++ Vanilla/ntserv/socket.c	Fri Jul 23 17:09:13 1999
@@ -1,4 +1,4 @@
-/* $Id: socket.c,v 1.16 1999/06/25 21:50:11 ahn Exp $
+/* $Id: socket.c,v 1.17 1999/07/23 22:09:13 ahn Exp $
  */
 
 /*
@@ -237,9 +237,12 @@
 static LONG sequence;			/* the holy sequence number */
 
 #ifdef UDP_PORTSWAP
-static int portswapflags = 0;		/* 1 = portswap enabled
-                                           2 = connect()ed yet (yes/no)
-                                           4 = are we processing UDP? */
+static int portswapflags = 0;
+
+#define PORTSWAP_ENABLED 1
+#define PORTSWAP_CONNECTED 2
+#define PORTSWAP_UDPRECEIVED 4
+
 #endif
 
 
@@ -931,7 +934,7 @@
 	if (udpSock >= 0 && FD_ISSET(udpSock, &readfds)) {
 
 #ifdef UDP_PORTSWAP
-            portswapflags |= 4;
+            portswapflags |= PORTSWAP_UDPRECEIVED;
 #endif
 
 	    V_UDPDIAG(("Activity on UDP socket\n"));
@@ -967,9 +970,13 @@
 #ifdef UDP_PORTSWAP
 
     /* read the source port of the first UDP packet that comes in, and
-       connect() to it -- PORTSWAP mode hack to work with NAT firewalls */
+       connect() to it -- PORTSWAP mode hack to work with NAT firewalls.
+
+       Note that if PORTSWAP_CONNECTED flag is set, the below 'if' block
+       will not be executed.
+     */
 
-    if (portswapflags == 5) {
+    if (portswapflags == (PORTSWAP_UDPRECEIVED | PORTSWAP_ENABLED)) {
         s = sizeof(moo);
         UDPDIAG(("portswap hack entered\n"));
         if (0 > recvfrom(asock, buf, BUFSIZ*2, MSG_PEEK,
@@ -979,8 +986,8 @@
         }
         else {
             UDPDIAG(("client port is really %d\n", ntohs(moo.sin_port)));
-            portswapflags |= 2;
-            portswapflags &= ~4;
+            portswapflags |= PORTSWAP_CONNECTED;
+            portswapflags &= ~PORTSWAP_UDPRECEIVED; 
             if (0 > connect(asock, (struct sockaddr *)&moo, sizeof(moo))) {
 		ERROR(1,("%s: portswap connect() failed, %s\n",
 			 whoami(), strerror(errno)));
@@ -2204,7 +2211,7 @@
 	    }
 #ifdef UDP_PORTSWAP
             if (packet->connmode == CONNMODE_PORT) {
-                portswapflags |= 1;
+                portswapflags |= PORTSWAP_ENABLED;
             }
 #endif
 	    /* (note no openUdpConn(); we go straight to connect) */
@@ -2302,7 +2309,7 @@
 
     UDPDIAG(("UDP_FIX code enabled.  portswapflags = %d\n", portswapflags));
 
-    if (portswapflags & 1) { 
+    if (portswapflags & PORTSWAP_ENABLED) { 
         UDPDIAG(("portswap mode -- putting of connect() until later\n"));
     }
     else
@@ -2318,7 +2325,7 @@
 
     UDPDIAG(("UDP_FIX code disabled.  portswapflags = %d\n", portswapflags));
 
-    if (portswapflags & 1) { 
+    if (portswapflags & PORTSWAP_ENABLED) { 
         UDPDIAG(("portswap mode -- putting of connect() until later\n"));
     }
     else
@@ -2363,6 +2370,11 @@
     shutdown(udpSock, 2);	/* wham */
     close(udpSock);		/* bam */
     udpSock = -1;		/* (nah) */
+
+#ifdef UDP_PORTSWAP
+    portswapflags &= ~(PORTSWAP_CONNECTED | PORTSWAP_ENABLED);
+    UDPDIAG(("Disabling PORTSWAP mode.  Flags = %d\n", portswapflags));
+#endif
 
     return (0);
 }