THE SOFTWARE.
*/
-/* For memmem. */
-#define _GNU_SOURCE
-
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
-#ifndef HAVE_MEMMEM
-#ifdef __GLIBC__
-#define HAVE_MEMMEM
-#endif
-#endif
-
-#ifndef MSG_CONFIRM
-#define MSG_CONFIRM 0
-#endif
-
-/* We set sin_family to 0 to mark unused slots. */
-#if AF_INET == 0 || AF_INET6 == 0
-#error You lose
-#endif
-
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-/* nothing */
-#elif defined(__GNUC__)
-#define inline __inline
-#if (__GNUC__ >= 3)
-#define restrict __restrict
-#else
-#define restrict /**/
-#endif
-#else
-#define inline /**/
-#define restrict /**/
-#endif
-
#define MAX(x, y) ((x) >= (y) ? (x) : (y))
#define MIN(x, y) ((x) <= (y) ? (x) : (y))
const unsigned char *tid,
int tid_len,
const unsigned char *target,
- int want,
- int confirm);
+ int want);
static int
send_nodes(
struct sockaddr *sa,
id[i] = random() & 0xFF;
make_tid(ttid, "fn", 0);
debugf("Sending find_node.\n");
- return send_find_node((struct sockaddr *)&ss, sslen, ttid, 4, id, want, 0);
+ return send_find_node((struct sockaddr *)&ss, sslen, ttid, 4, id, want);
}
}
int
main(int argc, char **argv)
{
- int port = 6881, quiet = 0, ipv4 = 1, ipv6 = 1;
- int opt, rc, i, send4;
- unsigned char ttid[4];
+ errno = 0;
+ int quiet = 0;
+ int ipv4 = 1;
+ int ipv6 = 1;
+ int opt = 0;
while (1) {
opt = getopt(argc, argv, "q46");
}
}
- i = optind;
+ int i = optind;
if (argc < i + 1)
goto usage;
}
}
+ int rc = 0;
{
- int fd;
- unsigned int seed;
-
- fd = open("/dev/urandom", O_RDONLY);
+ int fd = open("/dev/urandom", O_RDONLY);
if (fd < 0) {
perror("open(random)");
exit(1);
exit(1);
}
+ unsigned int seed;
rc = read(fd, &seed, sizeof(seed));
srandom(seed);
if (!quiet)
dht_debug = stdout;
+ unsigned char ttid[4];
+
while (i < argc) {
struct addrinfo hints, *info, *infop;
memset(&hints, 0, sizeof(hints));
token_bucket_time = time(NULL);
token_bucket_tokens = MAX_TOKEN_BUCKET_TOKENS;
+ int send4 = 0;
while (1) {
struct timeval tv;
fd_set readfds;
- int rc;
if ((dht_socket >= 0 && list_elements(&v4_confirmed) <= 16) ||
(dht_socket6 >= 0 && list_elements(&v6_confirmed) <= 16))
list_elements(&v4_new),
list_elements(&v6_new));
- rc = select(MAX(dht_socket, dht_socket6) + 1, &readfds, NULL, NULL, &tv);
+ int rc = select(MAX(dht_socket, dht_socket6) + 1, &readfds, NULL, NULL, &tv);
if (rc < 0) {
if (errno != EINTR) {
}
if (rc > 0) {
- int rc, message;
+ int rc = 0;
+ int message;
unsigned char tid[16], id[20], info_hash[20], target[20];
unsigned char buf[1536], nodes[256], nodes6[1024], token[128];
int tid_len = 16, token_len = 128;
const unsigned char *tid,
int tid_len,
const unsigned char *target,
- int want,
- int confirm)
+ int want)
{
char buf[512];
int i = 0, rc;
ADD_V(buf, i, 512);
rc = snprintf(buf + i, 512 - i, "1:y1:qe");
INC(i, rc, 512);
- return dht_send(buf, i, confirm ? MSG_CONFIRM : 0, sa, salen);
+ return dht_send(buf, i, 0, sa, salen);
fail:
errno = ENOSPC;
#undef COPY
#undef ADD_V
-#ifndef HAVE_MEMMEM
-static void *
-memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
-{
- const char *h = haystack;
- const char *n = needle;
- size_t i;
-
- /* size_t is unsigned */
- if (needlelen > haystacklen)
- return NULL;
-
- for (i = 0; i <= haystacklen - needlelen; i++) {
- if (memcmp(h + i, n, needlelen) == 0)
- return (void *)(h + i);
- }
- return NULL;
-}
-#endif
-
static int
parse_message(
const unsigned char *buf,