network.c:

- reset errno from failed bind() calls if the last one succeeds

DHT_bootstrap.c:
- move the perror() output next to where it belongs to
This commit is contained in:
Coren[m] 2013-09-11 00:44:05 +02:00
parent 0139f2838f
commit 5869057aba
2 changed files with 13 additions and 4 deletions

View File

@ -102,6 +102,8 @@ int main(int argc, char *argv[])
ip_init(&ip, ipv6enabled);
DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
perror("Initialization");
manage_keys(dht);
printf("Public key: ");
uint32_t i;
@ -122,8 +124,6 @@ int main(int argc, char *argv[])
printf("\n");
printf("Port: %u\n", PORT);
perror("Initialization.");
if (argc > argvoffset + 3) {
printf("Trying to bootstrap into the network...\n");
uint16_t port = htons(atoi(argv[argvoffset + 2]));

View File

@ -211,7 +211,7 @@ void networking_poll(Networking_Core *net)
}
}
uint8_t at_startup_ran;
uint8_t at_startup_ran = 0;
static int at_startup(void)
{
if (at_startup_ran != 0)
@ -252,8 +252,10 @@ Networking_Core *new_networking(IP ip, uint16_t port)
{
#ifdef TOX_ENABLE_IPV6
/* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */
if (ip.family != AF_INET && ip.family != AF_INET6)
if (ip.family != AF_INET && ip.family != AF_INET6) {
fprintf(stderr, "Invalid address family: %u\n", ip.family);
return NULL;
}
#endif
if (at_startup() != 0)
@ -287,6 +289,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
#else
if (temp->sock < 0) {
fprintf(stderr, "Failed to get a scoket?! %u, %s\n", errno, strerror(errno));
free(temp);
return NULL;
}
@ -409,6 +412,12 @@ Networking_Core *new_networking(IP ip, uint16_t port)
sprintf(logbuffer, "Bound successfully to %s:%u.\n", ip_ntoa(&ip), ntohs(temp->port));
loglog(logbuffer);
#endif
/* errno isn't reset on success, only set on failure, the failed
* binds with parallel clients yield a -EPERM to the outside if
* errno isn't cleared here */
if (tries > 0)
errno = 0;
return temp;
}