Enlightenment CVS committal

Author  : mej
Project : eterm
Module  : Eterm

Dir     : eterm/Eterm/src


Modified Files:
        libscream.c screamcfg.h 


Log Message:
Mon Dec  5 15:46:34 2005                        Michael Jennings (mej)

Prevent firewall bounces from trying for the same port.
----------------------------------------------------------------------

===================================================================
RCS file: /cvsroot/enlightenment/eterm/Eterm/src/libscream.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -3 -r1.28 -r1.29
--- libscream.c 5 Oct 2005 18:43:11 -0000       1.28
+++ libscream.c 5 Dec 2005 20:45:58 -0000       1.29
@@ -39,6 +39,7 @@
 #include <limits.h>             /* PATH_MAX */
 #include <ctype.h>              /* isspace() */
 #include <errno.h>              /* errno */
+#include <sys/socket.h>
 
 #include "config.h"
 #include "feature.h"
@@ -203,22 +204,29 @@
         bzero(h, sizeof(_ns_hop));
         if ((h->fw = STRDUP(fw))) {
             if (!lp) {
-                lp = NS_MIN_PORT;       /* local port defaults to */
-                if (ha) {       /* NS_MIN_PORT. if that's */
-                    int f;      /* taken, use next FREE port. */
-
-                    do {        /* FREE as in, not used by us. */
-                        _ns_hop *i = ha;
-
-                        f = 0;
-                        while (i)
-                            if (i->localport == lp) {
-                                f = 1;
-                                lp++;
-                                i = NULL;
-                            } else
-                                i = i->next;
-                    } while (f);
+                int tmp_sock;
+
+                tmp_sock = socket(PF_INET, SOCK_STREAM, 6);
+                if (tmp_sock > 0) {
+                    struct sockaddr_in addr;
+
+                    addr.sin_family = AF_INET;
+                    addr.sin_addr.s_addr = INADDR_LOOPBACK;
+                    for (lp = NS_MIN_PORT; (lp > 0) && (lp < NS_MAX_PORT); 
lp++) {
+                        addr.sin_port = htons(lp);
+
+                        if (!bind(tmp_sock, (struct sockaddr *) &addr, 
sizeof(struct sockaddr_in))
+                            && !listen(tmp_sock, 1)) {
+                            /* We can listen on this port.  Use it! */
+                            /* FIXME:  Minor race condition between port 
selection and ssh call. */
+                            break;
+                        }
+                    }
+                    if ((lp < 0) || (lp == NS_MAX_PORT)) {
+                        /* We're going to fail anyway, so just throw something 
in. */
+                        lp = (NS_MIN_PORT + random()) % NS_MAX_PORT;
+                        BOUND(lp, NS_MIN_PORT, NS_MAX_PORT);
+                    }
                 }
             }
             h->delay = (delay ? delay : NS_TUNNEL_DELAY);
===================================================================
RCS file: /cvsroot/enlightenment/eterm/Eterm/src/screamcfg.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- screamcfg.h 12 May 2005 13:09:28 -0000      1.14
+++ screamcfg.h 5 Dec 2005 20:45:58 -0000       1.15
@@ -54,7 +54,7 @@
 #define NS_SCREEN_PRVS_REG   "\x01:focus up\r"
 
 #define NS_DFLT_SSH_PORT     22
-#define NS_MIN_PORT          1025
+#define NS_MIN_PORT          47323
 #define NS_MAX_PORT          65535
 
 #define NS_MAX_DISPS         512




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to