Vanilla Development Maling List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS update: Vanilla/ntserv
Date: Tuesday May 11, 1999 @ 18:23
Author: ahn
Update of /home/netrek/cvsroot/Vanilla/ntserv
In directory cvs.castle.real-time.com:/var/tmp/cvs-serv994/ntserv
Modified Files:
socket.c
Log Message:
Changes by Dave Ahn. See ChangeLog for details.
****************************************
Index: Vanilla/ntserv/socket.c
diff -u Vanilla/ntserv/socket.c:1.9 Vanilla/ntserv/socket.c:1.10
--- Vanilla/ntserv/socket.c:1.9 Fri Apr 30 18:31:32 1999
+++ Vanilla/ntserv/socket.c Tue May 11 18:23:36 1999
@@ -1,4 +1,4 @@
-/* $Id: socket.c,v 1.9 1999/04/30 23:31:32 ahn Exp $
+/* $Id: socket.c,v 1.10 1999/05/11 23:23:36 ahn Exp $
*/
/*
@@ -235,6 +235,13 @@
int clientDead=0;
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? */
+#endif
+
+
static int udpLocalPort = 0;
static int udpClientPort = 0;
static int udpMode = MODE_SIMPLE; /* what kind of UDP trans we want */
@@ -899,6 +906,11 @@
retval += doRead(sock);
}
if (udpSock >= 0 && FD_ISSET(udpSock, &readfds)) {
+
+#ifdef UDP_PORTSWAP
+ portswapflags |= 4;
+#endif
+
V_UDPDIAG(("Activity on UDP socket\n"));
retval += doRead(udpSock);
}
@@ -921,11 +933,39 @@
int size;
int count;
int temp;
+#ifdef UDP_PORTSWAP
+ struct sockaddr_in moo;
+ int s;
+#endif
#ifdef PING /* need the socket in the ping handler routine */
rsock = asock;
#endif
+#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 */
+
+ if (portswapflags == 5) {
+ s = sizeof(moo);
+ UDPDIAG(("portswap hack entered\n"));
+ if (0 > recvfrom(asock, buf, BUFSIZ*2, MSG_PEEK,
+ (struct sockaddr *)&moo, &s)) {
+ perror("recvfrom");
+ }
+ else {
+ UDPDIAG(("client port is really %d\n", ntohs(moo.sin_port)));
+ portswapflags |= 2;
+ portswapflags &= ~4;
+ if (0 > connect(asock, (struct sockaddr *)&moo, sizeof(moo))) {
+ perror("connect");
+ }
+ }
+ }
+
+#endif
+
timeout.tv_sec=0;
timeout.tv_usec=0;
/* readfds = 1<<asock;*/
@@ -2128,6 +2168,11 @@
me->p_name));
closeUdpConn();
}
+#ifdef UDP_PORTSWAP
+ if (packet->connmode == CONNMODE_PORT) {
+ portswapflags |= 1;
+ }
+#endif
/* (note no openUdpConn(); we go straight to connect) */
if (connUdpConn() < 0) {
response.reply = SWITCH_DENIED;
@@ -2218,14 +2263,32 @@
caddr.sin_family = AF_INET;
caddr.sin_addr.s_addr = remoteaddr; /* addr of our client */
caddr.sin_port = htons(udpClientPort); /* client's port */
-
+
+#ifdef UDP_PORTSWAP
+
+ UDPDIAG(("UDP_FIX code enabled. portswapflags = %d\n", portswapflags));
+
+ if (portswapflags & 1) {
+ UDPDIAG(("portswap mode -- putting of connect() until later\n"));
+ }
+ else
+#endif
if (connect(udpSock, &caddr, sizeof(caddr)) < 0)
#else
- addr.sin_family = AF_INET;
+ addr.sin_family = AF_INET;
addr.sin_addr.s_addr = remoteaddr; /* addr of our client */
addr.sin_port = htons(udpClientPort); /* client's port */
+#ifdef UDP_PORTSWAP
+
+ UDPDIAG(("UDP_FIX code disabled. portswapflags = %d\n", portswapflags));
+
+ if (portswapflags & 1) {
+ UDPDIAG(("portswap mode -- putting of connect() until later\n"));
+ }
+ else
+#endif
if (connect(udpSock, &addr, sizeof(addr)) < 0)
#endif
{