/*
-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
}
}
+ 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)
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) {
}
/* 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) {
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));
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);
}
}
- 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) {