aboutsummaryrefslogtreecommitdiff
path: root/libc/inet/resolv.c
diff options
context:
space:
mode:
authorGravatar Mike Frysinger <vapier@gentoo.org>2007-01-26 00:47:48 +0000
committerGravatar Mike Frysinger <vapier@gentoo.org>2007-01-26 00:47:48 +0000
commit3a1f1db73f88c229de1a9b7d273308bdbfe4114a (patch)
tree3e2037141426988b34c671b1d70cbd48415aba17 /libc/inet/resolv.c
parent5baeb7a77b8531aa271d2ab95efb1939fd784c9a (diff)
downloaduClibc-3a1f1db73f88c229de1a9b7d273308bdbfe4114a.tar.gz
uClibc-3a1f1db73f88c229de1a9b7d273308bdbfe4114a.tar.bz2
even more accumulated fixes from trunk
Diffstat (limited to 'libc/inet/resolv.c')
-rw-r--r--libc/inet/resolv.c995
1 files changed, 488 insertions, 507 deletions
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 0312b2ca3..6d918c02f 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -7,7 +7,7 @@
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
-*/
+ */
/*
* Portions Copyright (c) 1985, 1993
@@ -153,6 +153,11 @@
#include <sys/utsname.h>
#include <sys/un.h>
+#include <bits/uClibc_mutex.h>
+
+__UCLIBC_MUTEX_EXTERN(__resolv_lock);
+
+
#define MAX_RECURSE 5
#define REPLY_TIMEOUT 10
#define MAX_RETRIES 3
@@ -180,18 +185,6 @@ extern char * __nameserver[MAX_SERVERS];
extern int __searchdomains;
extern char * __searchdomain[MAX_SEARCH];
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-extern pthread_mutex_t __resolv_lock;
-# define BIGLOCK __pthread_mutex_lock(&__resolv_lock)
-# define BIGUNLOCK __pthread_mutex_unlock(&__resolv_lock);
-#else
-# define BIGLOCK
-# define BIGUNLOCK
-#endif
-
-
-
/* Structs */
struct resolv_header {
int id;
@@ -229,49 +222,49 @@ enum etc_hosts_action {
/* function prototypes */
extern int __get_hosts_byname_r(const char * name, int type,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop);
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop);
extern int __get_hosts_byaddr_r(const char * addr, int len, int type,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop);
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop);
extern void __open_etc_hosts(FILE **fp);
extern int __read_etc_hosts_r(FILE *fp, const char * name, int type,
- enum etc_hosts_action action,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop);
+ enum etc_hosts_action action,
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop);
extern int __dns_lookup(const char * name, int type, int nscount,
- char ** nsip, unsigned char ** outpacket, struct resolv_answer * a);
+ char ** nsip, unsigned char ** outpacket, struct resolv_answer * a);
extern int __encode_dotted(const char * dotted, unsigned char * dest, int maxlen);
extern int __decode_dotted(const unsigned char * message, int offset,
- char * dest, int maxlen);
+ char * dest, int maxlen);
extern int __length_dotted(const unsigned char * message, int offset);
extern int __encode_header(struct resolv_header * h, unsigned char * dest, int maxlen);
extern int __decode_header(unsigned char * data, struct resolv_header * h);
extern int __encode_question(struct resolv_question * q,
- unsigned char * dest, int maxlen);
+ unsigned char * dest, int maxlen);
extern int __decode_question(unsigned char * message, int offset,
- struct resolv_question * q);
+ struct resolv_question * q);
extern int __encode_answer(struct resolv_answer * a,
- unsigned char * dest, int maxlen);
+ unsigned char * dest, int maxlen);
extern int __decode_answer(unsigned char * message, int offset,
- struct resolv_answer * a);
+ struct resolv_answer * a);
extern int __length_question(unsigned char * message, int offset);
extern int __open_nameservers(void);
extern void __close_nameservers(void);
extern int __dn_expand(const u_char *, const u_char *, const u_char *,
- char *, int);
+ char *, int);
extern int __ns_name_uncompress(const u_char *, const u_char *,
- const u_char *, char *, size_t);
+ const u_char *, char *, size_t);
extern int __ns_name_ntop(const u_char *, char *, size_t);
extern int __ns_name_unpack(const u_char *, const u_char *, const u_char *,
- u_char *, size_t);
+ u_char *, size_t);
#ifdef L_encodeh
@@ -361,7 +354,7 @@ int __encode_dotted(const char *dotted, unsigned char *dest, int maxlen)
This routine understands compressed data. */
int __decode_dotted(const unsigned char *data, int offset,
- char *dest, int maxlen)
+ char *dest, int maxlen)
{
int l;
int measure = 1;
@@ -435,7 +428,7 @@ int __length_dotted(const unsigned char *data, int offset)
#ifdef L_encodeq
int __encode_question(struct resolv_question *q,
- unsigned char *dest, int maxlen)
+ unsigned char *dest, int maxlen)
{
int i;
@@ -460,7 +453,7 @@ int __encode_question(struct resolv_question *q,
#ifdef L_decodeq
int __decode_question(unsigned char *message, int offset,
- struct resolv_question *q)
+ struct resolv_question *q)
{
char temp[256];
int i;
@@ -525,7 +518,7 @@ int __encode_answer(struct resolv_answer *a, unsigned char *dest, int maxlen)
#ifdef L_decodea
int __decode_answer(unsigned char *message, int offset,
- struct resolv_answer *a)
+ struct resolv_answer *a)
{
char temp[256];
int i;
@@ -557,11 +550,11 @@ int __decode_answer(unsigned char *message, int offset,
#ifdef L_encodep
int __encode_packet(struct resolv_header *h,
- struct resolv_question **q,
- struct resolv_answer **an,
- struct resolv_answer **ns,
- struct resolv_answer **ar,
- unsigned char *dest, int maxlen)
+ struct resolv_question **q,
+ struct resolv_answer **an,
+ struct resolv_answer **ns,
+ struct resolv_answer **ar,
+ unsigned char *dest, int maxlen)
{
int i, total = 0;
int j;
@@ -621,7 +614,7 @@ int __decode_packet(unsigned char *data, struct resolv_header *h)
#ifdef L_formquery
int __form_query(int id, const char *name, int type, unsigned char *packet,
- int maxlen)
+ int maxlen)
{
struct resolv_header h;
struct resolv_question q;
@@ -649,14 +642,7 @@ int __form_query(int id, const char *name, int type, unsigned char *packet,
#ifdef L_dnslookup
-#ifdef __UCLIBC_HAS_THREADS__
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK __pthread_mutex_lock(&mylock)
-# define UNLOCK __pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
/* Just for the record, having to lock __dns_lookup() just for these two globals
* is pretty lame. I think these two variables can probably be de-global-ized,
@@ -665,7 +651,7 @@ static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
static int ns=0, id=1;
int __dns_lookup(const char *name, int type, int nscount, char **nsip,
- unsigned char **outpacket, struct resolv_answer *a)
+ unsigned char **outpacket, struct resolv_answer *a)
{
int i, j, len, fd, pos, rc;
struct timeval tv;
@@ -693,10 +679,10 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
DPRINTF("Looking up type %d answer for '%s'\n", type, name);
/* Mess with globals while under lock */
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
local_ns = ns % nscount;
local_id = id;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
while (retries < MAX_RETRIES) {
if (fd != -1)
@@ -722,13 +708,13 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
strncpy(lookup,name,MAXDNAME);
if (variant >= 0) {
- BIGLOCK;
- if (variant < __searchdomains) {
- strncat(lookup,".", MAXDNAME);
- strncat(lookup,__searchdomain[variant], MAXDNAME);
- }
- BIGUNLOCK;
- }
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ if (variant < __searchdomains) {
+ strncat(lookup,".", MAXDNAME);
+ strncat(lookup,__searchdomain[variant], MAXDNAME);
+ }
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ }
DPRINTF("lookup name: %s\n", lookup);
q.dotted = (char *)lookup;
q.qtype = type;
@@ -750,7 +736,7 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
#endif
if (fd < 0) {
- retries++;
+ retries++;
continue;
}
@@ -772,11 +758,11 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
#endif
if (rc < 0) {
if (errno == ENETUNREACH) {
- /* routing error, presume not transient */
- goto tryall;
+ /* routing error, presume not transient */
+ goto tryall;
} else
- /* retry */
- retries++;
+ /* retry */
+ retries++;
continue;
}
@@ -838,55 +824,55 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
first_answer = 1;
for (j=0;j<h.ancount;j++,pos += i)
- {
- i = __decode_answer(packet, pos, &ma);
+ {
+ i = __decode_answer(packet, pos, &ma);
- if (i<0) {
- DPRINTF("failed decode %d\n", i);
- goto again;
- }
+ if (i<0) {
+ DPRINTF("failed decode %d\n", i);
+ goto again;
+ }
- if ( first_answer )
- {
- ma.buf = a->buf;
- ma.buflen = a->buflen;
- ma.add_count = a->add_count;
- memcpy(a, &ma, sizeof(ma));
- if (a->atype != T_SIG && (0 == a->buf || (type != T_A && type != T_AAAA)))
- {
- break;
- }
- if (a->atype != type)
- {
- free(a->dotted);
- continue;
- }
- a->add_count = h.ancount - j - 1;
- if ((a->rdlength + sizeof(struct in_addr*)) * a->add_count > a->buflen)
- {
- break;
- }
- a->add_count = 0;
- first_answer = 0;
- }
- else
- {
- free(ma.dotted);
- if (ma.atype != type)
- {
- continue;
- }
- if (a->rdlength != ma.rdlength)
- {
- free(a->dotted);
- DPRINTF("Answer address len(%u) differs from original(%u)\n",
- ma.rdlength, a->rdlength);
- goto again;
+ if ( first_answer )
+ {
+ ma.buf = a->buf;
+ ma.buflen = a->buflen;
+ ma.add_count = a->add_count;
+ memcpy(a, &ma, sizeof(ma));
+ if (a->atype != T_SIG && (0 == a->buf || (type != T_A && type != T_AAAA)))
+ {
+ break;
+ }
+ if (a->atype != type)
+ {
+ free(a->dotted);
+ continue;
+ }
+ a->add_count = h.ancount - j - 1;
+ if ((a->rdlength + sizeof(struct in_addr*)) * a->add_count > a->buflen)
+ {
+ break;
+ }
+ a->add_count = 0;
+ first_answer = 0;
+ }
+ else
+ {
+ free(ma.dotted);
+ if (ma.atype != type)
+ {
+ continue;
+ }
+ if (a->rdlength != ma.rdlength)
+ {
+ free(a->dotted);
+ DPRINTF("Answer address len(%u) differs from original(%u)\n",
+ ma.rdlength, a->rdlength);
+ goto again;
+ }
+ memcpy(a->buf + (a->add_count * ma.rdlength), ma.rdata, ma.rdlength);
+ ++a->add_count;
+ }
}
- memcpy(a->buf + (a->add_count * ma.rdlength), ma.rdata, ma.rdlength);
- ++a->add_count;
- }
- }
DPRINTF("Answer name = |%s|\n", a->dotted);
DPRINTF("Answer type = |%d|\n", a->atype);
@@ -900,48 +886,48 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
free(lookup);
/* Mess with globals while under lock */
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
ns = local_ns;
id = local_id;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return (len); /* success! */
- tryall:
+ tryall:
/* if there are other nameservers, give them a go,
otherwise return with error */
{
variant = -1;
- local_ns = (local_ns + 1) % nscount;
- if (local_ns == 0)
- retries++;
+ local_ns = (local_ns + 1) % nscount;
+ if (local_ns == 0)
+ retries++;
- continue;
+ continue;
}
- again:
+ again:
/* if there are searchdomains, try them or fallback as passed */
{
int sdomains;
- BIGLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
sdomains=__searchdomains;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
if (variant < sdomains - 1) {
- /* next search */
- variant++;
+ /* next search */
+ variant++;
} else {
- /* next server, first search */
- local_ns = (local_ns + 1) % nscount;
- if (local_ns == 0)
- retries++;
+ /* next server, first search */
+ local_ns = (local_ns + 1) % nscount;
+ if (local_ns == 0)
+ retries++;
- variant = -1;
+ variant = -1;
}
}
}
-fail:
+ fail:
if (fd != -1)
close(fd);
if (lookup)
@@ -951,10 +937,10 @@ fail:
h_errno = NETDB_INTERNAL;
/* Mess with globals while under lock */
if (local_ns != -1) {
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
ns = local_ns;
id = local_id;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
return -1;
}
@@ -966,9 +952,8 @@ int __nameservers;
char * __nameserver[MAX_SERVERS];
int __searchdomains;
char * __searchdomain[MAX_SEARCH];
-#ifdef __UCLIBC_HAS_THREADS__
-pthread_mutex_t __resolv_lock = PTHREAD_MUTEX_INITIALIZER;
-#endif
+
+__UCLIBC_MUTEX_INIT(__resolv_lock, PTHREAD_MUTEX_INITIALIZER);
/*
* we currently read formats not quite the same as that on normal
@@ -982,60 +967,63 @@ int __open_nameservers()
#define RESOLV_ARGS 5
char szBuffer[128], *p, *argv[RESOLV_ARGS];
int argc;
+ int rv = 0;
- BIGLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
if (__nameservers > 0) {
- BIGUNLOCK;
- return 0;
+ goto DONE;
}
if ((fp = fopen("/etc/resolv.conf", "r")) ||
- (fp = fopen("/etc/config/resolv.conf", "r")))
- {
-
- while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
-
- for (p = szBuffer; *p && isspace(*p); p++)
- /* skip white space */;
- if (*p == '\0' || *p == '\n' || *p == '#') /* skip comments etc */
- continue;
- argc = 0;
- while (*p && argc < RESOLV_ARGS) {
- argv[argc++] = p;
- while (*p && !isspace(*p) && *p != '\n')
- p++;
- while (*p && (isspace(*p) || *p == '\n')) /* remove spaces */
- *p++ = '\0';
- }
+ (fp = fopen("/etc/config/resolv.conf", "r")))
+ {
- if (strcmp(argv[0], "nameserver") == 0) {
- for (i = 1; i < argc && __nameservers < MAX_SERVERS; i++) {
- __nameserver[__nameservers++] = strdup(argv[i]);
- DPRINTF("adding nameserver %s\n", argv[i]);
+ while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
+
+ for (p = szBuffer; *p && isspace(*p); p++)
+ /* skip white space */;
+ if (*p == '\0' || *p == '\n' || *p == '#') /* skip comments etc */
+ continue;
+ argc = 0;
+ while (*p && argc < RESOLV_ARGS) {
+ argv[argc++] = p;
+ while (*p && !isspace(*p) && *p != '\n')
+ p++;
+ while (*p && (isspace(*p) || *p == '\n')) /* remove spaces */
+ *p++ = '\0';
}
- }
- /* domain and search are mutually exclusive, the last one wins */
- if (strcmp(argv[0],"domain")==0 || strcmp(argv[0],"search")==0) {
- while (__searchdomains > 0) {
- free(__searchdomain[--__searchdomains]);
- __searchdomain[__searchdomains] = NULL;
+ if (strcmp(argv[0], "nameserver") == 0) {
+ for (i = 1; i < argc && __nameservers < MAX_SERVERS; i++) {
+ __nameserver[__nameservers++] = strdup(argv[i]);
+ DPRINTF("adding nameserver %s\n", argv[i]);
+ }
}
- for (i=1; i < argc && __searchdomains < MAX_SEARCH; i++) {
- __searchdomain[__searchdomains++] = strdup(argv[i]);
- DPRINTF("adding search %s\n", argv[i]);
+
+ /* domain and search are mutually exclusive, the last one wins */
+ if (strcmp(argv[0],"domain")==0 || strcmp(argv[0],"search")==0) {
+ while (__searchdomains > 0) {
+ free(__searchdomain[--__searchdomains]);
+ __searchdomain[__searchdomains] = NULL;
+ }
+ for (i=1; i < argc && __searchdomains < MAX_SEARCH; i++) {
+ __searchdomain[__searchdomains++] = strdup(argv[i]);
+ DPRINTF("adding search %s\n", argv[i]);
+ }
}
}
+ fclose(fp);
+ DPRINTF("nameservers = %d\n", __nameservers);
+ goto DONE;
}
- fclose(fp);
- DPRINTF("nameservers = %d\n", __nameservers);
- BIGUNLOCK;
- return 0;
- }
DPRINTF("failed to open %s\n", "resolv.conf");
h_errno = NO_RECOVERY;
- BIGUNLOCK;
- return -1;
+
+ rv = -1;
+
+ DONE:
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ return rv;
}
#endif
@@ -1044,7 +1032,7 @@ int __open_nameservers()
void __close_nameservers(void)
{
- BIGLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
while (__nameservers > 0) {
free(__nameserver[--__nameservers]);
__nameserver[__nameservers] = NULL;
@@ -1053,7 +1041,7 @@ void __close_nameservers(void)
free(__searchdomain[--__searchdomains]);
__searchdomain[__searchdomains] = NULL;
}
- BIGUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
}
#endif
@@ -1063,8 +1051,8 @@ struct hostent *gethostbyname(const char *name)
{
static struct hostent h;
static char buf[sizeof(struct in_addr) +
- sizeof(struct in_addr *)*2 +
- sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
+ sizeof(struct in_addr *)*2 +
+ sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
struct hostent *hp;
gethostbyname_r(name, &h, buf, sizeof(buf), &hp, &h_errno);
@@ -1082,8 +1070,8 @@ struct hostent *gethostbyname2(const char *name, int family)
#else /* __UCLIBC_HAS_IPV6__ */
static struct hostent h;
static char buf[sizeof(struct in6_addr) +
- sizeof(struct in6_addr *)*2 +
- sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
+ sizeof(struct in6_addr *)*2 +
+ sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
struct hostent *hp;
gethostbyname2_r(name, family, &h, buf, sizeof(buf), &hp, &h_errno);
@@ -1119,7 +1107,7 @@ int res_init(void)
/** rp->rhook = NULL; **/
/** rp->_u._ext.nsinit = 0; **/
- BIGLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
if(__searchdomains) {
int i;
for(i=0; i<__searchdomains; i++) {
@@ -1139,7 +1127,7 @@ int res_init(void)
}
}
rp->nscount = __nameservers;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
return(0);
}
@@ -1175,10 +1163,10 @@ int res_query(const char *dname, int class, int type,
memset((char *) &a, '\0', sizeof(a));
- BIGLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
__nameserversXX=__nameservers;
__nameserverXX=__nameserver;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
i = __dns_lookup(dname, type, __nameserversXX, __nameserverXX, &packet, &a);
if (i < 0) {
@@ -1207,10 +1195,10 @@ int res_query(const char *dname, int class, int type,
* is detected. Error code, if any, is left in h_errno.
*/
int res_search(name, class, type, answer, anslen)
- const char *name; /* domain name */
- int class, type; /* class and type of query */
- u_char *answer; /* buffer to put answer */
- int anslen; /* size of answer */
+ const char *name; /* domain name */
+ int class, type; /* class and type of query */
+ u_char *answer; /* buffer to put answer */
+ int anslen; /* size of answer */
{
const char *cp, * const *domain;
HEADER *hp = (HEADER *)(void *)answer;
@@ -1256,11 +1244,11 @@ int res_search(name, class, type, answer, anslen)
int done = 0;
for (domain = (const char * const *)_res.dnsrch;
- *domain && !done;
- domain++) {
+ *domain && !done;
+ domain++) {
ret = res_querydomain(name, *domain, class, type,
- answer, anslen);
+ answer, anslen);
if (ret > 0)
return (ret);
@@ -1283,22 +1271,22 @@ int res_search(name, class, type, answer, anslen)
}
switch (h_errno) {
- case NO_DATA:
- got_nodata++;
- /* FALLTHROUGH */
- case HOST_NOT_FOUND:
- /* keep trying */
- break;
- case TRY_AGAIN:
- if (hp->rcode == SERVFAIL) {
- /* try next search element, if any */
- got_servfail++;
+ case NO_DATA:
+ got_nodata++;
+ /* FALLTHROUGH */
+ case HOST_NOT_FOUND:
+ /* keep trying */
break;
- }
- /* FALLTHROUGH */
- default:
- /* anything else implies that we're done */
- done++;
+ case TRY_AGAIN:
+ if (hp->rcode == SERVFAIL) {
+ /* try next search element, if any */
+ got_servfail++;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ /* anything else implies that we're done */
+ done++;
}
/*
* if we got here for some reason other than DNSRCH,
@@ -1342,10 +1330,10 @@ int res_search(name, class, type, answer, anslen)
* removing a trailing dot from name if domain is NULL.
*/
int res_querydomain(name, domain, class, type, answer, anslen)
- const char *name, *domain;
- int class, type; /* class and type of query */
- u_char *answer; /* buffer to put answer */
- int anslen; /* size of answer */
+ const char *name, *domain;
+ int class, type; /* class and type of query */
+ u_char *answer; /* buffer to put answer */
+ int anslen; /* size of answer */
{
char nbuf[MAXDNAME];
const char *longname = nbuf;
@@ -1359,7 +1347,7 @@ int res_querydomain(name, domain, class, type, answer, anslen)
#ifdef DEBUG
if (_res.options & RES_DEBUG)
printf(";; res_querydomain(%s, %s, %d, %d)\n",
- name, domain?domain:"<Nil>", class, type);
+ name, domain?domain:"<Nil>", class, type);
#endif
if (domain == NULL) {
/*
@@ -1400,11 +1388,11 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
static struct hostent h;
static char buf[
#ifndef __UCLIBC_HAS_IPV6__
- sizeof(struct in_addr) + sizeof(struct in_addr *)*2 +
+ sizeof(struct in_addr) + sizeof(struct in_addr *)*2 +
#else
- sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
+ sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
#endif /* __UCLIBC_HAS_IPV6__ */
- sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
+ sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
struct hostent *hp;
gethostbyaddr_r(addr, len, type, &h, buf, sizeof(buf), &hp, &h_errno);
@@ -1425,11 +1413,11 @@ void __open_etc_hosts(FILE **fp)
}
int __read_etc_hosts_r(FILE * fp, const char * name, int type,
- enum etc_hosts_action action,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+ enum etc_hosts_action action,
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
struct in_addr *in=NULL;
struct in_addr **addr_list=NULL;
@@ -1576,56 +1564,49 @@ int __read_etc_hosts_r(FILE * fp, const char * name, int type,
#ifdef L_gethostent
-#ifdef __UCLIBC_HAS_THREADS__
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK __pthread_mutex_lock(&mylock)
-# define UNLOCK __pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
static int __stay_open;
static FILE * __gethostent_fp;
void endhostent (void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
__stay_open = 0;
if (__gethostent_fp) {
- fclose(__gethostent_fp);
+ fclose(__gethostent_fp);
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
void sethostent (int stay_open)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
__stay_open = stay_open;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
int gethostent_r(struct hostent *result_buf, char *buf, size_t buflen,
- struct hostent **result, int *h_errnop)
+ struct hostent **result, int *h_errnop)
{
- int ret;
+ int ret = 0;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (__gethostent_fp == NULL) {
- __open_etc_hosts(&__gethostent_fp);
- if (__gethostent_fp == NULL) {
- UNLOCK;
- *result=NULL;
- return 0;
- }
+ __open_etc_hosts(&__gethostent_fp);
+ if (__gethostent_fp == NULL) {
+ *result=NULL;
+ goto DONE;
+ }
}
ret = __read_etc_hosts_r(__gethostent_fp, NULL, AF_INET, GETHOSTENT,
- result_buf, buf, buflen, result, h_errnop);
+ result_buf, buf, buflen, result, h_errnop);
if (__stay_open==0) {
- fclose(__gethostent_fp);
+ fclose(__gethostent_fp);
}
- UNLOCK;
+ DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return(ret);
}
@@ -1634,17 +1615,17 @@ struct hostent *gethostent (void)
static struct hostent h;
static char buf[
#ifndef __UCLIBC_HAS_IPV6__
- sizeof(struct in_addr) + sizeof(struct in_addr *)*2 +
+ sizeof(struct in_addr) + sizeof(struct in_addr *)*2 +
#else
- sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
+ sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
#endif /* __UCLIBC_HAS_IPV6__ */
- sizeof(char *)*(ALIAS_DIM) +
- 80/*namebuffer*/ + 2/* margin */];
+ sizeof(char *)*(ALIAS_DIM) +
+ 80/*namebuffer*/ + 2/* margin */];
struct hostent *host;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
gethostent_r(&h, buf, sizeof(buf), &host, &h_errno);
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return(host);
}
#endif
@@ -1652,23 +1633,23 @@ struct hostent *gethostent (void)
#ifdef L_get_hosts_byname_r
int __get_hosts_byname_r(const char * name, int type,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
return(__read_etc_hosts_r(NULL, name, type, GET_HOSTS_BYNAME,
- result_buf, buf, buflen, result, h_errnop));
+ result_buf, buf, buflen, result, h_errnop));
}
#endif
#ifdef L_get_hosts_byaddr_r
int __get_hosts_byaddr_r(const char * addr, int len, int type,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
#ifndef __UCLIBC_HAS_IPV6__
char ipaddr[INET_ADDRSTRLEN];
@@ -1677,24 +1658,24 @@ int __get_hosts_byaddr_r(const char * addr, int len, int type,
#endif /* __UCLIBC_HAS_IPV6__ */
switch (type) {
- case AF_INET:
- if (len != sizeof(struct in_addr))
- return 0;
- break;
+ case AF_INET:
+ if (len != sizeof(struct in_addr))
+ return 0;
+ break;
#ifdef __UCLIBC_HAS_IPV6__
- case AF_INET6:
- if (len != sizeof(struct in6_addr))
- return 0;
- break;
+ case AF_INET6:
+ if (len != sizeof(struct in6_addr))
+ return 0;
+ break;
#endif /* __UCLIBC_HAS_IPV6__ */
- default:
- return 0;
+ default:
+ return 0;
}
inet_ntop(type, addr, ipaddr, sizeof(ipaddr));
return(__read_etc_hosts_r(NULL, ipaddr, type, GET_HOSTS_BYADDR,
- result_buf, buf, buflen, result, h_errnop));
+ result_buf, buf, buflen, result, h_errnop));
}
#endif
@@ -1705,8 +1686,8 @@ int __get_hosts_byaddr_r(const char * addr, int len, int type,
#endif /* min */
int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
- socklen_t hostlen, char *serv, socklen_t servlen,
- unsigned int flags)
+ socklen_t hostlen, char *serv, socklen_t servlen,
+ unsigned int flags)
{
int serrno = errno;
int ok = 0;
@@ -1720,167 +1701,167 @@ int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
return EAI_FAMILY;
switch (sa->sa_family) {
- case AF_LOCAL:
- break;
- case AF_INET:
- if (addrlen < sizeof (struct sockaddr_in))
- return EAI_FAMILY;
- break;
+ case AF_LOCAL:
+ break;
+ case AF_INET:
+ if (addrlen < sizeof (struct sockaddr_in))
+ return EAI_FAMILY;
+ break;
#ifdef __UCLIBC_HAS_IPV6__
- case AF_INET6:
- if (addrlen < sizeof (struct sockaddr_in6))
- return EAI_FAMILY;
- break;
+ case AF_INET6:
+ if (addrlen < sizeof (struct sockaddr_in6))
+ return EAI_FAMILY;
+ break;
#endif /* __UCLIBC_HAS_IPV6__ */
- default:
- return EAI_FAMILY;
+ default:
+ return EAI_FAMILY;
}
if (host != NULL && hostlen > 0)
switch (sa->sa_family) {
- case AF_INET:
+ case AF_INET:
#ifdef __UCLIBC_HAS_IPV6__
- case AF_INET6:
+ case AF_INET6:
#endif /* __UCLIBC_HAS_IPV6__ */
- if (!(flags & NI_NUMERICHOST)) {
+ if (!(flags & NI_NUMERICHOST)) {
#ifdef __UCLIBC_HAS_IPV6__
- if (sa->sa_family == AF_INET6)
- h = gethostbyaddr ((const void *)
- &(((const struct sockaddr_in6 *) sa)->sin6_addr),
- sizeof(struct in6_addr), AF_INET6);
- else
+ if (sa->sa_family == AF_INET6)
+ h = gethostbyaddr ((const void *)
+ &(((const struct sockaddr_in6 *) sa)->sin6_addr),
+ sizeof(struct in6_addr), AF_INET6);
+ else
#endif /* __UCLIBC_HAS_IPV6__ */
- h = gethostbyaddr ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
- sizeof(struct in_addr), AF_INET);
-
- if (h) {
- char *c;
- if ((flags & NI_NOFQDN)
- && (getdomainname (domain, sizeof(domain)) == 0)
- && (c = strstr (h->h_name, domain))
- && (c != h->h_name) && (*(--c) == '.')) {
- strncpy (host, h->h_name,
- min(hostlen, (size_t) (c - h->h_name)));
- host[min(hostlen - 1, (size_t) (c - h->h_name))] = '\0';
- ok = 1;
- } else {
- strncpy (host, h->h_name, hostlen);
- ok = 1;
+ h = gethostbyaddr ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
+ sizeof(struct in_addr), AF_INET);
+
+ if (h) {
+ char *c;
+ if ((flags & NI_NOFQDN)
+ && (getdomainname (domain, sizeof(domain)) == 0)
+ && (c = strstr (h->h_name, domain))
+ && (c != h->h_name) && (*(--c) == '.')) {
+ strncpy (host, h->h_name,
+ min(hostlen, (size_t) (c - h->h_name)));
+ host[min(hostlen - 1, (size_t) (c - h->h_name))] = '\0';
+ ok = 1;
+ } else {
+ strncpy (host, h->h_name, hostlen);
+ ok = 1;
+ }
}
- }
- }
+ }
- if (!ok) {
- if (flags & NI_NAMEREQD) {
- errno = serrno;
- return EAI_NONAME;
- } else {
- const char *c;
+ if (!ok) {
+ if (flags & NI_NAMEREQD) {
+ errno = serrno;
+ return EAI_NONAME;
+ } else {
+ const char *c;
#ifdef __UCLIBC_HAS_IPV6__
- if (sa->sa_family == AF_INET6) {
- const struct sockaddr_in6 *sin6p;
+ if (sa->sa_family == AF_INET6) {
+ const struct sockaddr_in6 *sin6p;
- sin6p = (const struct sockaddr_in6 *) sa;
+ sin6p = (const struct sockaddr_in6 *) sa;
- c = inet_ntop (AF_INET6,
- (const void *) &sin6p->sin6_addr, host, hostlen);
+ c = inet_ntop (AF_INET6,
+ (const void *) &sin6p->sin6_addr, host, hostlen);
#if 0
- /* Does scope id need to be supported? */
- uint32_t scopeid;
- scopeid = sin6p->sin6_scope_id;
- if (scopeid != 0) {
- /* Buffer is >= IFNAMSIZ+1. */
- char scopebuf[IFNAMSIZ + 1];
- char *scopeptr;
- int ni_numericscope = 0;
- size_t real_hostlen = __strnlen (host, hostlen);
- size_t scopelen = 0;
-
- scopebuf[0] = SCOPE_DELIMITER;
- scopebuf[1] = '\0';
- scopeptr = &scopebuf[1];
-
- if (IN6_IS_ADDR_LINKLOCAL (&sin6p->sin6_addr)
- || IN6_IS_ADDR_MC_LINKLOCAL (&sin6p->sin6_addr)) {
- if (if_indextoname (scopeid, scopeptr) == NULL)
+ /* Does scope id need to be supported? */
+ uint32_t scopeid;
+ scopeid = sin6p->sin6_scope_id;
+ if (scopeid != 0) {
+ /* Buffer is >= IFNAMSIZ+1. */
+ char scopebuf[IFNAMSIZ + 1];
+ char *scopeptr;
+ int ni_numericscope = 0;
+ size_t real_hostlen = __strnlen (host, hostlen);
+ size_t scopelen = 0;
+
+ scopebuf[0] = SCOPE_DELIMITER;
+ scopebuf[1] = '\0';
+ scopeptr = &scopebuf[1];
+
+ if (IN6_IS_ADDR_LINKLOCAL (&sin6p->sin6_addr)
+ || IN6_IS_ADDR_MC_LINKLOCAL (&sin6p->sin6_addr)) {
+ if (if_indextoname (scopeid, scopeptr) == NULL)
+ ++ni_numericscope;
+ else
+ scopelen = strlen (scopebuf);
+ } else {
++ni_numericscope;
- else
- scopelen = strlen (scopebuf);
- } else {
- ++ni_numericscope;
+ }
+
+ if (ni_numericscope)
+ scopelen = 1 + snprintf (scopeptr,
+ (scopebuf
+ + sizeof scopebuf
+ - scopeptr),
+ "%u", scopeid);
+
+ if (real_hostlen + scopelen + 1 > hostlen)
+ return EAI_SYSTEM;
+ memcpy (host + real_hostlen, scopebuf, scopelen + 1);
}
-
- if (ni_numericscope)
- scopelen = 1 + snprintf (scopeptr,
- (scopebuf
- + sizeof scopebuf
- - scopeptr),
- "%u", scopeid);
-
- if (real_hostlen + scopelen + 1 > hostlen)
- return EAI_SYSTEM;
- memcpy (host + real_hostlen, scopebuf, scopelen + 1);
- }
#endif
- } else
+ } else
#endif /* __UCLIBC_HAS_IPV6__ */
- c = inet_ntop (AF_INET, (const void *)
- &(((const struct sockaddr_in *) sa)->sin_addr),
- host, hostlen);
+ c = inet_ntop (AF_INET, (const void *)
+ &(((const struct sockaddr_in *) sa)->sin_addr),
+ host, hostlen);
- if (c == NULL) {
- errno = serrno;
- return EAI_SYSTEM;
+ if (c == NULL) {
+ errno = serrno;
+ return EAI_SYSTEM;
+ }
}
+ ok = 1;
}
- ok = 1;
- }
- break;
+ break;
- case AF_LOCAL:
- if (!(flags & NI_NUMERICHOST)) {
- struct utsname utsname;
+ case AF_LOCAL:
+ if (!(flags & NI_NUMERICHOST)) {
+ struct utsname utsname;
- if (!uname (&utsname)) {
- strncpy (host, utsname.nodename, hostlen);
- break;
+ if (!uname (&utsname)) {
+ strncpy (host, utsname.nodename, hostlen);
+ break;
+ };
};
- };
- if (flags & NI_NAMEREQD) {
- errno = serrno;
- return EAI_NONAME;
- }
+ if (flags & NI_NAMEREQD) {
+ errno = serrno;
+ return EAI_NONAME;
+ }
- strncpy (host, "localhost", hostlen);
- break;
+ strncpy (host, "localhost", hostlen);
+ break;
- default:
- return EAI_FAMILY;
- }
+ default:
+ return EAI_FAMILY;
+ }
if (serv && (servlen > 0)) {
switch (sa->sa_family) {
- case AF_INET:
+ case AF_INET:
#ifdef __UCLIBC_HAS_IPV6__
- case AF_INET6:
+ case AF_INET6:
#endif /* __UCLIBC_HAS_IPV6__ */
- if (!(flags & NI_NUMERICSERV)) {
- struct servent *s;
- s = getservbyport (((const struct sockaddr_in *) sa)->sin_port,
- ((flags & NI_DGRAM) ? "udp" : "tcp"));
- if (s) {
- strncpy (serv, s->s_name, servlen);
- break;
+ if (!(flags & NI_NUMERICSERV)) {
+ struct servent *s;
+ s = getservbyport (((const struct sockaddr_in *) sa)->sin_port,
+ ((flags & NI_DGRAM) ? "udp" : "tcp"));
+ if (s) {
+ strncpy (serv, s->s_name, servlen);
+ break;
+ }
}
- }
- snprintf (serv, servlen, "%d",
- ntohs (((const struct sockaddr_in *) sa)->sin_port));
- break;
+ snprintf (serv, servlen, "%d",
+ ntohs (((const struct sockaddr_in *) sa)->sin_port));
+ break;
- case AF_LOCAL:
- strncpy (serv, ((const struct sockaddr_un *) sa)->sun_path, servlen);
- break;
+ case AF_LOCAL:
+ strncpy (serv, ((const struct sockaddr_un *) sa)->sun_path, servlen);
+ break;
}
}
if (host && (hostlen > 0))
@@ -1896,10 +1877,10 @@ int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
#ifdef L_gethostbyname_r
int gethostbyname_r(const char * name,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
struct in_addr *in;
struct in_addr **addr_list;
@@ -1921,7 +1902,7 @@ int gethostbyname_r(const char * name,
__set_errno(0); /* to check for missing /etc/hosts. */
if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
- buf, buflen, result, h_errnop))==0)
+ buf, buflen, result, h_errnop))==0)
return i;
switch (*h_errnop) {
case HOST_NOT_FOUND:
@@ -1983,60 +1964,60 @@ int gethostbyname_r(const char * name,
for (;;) {
- BIGLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
__nameserversXX=__nameservers;
__nameserverXX=__nameserver;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
a.buf = buf;
a.buflen = buflen;
a.add_count = 0;
i = __dns_lookup(name, T_A, __nameserversXX, __nameserverXX, &packet, &a);
if (i < 0) {
- *h_errnop = HOST_NOT_FOUND;
- DPRINTF("__dns_lookup\n");
- return TRY_AGAIN;
+ *h_errnop = HOST_NOT_FOUND;
+ DPRINTF("__dns_lookup\n");
+ return TRY_AGAIN;
}
if ((a.rdlength + sizeof(struct in_addr*)) * a.add_count + 256 > buflen)
- {
- free(a.dotted);
- free(packet);
- *h_errnop = NETDB_INTERNAL;
- DPRINTF("buffer too small for all addresses\n");
- return ERANGE;
- }
+ {
+ free(a.dotted);
+ free(packet);
+ *h_errnop = NETDB_INTERNAL;
+ DPRINTF("buffer too small for all addresses\n");
+ return ERANGE;
+ }
else if(a.add_count > 0)
- {
- memmove(buf - sizeof(struct in_addr*)*2, buf, a.add_count * a.rdlength);
- addr_list = (struct in_addr**)(buf + a.add_count * a.rdlength);
- addr_list[0] = in;
- for (i = a.add_count-1; i>=0; --i)
- addr_list[i+1] = (struct in_addr*)(buf - sizeof(struct in_addr*)*2 + a.rdlength * i);
- addr_list[a.add_count + 1] = 0;
- buflen -= (((char*)&(addr_list[a.add_count + 2])) - buf);
- buf = (char*)&addr_list[a.add_count + 2];
- }
+ {
+ memmove(buf - sizeof(struct in_addr*)*2, buf, a.add_count * a.rdlength);
+ addr_list = (struct in_addr**)(buf + a.add_count * a.rdlength);
+ addr_list[0] = in;
+ for (i = a.add_count-1; i>=0; --i)
+ addr_list[i+1] = (struct in_addr*)(buf - sizeof(struct in_addr*)*2 + a.rdlength * i);
+ addr_list[a.add_count + 1] = 0;
+ buflen -= (((char*)&(addr_list[a.add_count + 2])) - buf);
+ buf = (char*)&addr_list[a.add_count + 2];
+ }
strncpy(buf, a.dotted, buflen);
free(a.dotted);
if (a.atype == T_A) { /* ADDRESS */
- memcpy(in, a.rdata, sizeof(*in));
- result_buf->h_name = buf;
- result_buf->h_addrtype = AF_INET;
- result_buf->h_length = sizeof(*in);
- result_buf->h_addr_list = (char **) addr_list;
+ memcpy(in, a.rdata, sizeof(*in));
+ result_buf->h_name = buf;
+ result_buf->h_addrtype = AF_INET;
+ result_buf->h_length = sizeof(*in);
+ result_buf->h_addr_list = (char **) addr_list;
#ifdef __UCLIBC_MJN3_ONLY__
#warning TODO -- generate the full list
#endif
- result_buf->h_aliases = alias; /* TODO: generate the full list */
- free(packet);
- break;
+ result_buf->h_aliases = alias; /* TODO: generate the full list */
+ free(packet);
+ break;
} else {
- free(packet);
- *h_errnop=HOST_NOT_FOUND;
- return TRY_AGAIN;
+ free(packet);
+ *h_errnop=HOST_NOT_FOUND;
+ return TRY_AGAIN;
}
}
@@ -2049,14 +2030,14 @@ int gethostbyname_r(const char * name,
#ifdef L_gethostbyname2_r
int gethostbyname2_r(const char *name, int family,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
#ifndef __UCLIBC_HAS_IPV6__
return family == (AF_INET)? gethostbyname_r(name, result_buf,
- buf, buflen, result, h_errnop) : HOST_NOT_FOUND;
+ buf, buflen, result, h_errnop) : HOST_NOT_FOUND;
#else /* __UCLIBC_HAS_IPV6__ */
struct in6_addr *in;
struct in6_addr **addr_list;
@@ -2084,7 +2065,7 @@ int gethostbyname2_r(const char *name, int family,
__set_errno(0); /* to check for missing /etc/hosts. */
if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
- buf, buflen, result, h_errnop))==0)
+ buf, buflen, result, h_errnop))==0)
return i;
switch (*h_errnop) {
case HOST_NOT_FOUND:
@@ -2137,10 +2118,10 @@ int gethostbyname2_r(const char *name, int family,
memset((char *) &a, '\0', sizeof(a));
for (;;) {
- BIGLOCK;
- __nameserversXX=__nameservers;
- __nameserverXX=__nameserver;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ __nameserversXX=__nameservers;
+ __nameserverXX=__nameserver;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
i = __dns_lookup(buf, T_AAAA, __nameserversXX, __nameserverXX, &packet, &a);
@@ -2190,10 +2171,10 @@ int gethostbyname2_r(const char *name, int family,
#ifdef L_gethostbyaddr_r
int gethostbyaddr_r (const void *addr, socklen_t len, int type,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
struct in_addr *in;
@@ -2235,7 +2216,7 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
/* do /etc/hosts first */
if ((i=__get_hosts_byaddr_r(addr, len, type, result_buf,
- buf, buflen, result, h_errnop))==0)
+ buf, buflen, result, h_errnop))==0)
return i;
switch (*h_errnop) {
case HOST_NOT_FOUND:
@@ -2301,7 +2282,7 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
addr_list[0] = in;
sprintf(buf, "%u.%u.%u.%u.in-addr.arpa",
- tmp_addr[3], tmp_addr[2], tmp_addr[1], tmp_addr[0]);
+ tmp_addr[3], tmp_addr[2], tmp_addr[1], tmp_addr[0]);
#ifdef __UCLIBC_HAS_IPV6__
} else {
memcpy(in6->s6_addr, addr, len);
@@ -2311,7 +2292,7 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
for (i = len - 1; i >= 0; i--) {
qp += sprintf(qp, "%x.%x.", in6->s6_addr[i] & 0xf,
- (in6->s6_addr[i] >> 4) & 0xf);
+ (in6->s6_addr[i] >> 4) & 0xf);
}
strcpy(qp, "ip6.int");
#endif /* __UCLIBC_HAS_IPV6__ */
@@ -2324,10 +2305,10 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
for (;;) {
- BIGLOCK;
- __nameserversXX=__nameservers;
- __nameserverXX=__nameserver;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ __nameserversXX=__nameservers;
+ __nameserverXX=__nameserver;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
i = __dns_lookup(buf, T_PTR, __nameserversXX, __nameserverXX, &packet, &a);
if (i < 0) {
@@ -2392,7 +2373,7 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
* Return size of compressed name or -1 if there was an error.
*/
int __dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
- char *dst, int dstsiz)
+ char *dst, int dstsiz)
{
int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
@@ -2412,7 +2393,7 @@ int __dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
*/
static int printable(int ch)
{
- return (ch > 0x20 && ch < 0x7f);
+ return (ch > 0x20 && ch < 0x7f);
}
/*
@@ -2424,18 +2405,18 @@ static int printable(int ch)
*/
static int special(int ch)
{
- switch (ch) {
+ switch (ch) {
case 0x22: /* '"' */
case 0x2E: /* '.' */
case 0x3B: /* ';' */
case 0x5C: /* '\\' */
- /* Special modifiers in zone files. */
+ /* Special modifiers in zone files. */
case 0x40: /* '@' */
case 0x24: /* '$' */
- return (1);
+ return (1);
default:
- return (0);
- }
+ return (0);
+ }
}
/*
@@ -2447,7 +2428,7 @@ static int special(int ch)
* Root domain returns as "." not "".
*/
int __ns_name_uncompress(const u_char *msg, const u_char *eom,
- const u_char *src, char *dst, size_t dstsiz)
+ const u_char *src, char *dst, size_t dstsiz)
{
u_char tmp[NS_MAXCDNAME];
int n;
@@ -2536,7 +2517,7 @@ int __ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
return (-1);
}
*dn++ = '\0';
- return (dn - dst);
+ return (dn - dst);
}
/*
@@ -2546,7 +2527,7 @@ int __ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
* -1 if it fails, or consumed octets if it succeeds.
*/
int __ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
- u_char *dst, size_t dstsiz)
+ u_char *dst, size_t dstsiz)
{
const u_char *srcp, *dstlim;
u_char *dstp;
@@ -2565,46 +2546,46 @@ int __ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
while ((n = *srcp++) != 0) {
/* Check for indirection. */
switch (n & NS_CMPRSFLGS) {
- case 0:
- /* Limit checks. */
- if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
- }
- checked += n + 1;
- *dstp++ = n;
- memcpy(dstp, srcp, n);
- dstp += n;
- srcp += n;
- break;
+ case 0:
+ /* Limit checks. */
+ if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ checked += n + 1;
+ *dstp++ = n;
+ memcpy(dstp, srcp, n);
+ dstp += n;
+ srcp += n;
+ break;
- case NS_CMPRSFLGS:
- if (srcp >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
- }
- if (len < 0)
- len = srcp - src + 1;
- srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
- if (srcp < msg || srcp >= eom) { /* Out of range. */
- __set_errno (EMSGSIZE);
- return (-1);
- }
- checked += 2;
- /*
- * Check for loops in the compressed name;
- * if we've looked at the whole message,
- * there must be a loop.
- */
- if (checked >= eom - msg) {
- __set_errno (EMSGSIZE);
- return (-1);
- }
- break;
+ case NS_CMPRSFLGS:
+ if (srcp >= eom) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ if (len < 0)
+ len = srcp - src + 1;
+ srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
+ if (srcp < msg || srcp >= eom) { /* Out of range. */
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ checked += 2;
+ /*
+ * Check for loops in the compressed name;
+ * if we've looked at the whole message,
+ * there must be a loop.
+ */
+ if (checked >= eom - msg) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ break;
- default:
- __set_errno (EMSGSIZE);
- return (-1); /* flag error */
+ default:
+ __set_errno (EMSGSIZE);
+ return (-1); /* flag error */
}
}
*dstp = '\0';