summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dns.c
diff options
context:
space:
mode:
authorThierry Vignaud <thierry.vignaud@gmail.com>2014-02-28 08:22:24 +0100
committerThierry Vignaud <thierry.vignaud@gmail.com>2014-02-28 08:22:24 +0100
commit6d8df12830883d6537e6844a6deae8adb8bfe37c (patch)
treec64f3c41cc0de7a1eaa390d66409ebd4db280eae /mdk-stage1/dns.c
parent6a5716b7cc575050834fe8e0580da99905b69fd5 (diff)
downloaddrakx-6d8df12830883d6537e6844a6deae8adb8bfe37c.tar
drakx-6d8df12830883d6537e6844a6deae8adb8bfe37c.tar.gz
drakx-6d8df12830883d6537e6844a6deae8adb8bfe37c.tar.bz2
drakx-6d8df12830883d6537e6844a6deae8adb8bfe37c.tar.xz
drakx-6d8df12830883d6537e6844a6deae8adb8bfe37c.zip
use getaddrinfo() with glibc too now that use the dynamic library
glibc couldn't do hostname lookup when linked statically...
Diffstat (limited to 'mdk-stage1/dns.c')
-rw-r--r--mdk-stage1/dns.c140
1 files changed, 0 insertions, 140 deletions
diff --git a/mdk-stage1/dns.c b/mdk-stage1/dns.c
index 8651df5a7..f711758aa 100644
--- a/mdk-stage1/dns.c
+++ b/mdk-stage1/dns.c
@@ -21,10 +21,6 @@
#include <stdlib.h>
-// dietlibc can do hostname lookup, whereas glibc can't when linked statically :-(
-
-#if defined(__dietlibc__)
-
#include <unistd.h>
#include <string.h>
#include <stdio.h>
@@ -92,139 +88,3 @@ char * mygethostbyaddr(char * ipnum)
return strdup(hbuf);
else return NULL;
}
-
-#elif defined(__GLIBC__)
-
-#include <alloca.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <resolv.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "log.h"
-
-#include "dns.h"
-
-/* This is dumb, but glibc doesn't like to do hostname lookups w/o libc.so */
-
-union dns_response {
- HEADER hdr;
- u_char buf[PACKETSZ];
-} ;
-
-static int do_query(char * query, int queryType, char ** domainName, struct in_addr * ipNum)
-{
- int len, ancount, type;
- u_char * data, * end;
- char name[MAXDNAME];
- union dns_response response;
-
- _res.retry = 2;
-
-
- len = res_search(query, C_IN, queryType, (void *) &response, sizeof(response));
- if (len <= 0)
- return -1;
-
- if (ntohs(response.hdr.rcode) != NOERROR)
- return -1;
-
- ancount = ntohs(response.hdr.ancount);
- if (ancount < 1)
- return -1;
-
- data = response.buf + sizeof(HEADER);
- end = response.buf + len;
-
- /* skip the question */
- data += dn_skipname(data, end) + QFIXEDSZ;
-
- /* parse the answer(s) */
- while (--ancount >= 0 && data < end) {
-
- /* skip the domain name portion of the RR record */
- data += dn_skipname(data, end);
-
- /* get RR information */
- GETSHORT(type, data);
- data += INT16SZ; /* skipp class */
- data += INT32SZ; /* skipp TTL */
- GETSHORT(len, data);
-
- if (type == T_PTR) {
- /* we got a pointer */
- len = dn_expand(response.buf, end, data, name, sizeof(name));
- if (len <= 0) return -1;
- if (queryType == T_PTR && domainName) {
- /* we wanted a pointer */
- *domainName = malloc(strlen(name) + 1);
- strcpy(*domainName, name);
- return 0;
- }
- } else if (type == T_A) {
- /* we got an address */
- if (queryType == T_A && ipNum) {
- /* we wanted an address */
- memcpy(ipNum, data, sizeof(*ipNum));
- return 0;
- }
- }
-
- /* move ahead to next RR */
- data += len;
- }
-
- return -1;
-}
-
-char * mygethostbyaddr(char * ipnum) {
- int rc;
- char * result;
- char * strbuf;
- char * chptr;
- char * splits[4];
- int i;
-
- _res.retry = 1;
-
- strbuf = alloca(strlen(ipnum) + 1);
- strcpy(strbuf, ipnum);
-
- ipnum = alloca(strlen(strbuf) + 20);
-
- for (i = 0; i < 4; i++) {
- chptr = strbuf;
- while (*chptr && *chptr != '.')
- chptr++;
- *chptr = '\0';
-
- if (chptr - strbuf > 3) return NULL;
- splits[i] = strbuf;
- strbuf = chptr + 1;
- }
-
- sprintf(ipnum, "%s.%s.%s.%s.in-addr.arpa", splits[3], splits[2], splits[1], splits[0]);
-
- rc = do_query(ipnum, T_PTR, &result, NULL);
-
- if (rc)
- return NULL;
- else
- return result;
-}
-
-int mygethostbyname(char * name, struct in_addr * addr) {
- int rc = do_query(name, T_A, NULL, addr);
- if (!rc)
- log_message("is-at %s", inet_ntoa(*addr));
- return rc;
-}
-
-#else
-
-#error "Unsupported C library"
-
-#endif