Makefile: Conditionalize IPV6 files and build some commands as .rel

At least ifconfig has "static" global C constructors and you have
to force the objects in.
This commit is contained in:
Joel Sherrill
2012-10-23 13:31:30 -05:00
parent cc2aec486d
commit 68e0948111
6 changed files with 314 additions and 37 deletions

View File

@@ -340,6 +340,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
break;
#else
he->h_name = bp;
#ifdef INET6
if (statp->options & RES_USE_INET6) {
n = strlen(bp) + 1; /* for the \0 */
if (n >= MAXHOSTNAMELEN) {
@@ -349,6 +350,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
bp += n;
_map_v4v6_hostent(he, &bp, ep);
}
#endif
RES_SET_H_ERRNO(statp, NETDB_SUCCESS);
return (0);
#endif
@@ -424,8 +426,10 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
he->h_name = bp;
bp += n;
}
#ifdef INET6
if (statp->options & RES_USE_INET6)
_map_v4v6_hostent(he, &bp, ep);
#endif
RES_SET_H_ERRNO(statp, NETDB_SUCCESS);
return (0);
}
@@ -699,11 +703,13 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap)
memcpy(hed->host_addr, uaddr, len);
hed->h_addr_ptrs[0] = (char *)hed->host_addr;
hed->h_addr_ptrs[1] = NULL;
#ifdef INET6
if (af == AF_INET && (statp->options & RES_USE_INET6)) {
_map_v4v6_address((char*)hed->host_addr, (char*)hed->host_addr);
he.h_addrtype = AF_INET6;
he.h_length = NS_IN6ADDRSZ;
}
#endif
if (__copy_hostent(&he, hptr, buffer, buflen) != 0) {
*errnop = errno;
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);

View File

@@ -115,6 +115,7 @@ gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped,
if (!(cp = strpbrk(p, " \t")))
goto again;
*cp++ = '\0';
#ifdef INET6
if (inet_pton(AF_INET6, p, hed->host_addr) > 0) {
af = AF_INET6;
len = IN6ADDRSZ;
@@ -131,6 +132,12 @@ gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped,
} else {
goto again;
}
#else
if (inet_pton(AF_INET, p, hed->host_addr) > 0) {
af = AF_INET;
len = INADDRSZ;
}
#endif
hed->h_addr_ptrs[0] = (char *)hed->host_addr;
hed->h_addr_ptrs[1] = NULL;
he->h_addr_list = hed->h_addr_ptrs;
@@ -193,8 +200,10 @@ gethostent_r(struct hostent *hptr, char *buffer, size_t buflen,
*h_errnop = statp->res_h_errno;
return (-1);
}
#ifdef INET6
if (gethostent_p(&he, hed, statp->options & RES_USE_INET6, statp) != 0)
return (-1);
#endif
if (__copy_hostent(&he, hptr, buffer, buflen) != 0) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
@@ -254,12 +263,14 @@ _ht_gethostbyname(void *rval, void *cb_data, va_list ap)
while ((error = gethostent_p(&he, hed, 0, statp)) == 0) {
if (he.h_addrtype != af)
continue;
#ifdef INET6
if (he.h_addrtype == AF_INET &&
statp->options & RES_USE_INET6) {
_map_v4v6_address(he.h_addr, he.h_addr);
he.h_length = IN6ADDRSZ;
he.h_addrtype = AF_INET6;
}
#endif
if (strcasecmp(he.h_name, name) == 0)
break;
for (cp = he.h_aliases; *cp != 0; cp++)
@@ -317,6 +328,7 @@ _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap)
_sethosthtent(0, hed);
while ((error = gethostent_p(&he, hed, 0, statp)) == 0)
#ifdef INET6
if (he.h_addrtype == af && !bcmp(he.h_addr, addr, len)) {
if (he.h_addrtype == AF_INET &&
statp->options & RES_USE_INET6) {
@@ -326,6 +338,7 @@ _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap)
}
break;
}
#endif
_endhosthtent(hed);
if (error != 0)

View File

@@ -458,19 +458,23 @@ fakeaddr(const char *name, int af, struct hostent *hp, char *buf,
}
strncpy(hed->hostbuf, name, MAXDNAME);
hed->hostbuf[MAXDNAME] = '\0';
#ifdef INET6
if (af == AF_INET && (statp->options & RES_USE_INET6) != 0U) {
_map_v4v6_address((char *)hed->host_addr,
(char *)hed->host_addr);
af = AF_INET6;
}
#endif
he.h_addrtype = af;
switch(af) {
case AF_INET:
he.h_length = NS_INADDRSZ;
break;
#ifdef INET6
case AF_INET6:
he.h_length = NS_IN6ADDRSZ;
break;
#endif
default:
errno = EAFNOSUPPORT;
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);