]> Sergey Matveev's repositories - dht-bootstrap.git/blobdiff - dht-bootstrap.c
Remove unused global variable: ones.
[dht-bootstrap.git] / dht-bootstrap.c
index 372393e61947617c5dec3fc6b33525709a8cc12c..9a436705dfb85535ebc97fc5eba08197b374dd7a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2009 by Juliusz Chroboczek
+Copyright (c) 2009-2011 by Juliusz Chroboczek
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -114,11 +114,6 @@ static int parse_message(const unsigned char *buf, int buflen,
                          int *want_return);
 
 static const unsigned char zeroes[20] = {0};
-static const unsigned char ones[20] = {
-    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-    0xFF, 0xFF, 0xFF, 0xFF
-};
 static const unsigned char v4prefix[16] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0
 };
@@ -406,6 +401,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)
@@ -427,6 +431,7 @@ main(int argc, char **argv)
         struct sockaddr_in sin;
         int rc;
         memset(&sin, 0, sizeof(sin));
+        sin.sin_family = AF_INET;
         sin.sin_port = htons(port);
         rc = bind(dht_socket, (struct sockaddr*)&sin, sizeof(sin));
         if(rc < 0) {
@@ -460,10 +465,11 @@ main(int argc, char **argv)
         }
 
         /* BEP-32 mandates that we should bind this socket to one of our
-           global IPv6 addresses.  In this simple example, this only
-           happens if the user used the -b flag. */
+           global IPv6 addresses.  In this program, this only happens if
+           the user used the -b flag. */
 
         memset(&sin6, 0, sizeof(sin6));
+        sin6.sin6_family = AF_INET6;
         sin6.sin6_port = htons(port);
         rc = bind(dht_socket6, (struct sockaddr*)&sin6, sizeof(sin6));
         if(rc < 0) {
@@ -512,15 +518,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));
@@ -597,7 +594,7 @@ main(int argc, char **argv)
             unsigned short port;
             unsigned char values[2048], values6[2048];
             int values_len = 2048, values6_len = 2048;
-            int want, want4, want6;
+            int want;
             struct sockaddr_storage source_storage;
             struct sockaddr *source = (struct sockaddr*)&source_storage;
             socklen_t sourcelen = sizeof(source_storage);
@@ -643,14 +640,6 @@ main(int argc, char **argv)
                 }
             }
 
-            if(want > 0) {
-                want4 = (want & WANT4);
-                want6 = (want & WANT6);
-            } else {
-                want4 = source->sa_family == AF_INET;
-                want6 = source->sa_family == AF_INET6;
-            }
-
             switch(message) {
             case REPLY:
                 if(tid_len != 4) {