|
|
Ns_Set *Ns_QueryResolve(
int queryType,
char *nameServer,
char *domain
);
Ns_QueryResolve implements a subset of the nslookup program functions. You can query a nameServer about the specified domain for records of any of the following queryTypes: T_A, T_CNAME, T_NS, T_SOA, T_MX, or NS_T_HOST. If there isn't a record for the particular queryType, the Ns_Set size will be 0 along with no fields.
The T_A type is for address lookups, and it will will return all of the addresses for a particular host. For the T_CNAME type, if the query comes back "null" from DNS, it returns a set with null fields. The T_NS, T_SOA, and T_MX types require an authoritative domain/host or the command returns a set with no fields. The NS_T_HOST type is for host lookups (i.e., gethostbyname and gethostbyaddr).
If the queryType is invalid, it'll print an informative message in the server.log.
If the nameServer is NULL, it'll uses the default (first one) in the resolv.conf.
If the domain is NULL, it prints a bug message in the server.log.
#include "ns.h"
#include "nsresolve.h"
DllExport int Ns_ModuleVersion = 1;
struct {
int qType; /* Either NS_T_HOST or regular <arpa/nameser.h>
query
type */
char *qHost; /* What host domain to query DNS for? */
char *nServer; /* If NULL, this defaults to resolve.conf name
server
*/
} query[] = { { NS_T_HOST, "www.aol.com", NULL },
{ NS_T_HOST, "152.163.214.10" , NULL },
{ T_A , "aol.com" , NULL },
{ T_NS , "aol.com" , NULL },
{ T_MX , "aol.com" , NULL },
{ T_SOA , "aol.com" , NULL },
{ T_CNAME , "www.aol.com" , NULL },
{ 0 , NULL , NULL } };
DllExport int
Ns_ModuleInit (char * hServer, char *hModule) {
static char *asfuncname = "Ns_ModuleInit(Query Resolve Example)";
Ns_Set *aSet;
int i, status = NS_OK;
if (hServer == NULL || hModule == NULL) {
Ns_Log(Error, "%s: hServer and/or hModule NULL.", asfuncname);
status = NS_ERROR;
goto done;
}
for(i=0; query[i].qHost != NULL; i++) {
aSet = Ns_QueryResolve(query[i].qType, query[i].nServer,
query[i].qHost);
Ns_SetPrint(aSet);
Ns_SetFree(aSet); /* explicitly free set */
}
done:
return(status);
} /* end Ns_ModuleInit */