#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id: res_data.c,v 1.1.1.1 2003/01/10 00:48:32 bbraun Exp $";
#endif
#include "port_before.h"
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <ctype.h>
#include <netdb.h>
#include <resolv.h>
#include <res_update.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "port_after.h"
#undef _res
const char *_res_opcodes[] = {
"QUERY",
"IQUERY",
"CQUERYM",
"CQUERYU",
"NOTIFY",
"UPDATE",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"ZONEINIT",
"ZONEREF",
};
#ifdef BIND_UPDATE
const char *_res_sectioncodes[] = {
"ZONE",
"PREREQUISITES",
"UPDATE",
"ADDITIONAL",
};
#endif
#ifndef __BIND_NOSTATIC
struct __res_state _res
# if defined(__BIND_RES_TEXT)
= { RES_TIMEOUT, }
# endif
;
int res_ourserver_p(const res_state, const struct sockaddr_in *);
int
res_init(void) {
extern int __res_vinit(res_state, int);
if (!_res.retrans)
_res.retrans = RES_TIMEOUT;
if (!_res.retry)
_res.retry = 4;
if (!(_res.options & RES_INIT))
_res.options = RES_DEFAULT;
if (!_res.id)
_res.id = res_randomid();
return (__res_vinit(&_res, 1));
}
void
p_query(const u_char *msg) {
fp_query(msg, stdout);
}
void
fp_query(const u_char *msg, FILE *file) {
fp_nquery(msg, PACKETSZ, file);
}
void
fp_nquery(const u_char *msg, int len, FILE *file) {
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
return;
res_pquery(&_res, msg, len, file);
}
int
res_mkquery(int op,
const char *dname,
int class, int type,
const u_char *data,
int datalen,
const u_char *newrr_in,
u_char *buf,
int buflen)
{
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
return (res_nmkquery(&_res, op, dname, class, type,
data, datalen,
newrr_in, buf, buflen));
}
int
res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
return (res_nmkupdate(&_res, rrecp_in, buf, buflen));
}
int
res_query(const char *name,
int class, int type,
u_char *answer,
int anslen)
{
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
return (res_nquery(&_res, name, class, type, answer, anslen));
}
void
res_send_setqhook(res_send_qhook hook) {
_res.qhook = hook;
}
void
res_send_setrhook(res_send_rhook hook) {
_res.rhook = hook;
}
int
res_isourserver(const struct sockaddr_in *inp) {
return (res_ourserver_p(&_res, inp));
}
int
res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) {
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
return (-1);
}
return (res_nsend(&_res, buf, buflen, ans, anssiz));
}
int
res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
u_char *ans, int anssiz)
{
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
return (-1);
}
return (res_nsendsigned(&_res, buf, buflen, key, ans, anssiz));
}
void
res_close(void) {
res_nclose(&_res);
}
int
res_update(ns_updrec *rrecp_in) {
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
return (res_nupdate(&_res, rrecp_in, NULL));
}
int
res_search(const char *name,
int class, int type,
u_char *answer,
int anslen)
{
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
return (res_nsearch(&_res, name, class, type, answer, anslen));
}
int
res_querydomain(const char *name,
const char *domain,
int class, int type,
u_char *answer,
int anslen)
{
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
return (res_nquerydomain(&_res, name, domain,
class, type,
answer, anslen));
}
const char *
hostalias(const char *name) {
static char abuf[MAXDNAME];
return (res_hostalias(&_res, name, abuf, sizeof abuf));
}
#ifdef ultrix
int
local_hostname_length(const char *hostname) {
int len_host, len_domain;
if (!*_res.defdname)
res_init();
len_host = strlen(hostname);
len_domain = strlen(_res.defdname);
if (len_host > len_domain &&
!strcasecmp(hostname + len_host - len_domain, _res.defdname) &&
hostname[len_host - len_domain - 1] == '.')
return (len_host - len_domain - 1);
return (0);
}
#endif
#endif