From: Juliusz Chroboczek <jch@pps.jussieu.fr>
Date: Sun, 20 Nov 2011 22:47:20 +0000 (+0100)
Subject: Fix incorrect parsing of port number.
X-Git-Tag: dht-bootstrap-0.2~3
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=717d9460074a0fd3d5423bd82745713d5b35c5fb;p=dht-bootstrap.git

Fix incorrect parsing of port number.
---

diff --git a/dht-bootstrap.c b/dht-bootstrap.c
index d96b0f7..a282b78 100644
--- a/dht-bootstrap.c
+++ b/dht-bootstrap.c
@@ -406,6 +406,15 @@ main(int argc, char **argv)
         }
     }
 
+    i = optind;
+
+    if(argc < i + 1)
+        goto usage;
+
+    port = atoi(argv[i++]);
+    if(port <= 0 || port >= 0x10000)
+        goto usage;
+
     if(ipv4) {
         dht_socket = socket(PF_INET, SOCK_DGRAM, 0);
         if(dht_socket < 0)
@@ -514,15 +523,6 @@ main(int argc, char **argv)
     if(!quiet)
         dht_debug = stdout;
     
-    i = optind;
-
-    if(argc < i + 1)
-        goto usage;
-
-    port = atoi(argv[i++]);
-    if(port <= 0 || port >= 0x10000)
-        goto usage;
-
     while(i < argc) {
         struct addrinfo hints, *info, *infop;
         memset(&hints, 0, sizeof(hints));