[Vtun-Commit] CVS: The file 'vtun/generic/udp_proto.c' has been modified.
Status: Inactive
Brought to you by:
mtbishop
|
From: Bishop <mtbishop> - 2009-03-29 10:09:18
|
The following file was modified in vtun/generic:
Name Old version New version Comment
---- ----------- ----------- -------
udp_proto.c 1.10.2.2 1.10.2.3
The accompanying log:
rfe2636157 - Permit a delayed UDP connection to overcome unpredictable
NAT ports.
The diff of the modified file(s):
--- udp_proto.c 7 Jan 2008 22:36:19 -0000 1.10.2.2
+++ udp_proto.c 29 Mar 2009 10:09:13 -0000 1.10.2.3
@@ -56,12 +56,16 @@
#include "vtun.h"
#include "lib.h"
+extern int is_rmt_fd_connected;
+
/* Functions to read/write UDP frames. */
int udp_write(int fd, char *buf, int len)
{
register char *ptr;
register int wlen;
+ if (!is_rmt_fd_connected) return 0;
+
ptr = buf - sizeof(short);
*((unsigned short *)ptr) = htons(len);
@@ -86,6 +90,24 @@
unsigned short hdr, flen;
struct iovec iv[2];
register int rlen;
+ struct sockaddr_in from;
+ socklen_t fromlen = sizeof(struct sockaddr);
+
+ /* Late connect (NAT hack enabled) */
+ if (!is_rmt_fd_connected) {
+ while( 1 ){
+ if( (rlen = recvfrom(fd,buf,2,MSG_PEEK,(struct sockaddr *)&from,&fromlen)) < 0 ){
+ if( errno == EAGAIN || errno == EINTR ) continue;
+ else return rlen;
+ }
+ else break;
+ }
+ if( connect(fd,(struct sockaddr *)&from,fromlen) ){
+ vtun_syslog(LOG_ERR,"Can't connect socket");
+ return -1;
+ }
+ is_rmt_fd_connected = 1;
+ }
/* Read frame */
iv[0].iov_len = sizeof(short);
|