Resolve conflicts after import of ISC BIND 8.3.2-T1B.
This commit is contained in:
parent
0f9cfbb030
commit
8803a0eeb7
@ -98,6 +98,7 @@ static char sccsid[] = "@(#)commands.l 5.13 (Berkeley) 7/24/90";
|
||||
#include <netinet/in.h>
|
||||
#include <histedit.h>
|
||||
#include "port_after.h"
|
||||
#include <resolv.h>
|
||||
#include "res.h"
|
||||
|
||||
extern char rootServerName[];
|
||||
@ -160,9 +161,9 @@ nslookup_yy_input(buf, result, max_size, intr)
|
||||
|
||||
%}
|
||||
WS [ \t]
|
||||
FLET [A-Za-z0-9.*\\_]
|
||||
LET [A-Za-z0-9.*_]
|
||||
NAME [A-Za-z0-9.*=_/-]
|
||||
FLET [:A-Za-z0-9.*\\_]
|
||||
LET [:A-Za-z0-9.*_]
|
||||
NAME [:A-Za-z0-9.*=_/-]
|
||||
%%
|
||||
^{WS}*server{WS}+{LET}{NAME}*{WS}*$ {
|
||||
/*
|
||||
|
@ -54,7 +54,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static const char sccsid[] = "@(#)getinfo.c 5.26 (Berkeley) 3/21/91";
|
||||
static const char rcsid[] = "$Id: getinfo.c,v 8.20 2001/06/20 12:30:33 marka Exp $";
|
||||
static const char rcsid[] = "$Id: getinfo.c,v 8.23 2002/04/29 01:11:52 marka Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -80,16 +80,19 @@ static const char rcsid[] = "$Id: getinfo.c,v 8.20 2001/06/20 12:30:33 marka Exp
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "port_after.h"
|
||||
|
||||
#include <resolv.h>
|
||||
|
||||
#include "res.h"
|
||||
|
||||
static char *addr_list[MAXADDRS + 1];
|
||||
static int addr_len[MAXADDRS + 1];
|
||||
static int addr_type[MAXADDRS + 1];
|
||||
|
||||
static char *host_aliases[MAXALIASES];
|
||||
static int host_aliases_len[MAXALIASES];
|
||||
@ -100,6 +103,8 @@ typedef struct {
|
||||
char *domain[MAXDOMAINS];
|
||||
int numDomains;
|
||||
char *address[MAXADDRS];
|
||||
char len[MAXADDRS];
|
||||
char type[MAXADDRS];
|
||||
int numAddresses;
|
||||
} ServerTable;
|
||||
|
||||
@ -137,14 +142,16 @@ typedef union {
|
||||
*/
|
||||
|
||||
static int
|
||||
GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
struct in_addr *nsAddrPtr;
|
||||
GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer,
|
||||
merge)
|
||||
union res_sockaddr_union *nsAddrPtr;
|
||||
char *msg;
|
||||
int queryType;
|
||||
int msglen;
|
||||
Boolean iquery;
|
||||
register HostInfo *hostPtr;
|
||||
Boolean isServer;
|
||||
Boolean merge;
|
||||
{
|
||||
register HEADER *headerPtr;
|
||||
register const u_char *cp;
|
||||
@ -152,6 +159,8 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
char **aliasPtr;
|
||||
u_char *eom, *bp;
|
||||
char **addrPtr;
|
||||
int *lenPtr;
|
||||
int *typePtr;
|
||||
char *namePtr;
|
||||
char *dnamePtr;
|
||||
int type, class;
|
||||
@ -159,19 +168,26 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
int origClass = 0;
|
||||
int numAliases = 0;
|
||||
int numAddresses = 0;
|
||||
int n, i, j;
|
||||
int n, i, j, k, l, m;
|
||||
int dlen;
|
||||
int status;
|
||||
int numServers;
|
||||
size_t s;
|
||||
Boolean haveAnswer;
|
||||
Boolean printedAnswers = FALSE;
|
||||
int oldAliases;
|
||||
char **newAliases;
|
||||
int oldServers;
|
||||
ServerInfo **newServers;
|
||||
int oldAddresses;
|
||||
AddrInfo **newAddresses;
|
||||
|
||||
|
||||
/*
|
||||
* If the hostPtr was used before, free up the calloc'd areas.
|
||||
*/
|
||||
FreeHostInfoPtr(hostPtr);
|
||||
if (!merge)
|
||||
FreeHostInfoPtr(hostPtr);
|
||||
|
||||
status = SendRequest(nsAddrPtr, (u_char *)msg, msglen, (u_char *) &answer,
|
||||
sizeof(answer), &n);
|
||||
@ -219,6 +235,8 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
|
||||
aliasPtr = host_aliases;
|
||||
addrPtr = addr_list;
|
||||
lenPtr = addr_len;
|
||||
typePtr = addr_type;
|
||||
haveAnswer = FALSE;
|
||||
|
||||
/*
|
||||
@ -235,7 +253,8 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
printf("Non-authoritative answer:\n");
|
||||
}
|
||||
|
||||
if (queryType != T_A && !(iquery && queryType == T_PTR)) {
|
||||
if (queryType != T_A && queryType != T_AAAA && /* A6? */
|
||||
!(iquery && queryType == T_PTR)) {
|
||||
while (--ancount >= 0 && cp < eom) {
|
||||
if ((cp = Print_rr(cp, (u_char *)&answer,
|
||||
eom, stdout)) == NULL) {
|
||||
@ -287,36 +306,34 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
memcpy(hostPtr->name, bp, s);
|
||||
haveAnswer = TRUE;
|
||||
break;
|
||||
} else if (type != T_A) {
|
||||
} else if (type != T_A && type != T_AAAA) {
|
||||
cp += dlen;
|
||||
continue;
|
||||
}
|
||||
if (dlen != INADDRSZ)
|
||||
if (type == T_A && dlen != INADDRSZ)
|
||||
return (ERROR);
|
||||
if (type == T_AAAA && dlen != 16)
|
||||
return (ERROR);
|
||||
if (haveAnswer) {
|
||||
/*
|
||||
* If we've already got 1 address, we aren't interested
|
||||
* in addresses with a different length or class.
|
||||
* in addresses with a different class.
|
||||
*/
|
||||
if (dlen != hostPtr->addrLen) {
|
||||
cp += dlen;
|
||||
continue;
|
||||
}
|
||||
if (class != origClass) {
|
||||
cp += dlen;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* First address: record its length and class so we
|
||||
* only save additonal ones with the same attributes.
|
||||
* First address: record its class so we only save
|
||||
* additonal ones with the same attributes.
|
||||
*/
|
||||
hostPtr->addrLen = dlen;
|
||||
origClass = class;
|
||||
hostPtr->addrType = (class == C_IN) ? AF_INET : AF_UNSPEC;
|
||||
s = strlen((char *)bp) + 1;
|
||||
hostPtr->name = Calloc(1, s);
|
||||
memcpy(hostPtr->name, bp, s);
|
||||
if (hostPtr->name == NULL) {
|
||||
s = strlen((char *)bp) + 1;
|
||||
hostPtr->name = Calloc(1, s);
|
||||
memcpy(hostPtr->name, bp, s);
|
||||
}
|
||||
}
|
||||
bp += (((u_long)bp) % sizeof(align));
|
||||
|
||||
@ -332,6 +349,10 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
continue;
|
||||
}
|
||||
memcpy(*addrPtr++ = (char *)bp, cp, dlen);
|
||||
*lenPtr++ = dlen;
|
||||
*typePtr++ = (class == C_IN) ?
|
||||
((type == T_A) ? AF_INET : AF_INET6) :
|
||||
AF_UNSPEC;
|
||||
bp += dlen;
|
||||
cp += dlen;
|
||||
numAddresses++;
|
||||
@ -347,24 +368,70 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
* in the hostPtr variable.
|
||||
*/
|
||||
|
||||
oldAliases = 0;
|
||||
if (merge && hostPtr->aliases != NULL) {
|
||||
while (hostPtr->aliases[oldAliases] != NULL)
|
||||
oldAliases++;
|
||||
}
|
||||
if (numAliases > 0) {
|
||||
hostPtr->aliases =
|
||||
(char **) Calloc(1 + numAliases, sizeof(char *));
|
||||
for (i = 0; i < numAliases; i++) {
|
||||
hostPtr->aliases[i] = Calloc(1, host_aliases_len[i]);
|
||||
memcpy(hostPtr->aliases[i], host_aliases[i],
|
||||
host_aliases_len[i]);
|
||||
newAliases =
|
||||
(char **) Calloc(1 + numAliases + oldAliases, sizeof(char *));
|
||||
if (merge && hostPtr->aliases != NULL) {
|
||||
memcpy(newAliases, hostPtr->aliases,
|
||||
oldAliases * sizeof(char *));
|
||||
free(hostPtr->aliases);
|
||||
}
|
||||
hostPtr->aliases[i] = NULL;
|
||||
hostPtr->aliases = newAliases;
|
||||
k = oldAliases;
|
||||
for (i = 0; i < numAliases; i++) {
|
||||
for (l = 0; l < k; l++)
|
||||
if (!strcasecmp(hostPtr->aliases[l], host_aliases[i]))
|
||||
break;
|
||||
if (l < k) {
|
||||
free(host_aliases[i]);
|
||||
continue;
|
||||
}
|
||||
hostPtr->aliases[k] = Calloc(1, host_aliases_len[i]);
|
||||
memcpy(hostPtr->aliases[k], host_aliases[i],
|
||||
host_aliases_len[i]);
|
||||
k++;
|
||||
}
|
||||
hostPtr->aliases[k] = NULL;
|
||||
}
|
||||
oldAddresses = 0;
|
||||
if (merge && hostPtr->addrList != NULL) {
|
||||
while (hostPtr->addrList[oldAddresses] != NULL)
|
||||
oldAddresses++;
|
||||
}
|
||||
if (numAddresses > 0) {
|
||||
hostPtr->addrList =
|
||||
(char **)Calloc(1+numAddresses, sizeof(char *));
|
||||
for (i = 0; i < numAddresses; i++) {
|
||||
hostPtr->addrList[i] = Calloc(1, hostPtr->addrLen);
|
||||
memcpy(hostPtr->addrList[i], addr_list[i], hostPtr->addrLen);
|
||||
newAddresses =
|
||||
(AddrInfo **)Calloc(1+numAddresses, sizeof(AddrInfo *));
|
||||
if (merge && hostPtr->addrList != NULL) {
|
||||
memcpy(newAddresses, hostPtr->addrList,
|
||||
oldAddresses * sizeof(char *));
|
||||
free(hostPtr->addrList);
|
||||
}
|
||||
hostPtr->addrList[i] = NULL;
|
||||
hostPtr->addrList = newAddresses;
|
||||
k = oldAddresses;
|
||||
for (i = 0; i < numAddresses; i++) {
|
||||
for (l = 0; l < k; l++)
|
||||
if (hostPtr->addrList[l]->addrType == addr_type[i] &&
|
||||
hostPtr->addrList[l]->addrLen == addr_len[i] &&
|
||||
!memcmp(hostPtr->addrList[l]->addr, addr_list[i],
|
||||
addr_len[i]))
|
||||
break;
|
||||
if (l < k) {
|
||||
free(addr_list[i]);
|
||||
continue;
|
||||
}
|
||||
hostPtr->addrList[k] = (AddrInfo*)Calloc(1, sizeof(AddrInfo));
|
||||
hostPtr->addrList[k]->addr = Calloc(1, addr_len[i]);
|
||||
hostPtr->addrList[k]->addrType = addr_type[i];
|
||||
hostPtr->addrList[k]->addrLen = addr_len[i];
|
||||
memcpy(hostPtr->addrList[k]->addr, addr_list[i], addr_len[i]);
|
||||
k++;
|
||||
}
|
||||
hostPtr->addrList[k] = NULL;
|
||||
}
|
||||
#ifdef verbose
|
||||
if (headerPtr->aa || nscount == 0) {
|
||||
@ -383,7 +450,8 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
* in the additional resource records part.
|
||||
*/
|
||||
|
||||
if (!headerPtr->aa && (queryType != T_A) && (nscount > 0 || arcount > 0)) {
|
||||
if (!headerPtr->aa && (queryType != T_A) && (queryType != T_AAAA) &&
|
||||
(nscount > 0 || arcount > 0)) {
|
||||
if (printedAnswers) {
|
||||
putchar('\n');
|
||||
}
|
||||
@ -393,7 +461,7 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
cp = res_skip((u_char *)&answer, 2, eom);
|
||||
|
||||
numServers = 0;
|
||||
if (queryType != T_A) {
|
||||
if (queryType != T_A && queryType != T_AAAA) {
|
||||
/*
|
||||
* If we don't need to save the record, just print it.
|
||||
*/
|
||||
@ -447,7 +515,7 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
*/
|
||||
found = FALSE;
|
||||
for (j = 0; j < numServers; j++) {
|
||||
if (strcmp(namePtr, server[j].name) == 0) {
|
||||
if (strcasecmp(namePtr, server[j].name) == 0) {
|
||||
found = TRUE;
|
||||
free(namePtr);
|
||||
break;
|
||||
@ -503,20 +571,25 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
if (cp + dlen > eom)
|
||||
return (ERROR);
|
||||
|
||||
if (type != T_A) {
|
||||
if (type != T_A && type != T_AAAA) {
|
||||
cp += dlen;
|
||||
continue;
|
||||
} else {
|
||||
if (dlen != INADDRSZ)
|
||||
if (type == T_A && dlen != INADDRSZ)
|
||||
return (ERROR);
|
||||
if (type == T_AAAA && dlen != 16)
|
||||
return (ERROR);
|
||||
for (j = 0; j < numServers; j++) {
|
||||
if (strcmp((char *)bp, server[j].name) == 0) {
|
||||
if (strcasecmp((char *)bp, server[j].name) == 0) {
|
||||
server[j].numAddresses++;
|
||||
if (server[j].numAddresses <= MAXADDRS) {
|
||||
server[j].address[server[j].numAddresses-1] =
|
||||
Calloc(1,dlen);
|
||||
memcpy(server[j].address[server[j].numAddresses-1],
|
||||
cp, dlen);
|
||||
server[j].len[server[j].numAddresses-1] = dlen;
|
||||
server[j].type[server[j].numAddresses-1] =
|
||||
(type == T_A) ? AF_INET : AF_INET6;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -529,35 +602,88 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
/*
|
||||
* If we are returning name server info, transfer it to the hostPtr.
|
||||
*/
|
||||
oldServers = 0;
|
||||
if (merge && hostPtr->servers != NULL) {
|
||||
while (hostPtr->servers[oldServers] != NULL)
|
||||
oldServers++;
|
||||
}
|
||||
if (numServers > 0) {
|
||||
hostPtr->servers = (ServerInfo **)
|
||||
Calloc(numServers+1, sizeof(ServerInfo *));
|
||||
|
||||
for (i = 0; i < numServers; i++) {
|
||||
hostPtr->servers[i] = (ServerInfo *) Calloc(1, sizeof(ServerInfo));
|
||||
hostPtr->servers[i]->name = server[i].name;
|
||||
|
||||
|
||||
hostPtr->servers[i]->domains = (char **)
|
||||
Calloc(server[i].numDomains+1,sizeof(char *));
|
||||
for (j = 0; j < server[i].numDomains; j++) {
|
||||
hostPtr->servers[i]->domains[j] = server[i].domain[j];
|
||||
}
|
||||
hostPtr->servers[i]->domains[j] = NULL;
|
||||
|
||||
|
||||
hostPtr->servers[i]->addrList = (char **)
|
||||
Calloc(server[i].numAddresses+1,sizeof(char *));
|
||||
for (j = 0; j < server[i].numAddresses; j++) {
|
||||
hostPtr->servers[i]->addrList[j] = server[i].address[j];
|
||||
}
|
||||
hostPtr->servers[i]->addrList[j] = NULL;
|
||||
|
||||
newServers = (ServerInfo **) Calloc(numServers+oldServers+1,
|
||||
sizeof(ServerInfo *));
|
||||
if (merge && hostPtr->servers != NULL) {
|
||||
memcpy(newServers, hostPtr->servers,
|
||||
oldServers * sizeof(ServerInfo *));
|
||||
free(hostPtr->servers);
|
||||
}
|
||||
hostPtr->servers[i] = NULL;
|
||||
hostPtr->servers = newServers;
|
||||
k = oldServers;
|
||||
for (i = 0; i < numServers; i++) {
|
||||
for (l = 0; l < k; l++)
|
||||
if (!strcasecmp(hostPtr->servers[l]->name, server[i].name))
|
||||
break;
|
||||
if (l < k) {
|
||||
free(server[i].name);
|
||||
for (j = 0; j < server[i].numDomains; j++)
|
||||
free(server[i].domain[j]);
|
||||
} else {
|
||||
hostPtr->servers[l] = (ServerInfo *)
|
||||
Calloc(1, sizeof(ServerInfo));
|
||||
hostPtr->servers[l]->name = server[i].name;
|
||||
k++;
|
||||
|
||||
hostPtr->servers[l]->domains = (char **)
|
||||
Calloc(server[i].numDomains+1,sizeof(char *));
|
||||
for (j = 0; j < server[i].numDomains; j++) {
|
||||
hostPtr->servers[l]->domains[j] = server[i].domain[j];
|
||||
}
|
||||
hostPtr->servers[l]->domains[j] = NULL;
|
||||
}
|
||||
|
||||
|
||||
oldAddresses = 0;
|
||||
if (merge && hostPtr->servers[l]->addrList != NULL)
|
||||
while (hostPtr->servers[l]->addrList[oldAddresses] != NULL)
|
||||
oldAddresses++;
|
||||
newAddresses = (AddrInfo **)
|
||||
Calloc(server[i].numAddresses+oldAddresses+1,
|
||||
sizeof(AddrInfo *));
|
||||
if (merge && hostPtr->servers[l]->addrList != NULL) {
|
||||
memcpy(newAddresses, hostPtr->servers[l]->addrList,
|
||||
sizeof(AddrInfo *) * oldAddresses);
|
||||
free(hostPtr->servers[l]->addrList);
|
||||
}
|
||||
hostPtr->servers[l]->addrList = newAddresses;
|
||||
m = oldAddresses;
|
||||
for (j = 0; j < server[l].numAddresses; j++) {
|
||||
for (n = 0; n < m; n++)
|
||||
if (hostPtr->servers[l]->addrList[n]->addrType ==
|
||||
server[i].type[j] &&
|
||||
hostPtr->servers[l]->addrList[n]->addrLen ==
|
||||
server[i].len[j] &&
|
||||
!memcmp(hostPtr->servers[l]->addrList[n]->addr,
|
||||
server[i].address[j], server[i].len[j]))
|
||||
break;
|
||||
if (n < m) {
|
||||
free(server[i].address[j]);
|
||||
continue;
|
||||
}
|
||||
hostPtr->servers[l]->addrList[m] =
|
||||
(AddrInfo*)Calloc(1, sizeof(AddrInfo));
|
||||
hostPtr->servers[l]->addrList[m]->addr =
|
||||
server[i].address[j];
|
||||
hostPtr->servers[l]->addrList[m]->addrType =
|
||||
server[i].type[j];
|
||||
hostPtr->servers[l]->addrList[m]->addrLen =
|
||||
server[i].len[j];
|
||||
m++;
|
||||
}
|
||||
hostPtr->servers[l]->addrList[m] = NULL;
|
||||
}
|
||||
hostPtr->servers[k] = NULL;
|
||||
}
|
||||
|
||||
switch (queryType) {
|
||||
case T_AAAA:
|
||||
case T_A:
|
||||
return NONAUTH;
|
||||
case T_PTR:
|
||||
@ -587,20 +713,22 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
|
||||
*/
|
||||
|
||||
int
|
||||
GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer)
|
||||
struct in_addr *nsAddrPtr;
|
||||
GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer,
|
||||
merge)
|
||||
union res_sockaddr_union *nsAddrPtr;
|
||||
int queryClass;
|
||||
int queryType;
|
||||
const char *name;
|
||||
HostInfo *hostPtr;
|
||||
Boolean isServer;
|
||||
Boolean merge;
|
||||
{
|
||||
int n;
|
||||
register int result;
|
||||
register char **domain;
|
||||
const char *cp;
|
||||
Boolean got_nodata = FALSE;
|
||||
struct in_addr ina;
|
||||
union res_sockaddr_union ina;
|
||||
Boolean tried_as_is = FALSE;
|
||||
char tmp[NS_MAXDNAME];
|
||||
|
||||
@ -608,14 +736,30 @@ GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer)
|
||||
if ((queryType == T_A) && IsAddr(name, &ina)) {
|
||||
hostPtr->name = Calloc(strlen(name)+3, 1);
|
||||
(void)sprintf(hostPtr->name,"[%s]",name);
|
||||
hostPtr->aliases = NULL;
|
||||
hostPtr->servers = NULL;
|
||||
hostPtr->addrType = AF_INET;
|
||||
hostPtr->addrLen = INADDRSZ;
|
||||
hostPtr->addrList = (char **)Calloc(2, sizeof(char *));
|
||||
hostPtr->addrList[0] = Calloc(INT32SZ, sizeof(char));
|
||||
memcpy(hostPtr->addrList[0], &ina, INADDRSZ);
|
||||
hostPtr->addrList[1] = NULL;
|
||||
switch (ina.sin.sin_family) {
|
||||
case AF_INET:
|
||||
hostPtr->aliases = NULL;
|
||||
hostPtr->servers = NULL;
|
||||
hostPtr->addrList = (AddrInfo **)Calloc(2, sizeof(AddrInfo *));
|
||||
hostPtr->addrList[0] = (AddrInfo *)Calloc(1, sizeof(AddrInfo));
|
||||
hostPtr->addrList[0]->addr = Calloc(INT32SZ, sizeof(char));
|
||||
memcpy(hostPtr->addrList[0]->addr, &ina.sin.sin_addr, INADDRSZ);
|
||||
hostPtr->addrList[0]->addrType = AF_INET;
|
||||
hostPtr->addrList[0]->addrLen = INADDRSZ;
|
||||
hostPtr->addrList[1] = NULL;
|
||||
break;
|
||||
case AF_INET6:
|
||||
hostPtr->aliases = NULL;
|
||||
hostPtr->servers = NULL;
|
||||
hostPtr->addrList = (AddrInfo **)Calloc(2, sizeof(AddrInfo *));
|
||||
hostPtr->addrList[0] = (AddrInfo *)Calloc(1, sizeof(AddrInfo));
|
||||
hostPtr->addrList[0]->addr = Calloc(1, 16);
|
||||
memcpy(hostPtr->addrList[0]->addr, &ina.sin6.sin6_addr, 16);
|
||||
hostPtr->addrList[0]->addrType = AF_INET6;
|
||||
hostPtr->addrList[0]->addrLen = 16;
|
||||
hostPtr->addrList[1] = NULL;
|
||||
break;
|
||||
}
|
||||
return(SUCCESS);
|
||||
}
|
||||
|
||||
@ -626,7 +770,7 @@ GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer)
|
||||
if (n == 0 && (cp = res_hostalias(&res, name, tmp, sizeof tmp))) {
|
||||
printf("Aliased to \"%s\"\n\n", cp);
|
||||
return (GetHostDomain(nsAddrPtr, queryClass, queryType,
|
||||
cp, (char *)NULL, hostPtr, isServer));
|
||||
cp, (char *)NULL, hostPtr, isServer, merge));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -635,7 +779,8 @@ GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer)
|
||||
*/
|
||||
if (n >= (int)res.ndots) {
|
||||
result = GetHostDomain(nsAddrPtr, queryClass, queryType,
|
||||
name, (char *)NULL, hostPtr, isServer);
|
||||
name, (char *)NULL, hostPtr, isServer,
|
||||
merge);
|
||||
if (result == SUCCESS)
|
||||
return (result);
|
||||
if (result == NO_INFO)
|
||||
@ -653,7 +798,8 @@ GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer)
|
||||
(n != 0 && *--cp != '.' && (res.options & RES_DNSRCH) != 0))
|
||||
for (domain = res.dnsrch; *domain != NULL; domain++) {
|
||||
result = GetHostDomain(nsAddrPtr, queryClass, queryType,
|
||||
name, *domain, hostPtr, isServer);
|
||||
name, *domain, hostPtr, isServer,
|
||||
merge);
|
||||
/*
|
||||
* If no server present, give up.
|
||||
* If name isn't found in this domain,
|
||||
@ -680,7 +826,7 @@ GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer)
|
||||
*/
|
||||
if (!tried_as_is &&
|
||||
(result = GetHostDomain(nsAddrPtr, queryClass, queryType,
|
||||
name, (char *)NULL, hostPtr, isServer)
|
||||
name, (char *)NULL, hostPtr, isServer, merge)
|
||||
) == SUCCESS)
|
||||
return (result);
|
||||
if (got_nodata)
|
||||
@ -693,14 +839,16 @@ GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer)
|
||||
* removing a trailing dot from name if domain is NULL.
|
||||
*/
|
||||
int
|
||||
GetHostDomain(nsAddrPtr, queryClass, queryType, name, domain, hostPtr, isServer)
|
||||
struct in_addr *nsAddrPtr;
|
||||
GetHostDomain(nsAddrPtr, queryClass, queryType, name, domain, hostPtr,
|
||||
isServer, merge)
|
||||
union res_sockaddr_union *nsAddrPtr;
|
||||
int queryClass;
|
||||
int queryType;
|
||||
const char *name;
|
||||
char *domain;
|
||||
HostInfo *hostPtr;
|
||||
Boolean isServer;
|
||||
Boolean merge;
|
||||
{
|
||||
querybuf buf;
|
||||
char nbuf[2*MAXDNAME+2];
|
||||
@ -732,7 +880,8 @@ GetHostDomain(nsAddrPtr, queryClass, queryType, name, domain, hostPtr, isServer)
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
n = GetAnswer(nsAddrPtr, queryType, (char *)&buf, n, 0, hostPtr, isServer);
|
||||
n = GetAnswer(nsAddrPtr, queryType, (char *)&buf, n, 0, hostPtr,
|
||||
isServer, merge);
|
||||
|
||||
/*
|
||||
* GetAnswer didn't find a name, so set it to the specified one.
|
||||
@ -765,21 +914,76 @@ GetHostDomain(nsAddrPtr, queryClass, queryType, name, domain, hostPtr, isServer)
|
||||
*/
|
||||
|
||||
int
|
||||
GetHostInfoByAddr(nsAddrPtr, address, hostPtr)
|
||||
struct in_addr *nsAddrPtr;
|
||||
struct in_addr *address;
|
||||
HostInfo *hostPtr;
|
||||
GetHostInfoByAddr(union res_sockaddr_union *nsAddrPtr,
|
||||
union res_sockaddr_union *address,
|
||||
HostInfo * hostPtr)
|
||||
{
|
||||
int n;
|
||||
querybuf buf;
|
||||
char qbuf[MAXDNAME];
|
||||
char *p = (char *) &address->s_addr;
|
||||
char qbuf2[MAXDNAME];
|
||||
char *p = NULL;
|
||||
int ismapped = 0;
|
||||
|
||||
(void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
|
||||
((unsigned)p[3] & 0xff),
|
||||
((unsigned)p[2] & 0xff),
|
||||
((unsigned)p[1] & 0xff),
|
||||
((unsigned)p[0] & 0xff));
|
||||
switch (address->sin.sin_family) {
|
||||
case AF_INET:
|
||||
p = (char *) &address->sin.sin_addr.s_addr;
|
||||
mapped:
|
||||
(void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
|
||||
((unsigned)p[3 + (ismapped ? 12 : 0)] & 0xff),
|
||||
((unsigned)p[2 + (ismapped ? 12 : 0)] & 0xff),
|
||||
((unsigned)p[1 + (ismapped ? 12 : 0)] & 0xff),
|
||||
((unsigned)p[0 + (ismapped ? 12 : 0)] & 0xff));
|
||||
break;
|
||||
case AF_INET6:
|
||||
p = (char *)address->sin6.sin6_addr.s6_addr;
|
||||
if (IN6_IS_ADDR_V4MAPPED(&address->sin6.sin6_addr) ||
|
||||
IN6_IS_ADDR_V4COMPAT(&address->sin6.sin6_addr)) {
|
||||
ismapped = 1;
|
||||
goto mapped;
|
||||
}
|
||||
(void)sprintf(qbuf,
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"ip6.arpa",
|
||||
p[15] & 0xf, (p[15] >> 4) & 0xf,
|
||||
p[14] & 0xf, (p[14] >> 4) & 0xf,
|
||||
p[13] & 0xf, (p[13] >> 4) & 0xf,
|
||||
p[12] & 0xf, (p[12] >> 4) & 0xf,
|
||||
p[11] & 0xf, (p[11] >> 4) & 0xf,
|
||||
p[10] & 0xf, (p[10] >> 4) & 0xf,
|
||||
p[9] & 0xf, (p[9] >> 4) & 0xf,
|
||||
p[8] & 0xf, (p[8] >> 4) & 0xf,
|
||||
p[7] & 0xf, (p[7] >> 4) & 0xf,
|
||||
p[6] & 0xf, (p[4] >> 4) & 0xf,
|
||||
p[5] & 0xf, (p[5] >> 4) & 0xf,
|
||||
p[4] & 0xf, (p[4] >> 4) & 0xf,
|
||||
p[3] & 0xf, (p[3] >> 4) & 0xf,
|
||||
p[2] & 0xf, (p[2] >> 4) & 0xf,
|
||||
p[1] & 0xf, (p[1] >> 4) & 0xf,
|
||||
p[0] & 0xf, (p[0] >> 4) & 0xf);
|
||||
(void)sprintf(qbuf2,
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"ip6.int",
|
||||
p[15] & 0xf, (p[15] >> 4) & 0xf,
|
||||
p[14] & 0xf, (p[14] >> 4) & 0xf,
|
||||
p[13] & 0xf, (p[13] >> 4) & 0xf,
|
||||
p[12] & 0xf, (p[12] >> 4) & 0xf,
|
||||
p[11] & 0xf, (p[11] >> 4) & 0xf,
|
||||
p[10] & 0xf, (p[10] >> 4) & 0xf,
|
||||
p[9] & 0xf, (p[9] >> 4) & 0xf,
|
||||
p[8] & 0xf, (p[8] >> 4) & 0xf,
|
||||
p[7] & 0xf, (p[7] >> 4) & 0xf,
|
||||
p[6] & 0xf, (p[4] >> 4) & 0xf,
|
||||
p[5] & 0xf, (p[5] >> 4) & 0xf,
|
||||
p[4] & 0xf, (p[4] >> 4) & 0xf,
|
||||
p[3] & 0xf, (p[3] >> 4) & 0xf,
|
||||
p[2] & 0xf, (p[2] >> 4) & 0xf,
|
||||
p[1] & 0xf, (p[1] >> 4) & 0xf,
|
||||
p[0] & 0xf, (p[0] >> 4) & 0xf);
|
||||
break;
|
||||
}
|
||||
n = res_nmkquery(&res, QUERY, qbuf, C_IN, T_PTR, NULL, 0, NULL,
|
||||
buf.qb2, sizeof buf);
|
||||
if (n < 0) {
|
||||
@ -788,13 +992,47 @@ GetHostInfoByAddr(nsAddrPtr, address, hostPtr)
|
||||
}
|
||||
return (ERROR);
|
||||
}
|
||||
n = GetAnswer(nsAddrPtr, T_PTR, (char *) &buf, n, 1, hostPtr, 1);
|
||||
n = GetAnswer(nsAddrPtr, T_PTR, (char *) &buf, n, 1, hostPtr, 1, 0);
|
||||
if (n == SUCCESS) {
|
||||
hostPtr->addrType = AF_INET;
|
||||
hostPtr->addrLen = 4;
|
||||
hostPtr->addrList = (char **)Calloc(2, sizeof(char *));
|
||||
hostPtr->addrList[0] = Calloc(INT32SZ, sizeof(char));
|
||||
memcpy(hostPtr->addrList[0], p, INADDRSZ);
|
||||
switch (address->sin.sin_family) {
|
||||
case AF_INET:
|
||||
hostPtr->addrList = (AddrInfo **)Calloc(2, sizeof(AddrInfo *));
|
||||
hostPtr->addrList[0] = (AddrInfo *)Calloc(1, sizeof(AddrInfo));
|
||||
hostPtr->addrList[0]->addr = Calloc(INT32SZ, sizeof(char));
|
||||
memcpy(hostPtr->addrList[0]->addr, p, INADDRSZ);
|
||||
hostPtr->addrList[0]->addrType = AF_INET;
|
||||
hostPtr->addrList[0]->addrLen = 4;
|
||||
hostPtr->addrList[1] = NULL;
|
||||
break;
|
||||
case AF_INET6:
|
||||
hostPtr->addrList = (AddrInfo **)Calloc(2, sizeof(AddrInfo *));
|
||||
hostPtr->addrList[0] = (AddrInfo *)Calloc(1, sizeof(AddrInfo));
|
||||
hostPtr->addrList[0]->addr = Calloc(16, sizeof(char));
|
||||
memcpy(hostPtr->addrList[0]->addr, p, 16);
|
||||
hostPtr->addrList[0]->addrType = AF_INET6;
|
||||
hostPtr->addrList[0]->addrLen = 16;
|
||||
hostPtr->addrList[1] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n == SUCCESS || ismapped || address->sin.sin_family != AF_INET6)
|
||||
return n;
|
||||
n = res_nmkquery(&res, QUERY, qbuf2, C_IN, T_PTR, NULL, 0, NULL,
|
||||
buf.qb2, sizeof buf);
|
||||
if (n < 0) {
|
||||
if (res.options & RES_DEBUG) {
|
||||
printf("res_nmkquery() failed\n");
|
||||
}
|
||||
return (ERROR);
|
||||
}
|
||||
n = GetAnswer(nsAddrPtr, T_PTR, (char *) &buf, n, 1, hostPtr, 1, 0);
|
||||
if (n == SUCCESS) {
|
||||
hostPtr->addrList = (AddrInfo **)Calloc(2, sizeof(AddrInfo *));
|
||||
hostPtr->addrList[0] = (AddrInfo *)Calloc(1, sizeof(AddrInfo *));
|
||||
hostPtr->addrList[0]->addr = Calloc(16, sizeof(char));
|
||||
memcpy(hostPtr->addrList[0]->addr, p, 16);
|
||||
hostPtr->addrList[0]->addrType = AF_INET6;
|
||||
hostPtr->addrList[0]->addrLen = 16;
|
||||
hostPtr->addrList[1] = NULL;
|
||||
}
|
||||
return n;
|
||||
@ -834,6 +1072,7 @@ FreeHostInfoPtr(hostPtr)
|
||||
if (hostPtr->addrList != NULL) {
|
||||
i = 0;
|
||||
while (hostPtr->addrList[i] != NULL) {
|
||||
free(hostPtr->addrList[i]->addr);
|
||||
free(hostPtr->addrList[i]);
|
||||
i++;
|
||||
}
|
||||
@ -861,6 +1100,7 @@ FreeHostInfoPtr(hostPtr)
|
||||
if (hostPtr->servers[i]->addrList != NULL) {
|
||||
j = 0;
|
||||
while (hostPtr->servers[i]->addrList[j] != NULL) {
|
||||
free(hostPtr->servers[i]->addrList[j]->addr);
|
||||
free(hostPtr->servers[i]->addrList[j]);
|
||||
j++;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ char copyright[] =
|
||||
|
||||
#ifndef lint
|
||||
static const char sccsid[] = "@(#)main.c 5.42 (Berkeley) 3/3/91";
|
||||
static const char rcsid[] = "$Id: main.c,v 8.20 2001/06/20 12:40:06 marka Exp $";
|
||||
static const char rcsid[] = "$Id: main.c,v 8.22 2002/04/12 03:03:49 marka Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -109,7 +109,6 @@ static const char rcsid[] = "$Id: main.c,v 8.20 2001/06/20 12:40:06 marka Exp $"
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <netdb.h>
|
||||
#include <resolv.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@ -119,6 +118,8 @@ static const char rcsid[] = "$Id: main.c,v 8.20 2001/06/20 12:40:06 marka Exp $"
|
||||
|
||||
#include "port_after.h"
|
||||
|
||||
#include <resolv.h>
|
||||
|
||||
#include "res.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
@ -155,7 +156,7 @@ int curHostValid = FALSE;
|
||||
|
||||
HostInfo *defaultPtr = NULL;
|
||||
char defaultServer[NAME_LEN];
|
||||
struct in_addr defaultAddr;
|
||||
union res_sockaddr_union defaultAddr;
|
||||
|
||||
|
||||
/*
|
||||
@ -190,6 +191,31 @@ static void res_re_init(void);
|
||||
static void res_dnsrch(char *cp);
|
||||
static void Usage(void);
|
||||
static void ShowOptions(void);
|
||||
|
||||
static void
|
||||
UnionFromAddr(union res_sockaddr_union *u, int family, void *addr) {
|
||||
memset(u, 0, sizeof *u);
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
u->sin.sin_family = AF_INET;
|
||||
u->sin.sin_port = htons(nsport);
|
||||
memcpy(&u->sin.sin_addr, addr, 4);
|
||||
#ifdef HAVE_SA_LEN
|
||||
u->sin.sin_len = sizeof(u->sin);
|
||||
#endif
|
||||
break;
|
||||
case AF_INET6:
|
||||
u->sin6.sin6_family = AF_INET6;
|
||||
u->sin6.sin6_port = htons(nsport);
|
||||
memcpy(&u->sin6.sin6_addr, addr, 16);
|
||||
#ifdef HAVE_SA_LEN
|
||||
u->sin6.sin6_len = sizeof(u->sin6);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
@ -209,7 +235,6 @@ main(int argc, char **argv) {
|
||||
Boolean useLocalServer;
|
||||
int result;
|
||||
int i;
|
||||
struct hostent *hp;
|
||||
|
||||
/*
|
||||
* Initialize the resolver library routines.
|
||||
@ -265,30 +290,38 @@ main(int argc, char **argv) {
|
||||
|
||||
useLocalServer = FALSE;
|
||||
if (argc == 2) {
|
||||
struct in_addr addr;
|
||||
int nscount = 0;
|
||||
union res_sockaddr_union u[MAXNS];
|
||||
struct addrinfo *answer = NULL;
|
||||
struct addrinfo *cur = NULL;
|
||||
struct addrinfo hint;
|
||||
|
||||
/*
|
||||
* Use an explicit name server. If the hostname lookup fails,
|
||||
* default to the server(s) in resolv.conf.
|
||||
*/
|
||||
|
||||
if (inet_aton(*++argv, &addr)) {
|
||||
res.nscount = 1;
|
||||
res.nsaddr.sin_addr = addr;
|
||||
} else {
|
||||
hp = gethostbyname(*argv);
|
||||
if (hp == NULL) {
|
||||
fprintf(stderr, "*** Can't find server address for '%s': ",
|
||||
*argv);
|
||||
herror((char *)NULL);
|
||||
fputc('\n', stderr);
|
||||
} else {
|
||||
for (i = 0; i < MAXNS && hp->h_addr_list[i] != NULL; i++) {
|
||||
memcpy(&res.nsaddr_list[i].sin_addr, hp->h_addr_list[i],
|
||||
hp->h_length);
|
||||
memset(u, 0, sizeof(u));
|
||||
memset(&hint, 0, sizeof(hint));
|
||||
hint.ai_socktype = SOCK_DGRAM;
|
||||
if (!getaddrinfo(*++argv, NULL, &hint, &answer)) {
|
||||
for (cur = answer; cur != NULL; cur = cur->ai_next) {
|
||||
if (nscount == MAXNS)
|
||||
break;
|
||||
switch (cur->ai_addr->sa_family) {
|
||||
case AF_INET6:
|
||||
u[nscount].sin6 = *(struct sockaddr_in6*)cur->ai_addr;
|
||||
u[nscount++].sin6.sin6_port = htons(nsport);
|
||||
break;
|
||||
case AF_INET:
|
||||
u[nscount].sin = *(struct sockaddr_in*)cur->ai_addr;
|
||||
u[nscount++].sin.sin_port = htons(nsport);
|
||||
break;
|
||||
}
|
||||
res.nscount = i;
|
||||
}
|
||||
}
|
||||
if (nscount != 0)
|
||||
res_setservers(&res, u, nscount);
|
||||
freeaddrinfo(answer);;
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,21 +329,24 @@ main(int argc, char **argv) {
|
||||
if (res.nscount == 0 || useLocalServer) {
|
||||
LocalServer(defaultPtr);
|
||||
} else {
|
||||
for (i = 0; i < res.nscount; i++) {
|
||||
if (res.nsaddr_list[i].sin_addr.s_addr == INADDR_ANY) {
|
||||
int nscount = 0;
|
||||
union res_sockaddr_union u[MAXNS];
|
||||
|
||||
nscount = res_getservers(&res, u, MAXNS);
|
||||
for (i = 0; i < nscount; i++) {
|
||||
if (u[i].sin.sin_family == AF_INET &&
|
||||
u[i].sin.sin_addr.s_addr == INADDR_ANY) {
|
||||
LocalServer(defaultPtr);
|
||||
break;
|
||||
} else {
|
||||
result = GetHostInfoByAddr(&(res.nsaddr_list[i].sin_addr),
|
||||
&(res.nsaddr_list[i].sin_addr),
|
||||
defaultPtr);
|
||||
result = GetHostInfoByAddr(&u[i], &u[i], defaultPtr);
|
||||
if (result != SUCCESS) {
|
||||
fprintf(stderr,
|
||||
"*** Can't find server name for address %s: %s\n",
|
||||
inet_ntoa(res.nsaddr_list[i].sin_addr),
|
||||
DecodeError(result));
|
||||
} else {
|
||||
defaultAddr = res.nsaddr_list[i].sin_addr;
|
||||
defaultAddr = u[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -386,9 +422,15 @@ LocalServer(defaultPtr)
|
||||
|
||||
(void) gethostname(hostName, sizeof(hostName));
|
||||
|
||||
defaultAddr.s_addr = htonl(INADDR_ANY);
|
||||
memset(&defaultAddr, 0, sizeof(defaultAddr));
|
||||
defaultAddr.sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
defaultAddr.sin.sin_family = AF_INET;
|
||||
defaultAddr.sin.sin_port = htons(nsport);
|
||||
#ifdef HAVE_SA_LEN
|
||||
defaultAddr.sin.sin_len = sizeof(defaultAddr.sin);
|
||||
#endif
|
||||
(void) GetHostInfoByName(&defaultAddr, C_IN, T_A,
|
||||
"0.0.0.0", defaultPtr, 1);
|
||||
"0.0.0.0", defaultPtr, 1, 0);
|
||||
free(defaultPtr->name);
|
||||
defaultPtr->name = Calloc(1, sizeof(hostName)+1);
|
||||
strcpy(defaultPtr->name, hostName);
|
||||
@ -434,22 +476,24 @@ Usage(void) {
|
||||
Boolean
|
||||
IsAddr(host, addrPtr)
|
||||
const char *host;
|
||||
struct in_addr *addrPtr; /* If return TRUE, contains IP address */
|
||||
union res_sockaddr_union *addrPtr;
|
||||
/* If return TRUE, contains IP address */
|
||||
{
|
||||
register const char *cp;
|
||||
|
||||
if (isdigit(host[0])) {
|
||||
/* Make sure it has only digits and dots. */
|
||||
for (cp = host; *cp; ++cp) {
|
||||
if (!isdigit(*cp) && *cp != '.')
|
||||
return FALSE;
|
||||
}
|
||||
/* If it has a trailing dot, don't treat it as an address. */
|
||||
if (*--cp != '.') {
|
||||
return inet_aton(host, addrPtr);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
if (inet_pton(AF_INET6, host, &addrPtr->sin6.sin6_addr) == 1) {
|
||||
addrPtr->sin6.sin6_family = AF_INET6;
|
||||
addrPtr->sin6.sin6_port = htons(nsport);
|
||||
#ifdef HAVE_SA_LEN
|
||||
addrPtr->sin6.sin6_len = sizeof(addrPtr->sin6);
|
||||
#endif
|
||||
} else if (inet_pton(AF_INET, host, &addrPtr->sin.sin_addr) == 1) {
|
||||
addrPtr->sin.sin_family = AF_INET;
|
||||
addrPtr->sin.sin_port = htons(nsport);
|
||||
#ifdef HAVE_SA_LEN
|
||||
addrPtr->sin.sin_len = sizeof(addrPtr->sin);
|
||||
#endif
|
||||
} else
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -483,10 +527,11 @@ SetDefaultServer(string, local)
|
||||
Boolean local;
|
||||
{
|
||||
register HostInfo *newDefPtr;
|
||||
struct in_addr *servAddrPtr;
|
||||
struct in_addr addr;
|
||||
union res_sockaddr_union servAddr;
|
||||
union res_sockaddr_union addr;
|
||||
char newServer[NAME_LEN];
|
||||
int result;
|
||||
int tresult;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
@ -546,21 +591,28 @@ SetDefaultServer(string, local)
|
||||
*/
|
||||
|
||||
if (local) {
|
||||
servAddrPtr = &defaultAddr;
|
||||
servAddr = defaultAddr;
|
||||
} else if (defaultPtr->addrList != NULL) {
|
||||
servAddrPtr = (struct in_addr *) defaultPtr->addrList[0];
|
||||
UnionFromAddr(&servAddr, defaultPtr->addrList[0]->addrType,
|
||||
defaultPtr->addrList[0]->addr);
|
||||
} else {
|
||||
servAddrPtr = (struct in_addr *) defaultPtr->servers[0]->addrList[0];
|
||||
UnionFromAddr(&servAddr, defaultPtr->addrList[0]->addrType,
|
||||
defaultPtr->servers[0]->addrList[0]->addr);
|
||||
}
|
||||
|
||||
result = ERROR;
|
||||
if (IsAddr(newServer, &addr)) {
|
||||
result = GetHostInfoByAddr(servAddrPtr, &addr, newDefPtr);
|
||||
result = GetHostInfoByAddr(&servAddr, &addr, newDefPtr);
|
||||
/* If we can't get the name, fall through... */
|
||||
}
|
||||
if (result != SUCCESS && result != NONAUTH) {
|
||||
result = GetHostInfoByName(servAddrPtr, C_IN, T_A,
|
||||
newServer, newDefPtr, 1);
|
||||
result = GetHostInfoByName(&servAddr, C_IN, T_A,
|
||||
newServer, newDefPtr, 1, 0);
|
||||
if (result == SUCCESS || result == NONAUTH || result == NO_INFO)
|
||||
tresult = GetHostInfoByName(&servAddr, C_IN, T_AAAA,
|
||||
newServer, newDefPtr, 1, 1);
|
||||
if (result == NO_INFO)
|
||||
result = tresult;
|
||||
}
|
||||
|
||||
/* If we ask for an A record and get none back, but get an NS
|
||||
@ -612,8 +664,8 @@ DoLookup(host, servPtr, serverName)
|
||||
char *serverName;
|
||||
{
|
||||
int result;
|
||||
struct in_addr *servAddrPtr;
|
||||
struct in_addr addr;
|
||||
union res_sockaddr_union servAddr;
|
||||
union res_sockaddr_union addr;
|
||||
|
||||
/* Skip escape character */
|
||||
if (host[0] == '\\')
|
||||
@ -630,9 +682,11 @@ DoLookup(host, servPtr, serverName)
|
||||
*/
|
||||
|
||||
if (servPtr->addrList != NULL) {
|
||||
servAddrPtr = (struct in_addr *) servPtr->addrList[0];
|
||||
UnionFromAddr(&servAddr, servPtr->addrList[0]->addrType,
|
||||
servPtr->addrList[0]->addr);
|
||||
} else {
|
||||
servAddrPtr = (struct in_addr *) servPtr->servers[0]->addrList[0];
|
||||
UnionFromAddr(&servAddr, servPtr->servers[0]->addrList[0]->addrType,
|
||||
servPtr->servers[0]->addrList[0]->addr);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -640,13 +694,13 @@ DoLookup(host, servPtr, serverName)
|
||||
* dotted-decimal number before looking it up [...]" (p. 13).
|
||||
*/
|
||||
if (queryType == T_A && IsAddr(host, &addr)) {
|
||||
result = GetHostInfoByAddr(servAddrPtr, &addr, &curHostInfo);
|
||||
result = GetHostInfoByAddr(&servAddr, &addr, &curHostInfo);
|
||||
} else {
|
||||
if (queryType == T_PTR) {
|
||||
CvtAddrToPtr(host);
|
||||
}
|
||||
result = GetHostInfoByName(servAddrPtr, queryClass, queryType, host,
|
||||
&curHostInfo, 0);
|
||||
result = GetHostInfoByName(&servAddr, queryClass, queryType, host,
|
||||
&curHostInfo, 0, 0);
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
@ -788,6 +842,7 @@ LookupHostWithServer(char *string, Boolean putToFile) {
|
||||
static HostInfo serverInfo;
|
||||
int i;
|
||||
int j;
|
||||
union res_sockaddr_union u;
|
||||
|
||||
curHostValid = FALSE;
|
||||
|
||||
@ -814,11 +869,16 @@ LookupHostWithServer(char *string, Boolean putToFile) {
|
||||
fprintf(filePtr,"> %s\n", string);
|
||||
}
|
||||
|
||||
result = GetHostInfoByName(
|
||||
defaultPtr->addrList ?
|
||||
(struct in_addr *) defaultPtr->addrList[0] :
|
||||
(struct in_addr *) defaultPtr->servers[0]->addrList[0],
|
||||
C_IN, T_A, server, &serverInfo, 1);
|
||||
if (defaultPtr->addrList != NULL)
|
||||
UnionFromAddr(&u, defaultPtr->addrList[0]->addrType,
|
||||
defaultPtr->addrList[0]->addr);
|
||||
else
|
||||
UnionFromAddr(&u, defaultPtr->servers[0]->addrList[0]->addrType,
|
||||
defaultPtr->servers[0]->addrList[0]->addr);
|
||||
result = GetHostInfoByName(&u, C_IN, T_A, server, &serverInfo, 1, 0);
|
||||
if (result == NO_INFO)
|
||||
result = GetHostInfoByName(&u, C_IN, T_AAAA, server,
|
||||
&serverInfo, 1, 1);
|
||||
|
||||
if (result != SUCCESS) {
|
||||
fprintf(stderr,"*** Can't find address for server %s: %s\n", server,
|
||||
@ -1168,13 +1228,54 @@ CvtAddrToPtr(name)
|
||||
{
|
||||
const char *p;
|
||||
int ip[4];
|
||||
struct in_addr addr;
|
||||
union res_sockaddr_union addr;
|
||||
|
||||
if (IsAddr(name, &addr)) {
|
||||
p = inet_ntoa(addr);
|
||||
if (sscanf(p, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]) == 4) {
|
||||
sprintf(name, "%d.%d.%d.%d.in-addr.arpa.",
|
||||
ip[3], ip[2], ip[1], ip[0]);
|
||||
switch (addr.sin.sin_family) {
|
||||
case AF_INET:
|
||||
p = inet_ntoa(addr.sin.sin_addr);
|
||||
if (sscanf(p, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]) == 4)
|
||||
sprintf(name, "%d.%d.%d.%d.in-addr.arpa.",
|
||||
ip[3], ip[2], ip[1], ip[0]);
|
||||
break;
|
||||
case AF_INET6:
|
||||
sprintf(name,
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"ip6.arpa",
|
||||
addr.sin6.sin6_addr.s6_addr[15] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[15] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[14] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[14] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[13] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[13] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[12] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[12] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[11] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[11] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[10] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[10] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[9] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[9] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[8] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[8] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[7] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[7] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[6] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[6] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[5] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[5] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[4] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[4] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[3] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[3] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[2] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[2] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[1] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[1] >> 4) & 0xf,
|
||||
addr.sin6.sin6_addr.s6_addr[0] & 0xf,
|
||||
(addr.sin6.sin6_addr.s6_addr[0] >> 4) & 0xf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
#define HAVE_MINIMUM_IFREQ
|
||||
#define HAVE_CHROOT
|
||||
#define CAN_CHANGE_ID
|
||||
#define MISSING_IN6ADDR_ANY
|
||||
|
||||
#define _TIMEZONE timezone
|
||||
|
||||
@ -124,11 +123,45 @@ extern const struct in6_addr in6addr_any;
|
||||
IN6_ARE_ADDR_EQUAL(a, &in6addr_any)
|
||||
#endif
|
||||
|
||||
#ifndef IN6_IS_ADDR_LOOPBACK
|
||||
extern const struct in6_addr isc_in6addr_loopback;
|
||||
#define IN6_IS_ADDR_LOOPBACK(a) \
|
||||
IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback)
|
||||
#endif
|
||||
|
||||
#ifndef IN6_IS_ADDR_V4COMPAT
|
||||
#define IN6_IS_ADDR_V4COMPAT(a) \
|
||||
((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
|
||||
(a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
|
||||
(a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
|
||||
(a)->s6_addr[6] == 0x00 && (a)->s6_addr[7] == 0x00 && \
|
||||
(a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
|
||||
(a)->s6_addr[10] == 0x00 && (a)->s6_addr[11] == 0x00 && \
|
||||
((a)->s6_addr[12] != 0x00 || (a)->s6_addr[13] != 0x00 || \
|
||||
(a)->s6_addr[14] != 0x00 || \
|
||||
((a)->s6_addr[15] != 0x00 && (a)->s6_addr[15] != 1)))
|
||||
#endif
|
||||
|
||||
#ifndef IN6_IS_ADDR_V4MAPPED
|
||||
#define IN6_IS_ADDR_V4MAPPED(a) \
|
||||
((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
|
||||
(a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
|
||||
(a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
|
||||
(a)->s6_addr[6] == 0x00 && (a)->s6_addr[7] == 0x00 && \
|
||||
(a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
|
||||
(a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
|
||||
#endif
|
||||
|
||||
#ifndef IN6_IS_ADDR_SITELOCAL
|
||||
#define IN6_IS_ADDR_SITELOCAL(a) \
|
||||
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
|
||||
#endif
|
||||
|
||||
#ifndef IN6_IS_ADDR_LINKLOCAL
|
||||
#define IN6_IS_ADDR_LINKLOCAL(a) \
|
||||
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
|
||||
#endif
|
||||
|
||||
#ifndef IN6_IS_ADDR_MULTICAST
|
||||
#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user