From: Johannes Maximilian Kuehn Date: Wed, 6 Aug 2008 08:05:34 +0000 (+0900) Subject: networking.c: X-Git-Tag: NTP_4_2_5P142~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01aece0760c9a0387e68ac3b25d822d051781f38;p=thirdparty%2Fntp.git networking.c: Fixed resolver and some minor stuff bk: 48995b4eumjlZ72OabXOW8lFvFG4jQ --- diff --git a/gsoc_sntp/networking.c b/gsoc_sntp/networking.c index f6d5d1242..4ba563fd1 100644 --- a/gsoc_sntp/networking.c +++ b/gsoc_sntp/networking.c @@ -2,6 +2,7 @@ /* #include "sntp-opts.h" /**/ #include "networking.h" +#include "header.h" #include "log.h" @@ -9,63 +10,101 @@ int resolve_hosts (char **hosts, int hostc, struct addrinfo **res) { register unsigned int a, b; unsigned int entryc = 0; - res = (struct addrinfo **) malloc(sizeof(struct addrinfo) * hostc); - + /* res = (struct addrinfo **) malloc(sizeof(struct addrinfo) * (hostc + 1)); */ + + if(hostc < 1) + return 0; + struct addrinfo ***tres = (struct addrinfo ***) malloc(sizeof(struct addrinfo **) * hostc); + for(a=0; aai_next) { + entryc++; +#ifdef DEBUG + printf("--------------------------------------------------------------------------------\n"); + printf("Resolv No.: %i Result of getaddrinfo for %s:\n", entryc, hosts[a]); + printf("socktype: %i ", dres->ai_socktype); + printf("protocol: %i ", dres->ai_protocol); + printf("Prefered socktype: %i IP: %s\n", dres->ai_socktype, inet_ntoa(dres->ai_addr)); + printf("--------------------------------------------------------------------------------\n\n"); +#endif + } } } +#ifdef DEBUG + printf("Retrieved %i DNS entries, continuing...\n", entryc); +#endif + /* Make a list of the addrinfo list entries, start by counting them */ - for(a=0; aai_next != NULL) { - while(res[a]->ai_next != NULL) - entryc++; - } - } + for(a=0, b=0; aai_next != NULL) { - memcpy(result[a], res[b], sizeof(struct addrinfo)); - a++; + if(cur->ai_next == NULL) { + result[b] = *tres[a]; } else { - struct addrinfo *seek = res[b]->ai_next; + struct addrinfo *seek = *tres[a]; - for(; aai_next; } } } +#ifdef DEBUG + for(a=0; aai_addr)); +#endif + + *res = (struct addrinfo *) malloc(sizeof(struct addrinfo *) * entryc); + + for(a=0; a