]> Sergey Matveev's repositories - dht-bootstrap.git/blobdiff - dht-bootstrap.c
Fix incorrect parsing of port number.
[dht-bootstrap.git] / dht-bootstrap.c
index d96b0f7a763623dd93c53684ac3ca140d8248798..a282b782abdcbd63e691e7bfe16f237d83959d11 100644 (file)
@@ -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));