897a62e
diff -up quagga-0.99.9/ripngd/ripng_main.c.port_overflow quagga-0.99.9/ripngd/ripng_main.c
897a62e
--- quagga-0.99.9/ripngd/ripng_main.c.port_overflow	2006-10-16 01:34:48.000000000 +0200
897a62e
+++ quagga-0.99.9/ripngd/ripng_main.c	2008-01-29 17:39:58.000000000 +0100
897a62e
@@ -240,7 +240,8 @@ main (int argc, char **argv)
897a62e
               break;
897a62e
             } 
897a62e
           vty_port = atoi (optarg);
897a62e
-          vty_port = (vty_port ? vty_port : RIPNG_VTY_PORT);
897a62e
+          if (vty_port <= 0 || vty_port > 0xffff)
897a62e
+            vty_port = RIPNG_VTY_PORT;
897a62e
           break;
897a62e
 	case 'r':
897a62e
 	  retain_mode = 1;
897a62e
diff -up quagga-0.99.9/bgpd/bgp_main.c.port_overflow quagga-0.99.9/bgpd/bgp_main.c
897a62e
--- quagga-0.99.9/bgpd/bgp_main.c.port_overflow	2006-10-16 01:34:47.000000000 +0200
897a62e
+++ quagga-0.99.9/bgpd/bgp_main.c	2008-01-29 17:58:31.000000000 +0100
897a62e
@@ -201,6 +201,7 @@ main (int argc, char **argv)
897a62e
   int dryrun = 0;
897a62e
   char *progname;
897a62e
   struct thread thread;
897a62e
+  int tmp_port;
897a62e
 
897a62e
   /* Set umask before anything for security */
897a62e
   umask (0027);
897a62e
@@ -236,7 +237,11 @@ main (int argc, char **argv)
897a62e
           pid_file = optarg;
897a62e
           break;
897a62e
 	case 'p':
897a62e
-	  bm->port = atoi (optarg);
897a62e
+	  tmp_port = atoi (optarg);
897a62e
+	  if (tmp_port <= 0 || tmp_port > 0xffff)
897a62e
+	    bm->port = BGP_PORT_DEFAULT;
897a62e
+	  else
897a62e
+	    bm->port = tmp_port;
897a62e
 	  break;
897a62e
 	case 'A':
897a62e
 	  vty_addr = optarg;
897a62e
@@ -250,7 +255,8 @@ main (int argc, char **argv)
897a62e
               break;
897a62e
             } 
897a62e
           vty_port = atoi (optarg);
897a62e
-          vty_port = (vty_port ? vty_port : BGP_VTY_PORT);
897a62e
+	  if (vty_port <= 0 || vty_port > 0xffff)
897a62e
+	    vty_port = BGP_VTY_PORT;
897a62e
 	  break;
897a62e
 	case 'r':
897a62e
 	  retain_mode = 1;
897a62e
diff -up quagga-0.99.9/ripd/rip_main.c.port_overflow quagga-0.99.9/ripd/rip_main.c
897a62e
--- quagga-0.99.9/ripd/rip_main.c.port_overflow	2006-10-16 01:34:48.000000000 +0200
897a62e
+++ quagga-0.99.9/ripd/rip_main.c	2008-01-29 17:39:58.000000000 +0100
897a62e
@@ -236,7 +236,8 @@ main (int argc, char **argv)
897a62e
               break;
897a62e
             } 
897a62e
           vty_port = atoi (optarg);
897a62e
-          vty_port = (vty_port ? vty_port : RIP_VTY_PORT);
897a62e
+          if (vty_port <= 0 || vty_port > 0xffff)
897a62e
+            vty_port = RIP_VTY_PORT;
897a62e
 	  break;
897a62e
 	case 'r':
897a62e
 	  retain_mode = 1;
897a62e
diff -up quagga-0.99.9/ospfd/ospf_main.c.port_overflow quagga-0.99.9/ospfd/ospf_main.c
897a62e
--- quagga-0.99.9/ospfd/ospf_main.c.port_overflow	2006-10-16 01:34:48.000000000 +0200
897a62e
+++ quagga-0.99.9/ospfd/ospf_main.c	2008-01-29 17:39:58.000000000 +0100
897a62e
@@ -245,7 +245,8 @@ main (int argc, char **argv)
897a62e
               break;
897a62e
             } 
897a62e
           vty_port = atoi (optarg);
897a62e
-          vty_port = (vty_port ? vty_port : OSPF_VTY_PORT);
897a62e
+          if (vty_port <= 0 || vty_port > 0xffff)
897a62e
+            vty_port = OSPF_VTY_PORT;
897a62e
   	  break;
897a62e
 	case 'u':
897a62e
 	  ospfd_privs.user = optarg;
897a62e
diff -up quagga-0.99.9/ospf6d/ospf6_main.c.port_overflow quagga-0.99.9/ospf6d/ospf6_main.c
897a62e
--- quagga-0.99.9/ospf6d/ospf6_main.c.port_overflow	2006-10-16 01:34:48.000000000 +0200
897a62e
+++ quagga-0.99.9/ospf6d/ospf6_main.c	2008-01-29 17:39:58.000000000 +0100
897a62e
@@ -227,7 +227,8 @@ main (int argc, char *argv[], char *envp
897a62e
               break;
897a62e
             }
897a62e
           vty_port = atoi (optarg);
897a62e
-          vty_port = (vty_port ? vty_port : OSPF6_VTY_PORT);
897a62e
+          if (vty_port <= 0 || vty_port > 0xffff)
897a62e
+            vty_port = OSPF6_VTY_PORT;
897a62e
           break;
897a62e
         case 'u':
897a62e
           ospf6d_privs.user = optarg;
897a62e
diff -up quagga-0.99.9/zebra/main.c.port_overflow quagga-0.99.9/zebra/main.c
897a62e
--- quagga-0.99.9/zebra/main.c.port_overflow	2007-05-02 17:28:33.000000000 +0200
897a62e
+++ quagga-0.99.9/zebra/main.c	2008-01-29 17:39:58.000000000 +0100
897a62e
@@ -276,7 +276,8 @@ main (int argc, char **argv)
897a62e
 	      break;
897a62e
 	    } 
897a62e
 	  vty_port = atoi (optarg);
897a62e
-	  vty_port = (vty_port ? vty_port : ZEBRA_VTY_PORT);
897a62e
+	  if (vty_port <= 0 || vty_port > 0xffff)
897a62e
+	    vty_port = ZEBRA_VTY_PORT;
897a62e
 	  break;
897a62e
 	case 'r':
897a62e
 	  retain_mode = 1;