1*aa6411e2SAugustin Cavalier /* $NetBSD: res_data.c,v 1.14 2009/10/24 05:35:37 christos Exp $ */ 2*aa6411e2SAugustin Cavalier 3*aa6411e2SAugustin Cavalier /* 4*aa6411e2SAugustin Cavalier * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 5*aa6411e2SAugustin Cavalier * Copyright (c) 1995-1999 by Internet Software Consortium. 6*aa6411e2SAugustin Cavalier * 7*aa6411e2SAugustin Cavalier * Permission to use, copy, modify, and distribute this software for any 8*aa6411e2SAugustin Cavalier * purpose with or without fee is hereby granted, provided that the above 9*aa6411e2SAugustin Cavalier * copyright notice and this permission notice appear in all copies. 10*aa6411e2SAugustin Cavalier * 11*aa6411e2SAugustin Cavalier * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 12*aa6411e2SAugustin Cavalier * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13*aa6411e2SAugustin Cavalier * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 14*aa6411e2SAugustin Cavalier * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15*aa6411e2SAugustin Cavalier * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16*aa6411e2SAugustin Cavalier * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 17*aa6411e2SAugustin Cavalier * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18*aa6411e2SAugustin Cavalier */ 19*aa6411e2SAugustin Cavalier 20*aa6411e2SAugustin Cavalier #include <sys/cdefs.h> 21*aa6411e2SAugustin Cavalier #if defined(LIBC_SCCS) && !defined(lint) 22*aa6411e2SAugustin Cavalier #ifdef notdef 23*aa6411e2SAugustin Cavalier static const char rcsid[] = "Id: res_data.c,v 1.7 2008/12/11 09:59:00 marka Exp"; 24*aa6411e2SAugustin Cavalier #else 25*aa6411e2SAugustin Cavalier __RCSID("$NetBSD: res_data.c,v 1.14 2009/10/24 05:35:37 christos Exp $"); 26*aa6411e2SAugustin Cavalier #endif 27*aa6411e2SAugustin Cavalier #endif /* LIBC_SCCS and not lint */ 28*aa6411e2SAugustin Cavalier 29*aa6411e2SAugustin Cavalier #include "port_before.h" 30*aa6411e2SAugustin Cavalier 31*aa6411e2SAugustin Cavalier #include <sys/types.h> 32*aa6411e2SAugustin Cavalier #include <sys/param.h> 33*aa6411e2SAugustin Cavalier #include <sys/socket.h> 34*aa6411e2SAugustin Cavalier #include <sys/time.h> 35*aa6411e2SAugustin Cavalier 36*aa6411e2SAugustin Cavalier #include <netinet/in.h> 37*aa6411e2SAugustin Cavalier #include <arpa/inet.h> 38*aa6411e2SAugustin Cavalier #include <arpa/nameser.h> 39*aa6411e2SAugustin Cavalier 40*aa6411e2SAugustin Cavalier #include <ctype.h> 41*aa6411e2SAugustin Cavalier #include <netdb.h> 42*aa6411e2SAugustin Cavalier #include <resolv.h> 43*aa6411e2SAugustin Cavalier #include <res_update.h> 44*aa6411e2SAugustin Cavalier #include <stdio.h> 45*aa6411e2SAugustin Cavalier #include <stdlib.h> 46*aa6411e2SAugustin Cavalier #include <string.h> 47*aa6411e2SAugustin Cavalier #include <unistd.h> 48*aa6411e2SAugustin Cavalier 49*aa6411e2SAugustin Cavalier #include "port_after.h" 50*aa6411e2SAugustin Cavalier 51*aa6411e2SAugustin Cavalier #include "res_private.h" 52*aa6411e2SAugustin Cavalier 53*aa6411e2SAugustin Cavalier #ifdef __weak_alias 54*aa6411e2SAugustin Cavalier __weak_alias(res_init,_res_init) 55*aa6411e2SAugustin Cavalier __weak_alias(res_mkquery,_res_mkquery) 56*aa6411e2SAugustin Cavalier __weak_alias(res_query,_res_query) 57*aa6411e2SAugustin Cavalier __weak_alias(res_search,_res_search) 58*aa6411e2SAugustin Cavalier __weak_alias(res_send,__res_send) 59*aa6411e2SAugustin Cavalier __weak_alias(res_close,__res_close) 60*aa6411e2SAugustin Cavalier /* XXX: these leaked in the old bind8 libc */ 61*aa6411e2SAugustin Cavalier __weak_alias(res_querydomain,__res_querydomain) 62*aa6411e2SAugustin Cavalier __weak_alias(res_send_setqhook,__res_send_setqhook) 63*aa6411e2SAugustin Cavalier __weak_alias(res_send_setrhook,__res_send_setrhook) 64*aa6411e2SAugustin Cavalier #if 0 65*aa6411e2SAugustin Cavalier __weak_alias(p_query,__p_query) 66*aa6411e2SAugustin Cavalier __weak_alias(fp_query,__fp_query) 67*aa6411e2SAugustin Cavalier __weak_alias(fp_nquery,__fp_nquery) 68*aa6411e2SAugustin Cavalier __weak_alias(res_isourserver,__res_isourserver) 69*aa6411e2SAugustin Cavalier __weak_alias(hostalias,__hostalias) 70*aa6411e2SAugustin Cavalier #endif 71*aa6411e2SAugustin Cavalier #endif 72*aa6411e2SAugustin Cavalier 73*aa6411e2SAugustin Cavalier const char *_res_opcodes[] = { 74*aa6411e2SAugustin Cavalier "QUERY", 75*aa6411e2SAugustin Cavalier "IQUERY", 76*aa6411e2SAugustin Cavalier "CQUERYM", 77*aa6411e2SAugustin Cavalier "CQUERYU", /*%< experimental */ 78*aa6411e2SAugustin Cavalier "NOTIFY", /*%< experimental */ 79*aa6411e2SAugustin Cavalier "UPDATE", 80*aa6411e2SAugustin Cavalier "6", 81*aa6411e2SAugustin Cavalier "7", 82*aa6411e2SAugustin Cavalier "8", 83*aa6411e2SAugustin Cavalier "9", 84*aa6411e2SAugustin Cavalier "10", 85*aa6411e2SAugustin Cavalier "11", 86*aa6411e2SAugustin Cavalier "12", 87*aa6411e2SAugustin Cavalier "13", 88*aa6411e2SAugustin Cavalier "ZONEINIT", 89*aa6411e2SAugustin Cavalier "ZONEREF", 90*aa6411e2SAugustin Cavalier }; 91*aa6411e2SAugustin Cavalier 92*aa6411e2SAugustin Cavalier #ifdef BIND_UPDATE 93*aa6411e2SAugustin Cavalier const char *_res_sectioncodes[] = { 94*aa6411e2SAugustin Cavalier "ZONE", 95*aa6411e2SAugustin Cavalier "PREREQUISITES", 96*aa6411e2SAugustin Cavalier "UPDATE", 97*aa6411e2SAugustin Cavalier "ADDITIONAL", 98*aa6411e2SAugustin Cavalier }; 99*aa6411e2SAugustin Cavalier #endif 100*aa6411e2SAugustin Cavalier 101*aa6411e2SAugustin Cavalier #ifndef __BIND_NOSTATIC 102*aa6411e2SAugustin Cavalier extern struct __res_state _nres; 103*aa6411e2SAugustin Cavalier 104*aa6411e2SAugustin Cavalier /* Proto. */ 105*aa6411e2SAugustin Cavalier 106*aa6411e2SAugustin Cavalier int res_ourserver_p(const res_state, const struct sockaddr *); 107*aa6411e2SAugustin Cavalier 108*aa6411e2SAugustin Cavalier int 109*aa6411e2SAugustin Cavalier res_init(void) { 110*aa6411e2SAugustin Cavalier int rv; 111*aa6411e2SAugustin Cavalier #ifdef COMPAT__RES 112*aa6411e2SAugustin Cavalier /* 113*aa6411e2SAugustin Cavalier * Compatibility with program that were accessing _res directly 114*aa6411e2SAugustin Cavalier * to set options. We keep another struct res that is the same 115*aa6411e2SAugustin Cavalier * size as the original res structure, and then copy fields to 116*aa6411e2SAugustin Cavalier * it so that we achieve the same initialization 117*aa6411e2SAugustin Cavalier */ 118*aa6411e2SAugustin Cavalier extern void *__res_get_old_state(void); 119*aa6411e2SAugustin Cavalier extern void __res_put_old_state(void *); 120*aa6411e2SAugustin Cavalier res_state ores = __res_get_old_state(); 121*aa6411e2SAugustin Cavalier 122*aa6411e2SAugustin Cavalier if (ores->options != 0) 123*aa6411e2SAugustin Cavalier _nres.options = ores->options; 124*aa6411e2SAugustin Cavalier if (ores->retrans != 0) 125*aa6411e2SAugustin Cavalier _nres.retrans = ores->retrans; 126*aa6411e2SAugustin Cavalier if (ores->retry != 0) 127*aa6411e2SAugustin Cavalier _nres.retry = ores->retry; 128*aa6411e2SAugustin Cavalier #endif 129*aa6411e2SAugustin Cavalier 130*aa6411e2SAugustin Cavalier /* 131*aa6411e2SAugustin Cavalier * These three fields used to be statically initialized. This made 132*aa6411e2SAugustin Cavalier * it hard to use this code in a shared library. It is necessary, 133*aa6411e2SAugustin Cavalier * now that we're doing dynamic initialization here, that we preserve 134*aa6411e2SAugustin Cavalier * the old semantics: if an application modifies one of these three 135*aa6411e2SAugustin Cavalier * fields of _res before res_init() is called, res_init() will not 136*aa6411e2SAugustin Cavalier * alter them. Of course, if an application is setting them to 137*aa6411e2SAugustin Cavalier * _zero_ before calling res_init(), hoping to override what used 138*aa6411e2SAugustin Cavalier * to be the static default, we can't detect it and unexpected results 139*aa6411e2SAugustin Cavalier * will follow. Zero for any of these fields would make no sense, 140*aa6411e2SAugustin Cavalier * so one can safely assume that the applications were already getting 141*aa6411e2SAugustin Cavalier * unexpected results. 142*aa6411e2SAugustin Cavalier * 143*aa6411e2SAugustin Cavalier * _nres.options is tricky since some apps were known to diddle the bits 144*aa6411e2SAugustin Cavalier * before res_init() was first called. We can't replicate that semantic 145*aa6411e2SAugustin Cavalier * with dynamic initialization (they may have turned bits off that are 146*aa6411e2SAugustin Cavalier * set in RES_DEFAULT). Our solution is to declare such applications 147*aa6411e2SAugustin Cavalier * "broken". They could fool us by setting RES_INIT but none do (yet). 148*aa6411e2SAugustin Cavalier */ 149*aa6411e2SAugustin Cavalier if (!_nres.retrans) 150*aa6411e2SAugustin Cavalier _nres.retrans = RES_TIMEOUT; 151*aa6411e2SAugustin Cavalier if (!_nres.retry) 152*aa6411e2SAugustin Cavalier _nres.retry = 4; 153*aa6411e2SAugustin Cavalier if (!(_nres.options & RES_INIT)) 154*aa6411e2SAugustin Cavalier _nres.options = RES_DEFAULT; 155*aa6411e2SAugustin Cavalier 156*aa6411e2SAugustin Cavalier /* 157*aa6411e2SAugustin Cavalier * This one used to initialize implicitly to zero, so unless the app 158*aa6411e2SAugustin Cavalier * has set it to something in particular, we can randomize it now. 159*aa6411e2SAugustin Cavalier */ 160*aa6411e2SAugustin Cavalier if (!_nres.id) 161*aa6411e2SAugustin Cavalier _nres.id = res_nrandomid(&_nres); 162*aa6411e2SAugustin Cavalier 163*aa6411e2SAugustin Cavalier rv = __res_vinit(&_nres, 1); 164*aa6411e2SAugustin Cavalier #ifdef COMPAT__RES 165*aa6411e2SAugustin Cavalier __res_put_old_state(&_nres); 166*aa6411e2SAugustin Cavalier #endif 167*aa6411e2SAugustin Cavalier return rv; 168*aa6411e2SAugustin Cavalier } 169*aa6411e2SAugustin Cavalier 170*aa6411e2SAugustin Cavalier void 171*aa6411e2SAugustin Cavalier p_query(const u_char *msg) { 172*aa6411e2SAugustin Cavalier fp_query(msg, stdout); 173*aa6411e2SAugustin Cavalier } 174*aa6411e2SAugustin Cavalier 175*aa6411e2SAugustin Cavalier void 176*aa6411e2SAugustin Cavalier fp_query(const u_char *msg, FILE *file) { 177*aa6411e2SAugustin Cavalier fp_nquery(msg, PACKETSZ, file); 178*aa6411e2SAugustin Cavalier } 179*aa6411e2SAugustin Cavalier 180*aa6411e2SAugustin Cavalier void 181*aa6411e2SAugustin Cavalier fp_nquery(const u_char *msg, int len, FILE *file) { 182*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) 183*aa6411e2SAugustin Cavalier return; 184*aa6411e2SAugustin Cavalier 185*aa6411e2SAugustin Cavalier res_pquery(&_nres, msg, len, file); 186*aa6411e2SAugustin Cavalier } 187*aa6411e2SAugustin Cavalier 188*aa6411e2SAugustin Cavalier int 189*aa6411e2SAugustin Cavalier res_mkquery(int op, /*!< opcode of query */ 190*aa6411e2SAugustin Cavalier const char *dname, /*!< domain name */ 191*aa6411e2SAugustin Cavalier int class, int type, /*!< class and type of query */ 192*aa6411e2SAugustin Cavalier const u_char *data, /*!< resource record data */ 193*aa6411e2SAugustin Cavalier int datalen, /*!< length of data */ 194*aa6411e2SAugustin Cavalier const u_char *newrr_in, /*!< new rr for modify or append */ 195*aa6411e2SAugustin Cavalier u_char *buf, /*!< buffer to put query */ 196*aa6411e2SAugustin Cavalier int buflen) /*!< size of buffer */ 197*aa6411e2SAugustin Cavalier { 198*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 199*aa6411e2SAugustin Cavalier RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 200*aa6411e2SAugustin Cavalier return (-1); 201*aa6411e2SAugustin Cavalier } 202*aa6411e2SAugustin Cavalier return (res_nmkquery(&_nres, op, dname, class, type, 203*aa6411e2SAugustin Cavalier data, datalen, 204*aa6411e2SAugustin Cavalier newrr_in, buf, buflen)); 205*aa6411e2SAugustin Cavalier } 206*aa6411e2SAugustin Cavalier 207*aa6411e2SAugustin Cavalier #ifdef _LIBRESOLV 208*aa6411e2SAugustin Cavalier int 209*aa6411e2SAugustin Cavalier res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { 210*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 211*aa6411e2SAugustin Cavalier RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 212*aa6411e2SAugustin Cavalier return (-1); 213*aa6411e2SAugustin Cavalier } 214*aa6411e2SAugustin Cavalier 215*aa6411e2SAugustin Cavalier return (res_nmkupdate(&_nres, rrecp_in, buf, buflen)); 216*aa6411e2SAugustin Cavalier } 217*aa6411e2SAugustin Cavalier #endif 218*aa6411e2SAugustin Cavalier 219*aa6411e2SAugustin Cavalier int 220*aa6411e2SAugustin Cavalier res_query(const char *name, /*!< domain name */ 221*aa6411e2SAugustin Cavalier int class, int type, /*!< class and type of query */ 222*aa6411e2SAugustin Cavalier u_char *answer, /*!< buffer to put answer */ 223*aa6411e2SAugustin Cavalier int anslen) /*!< size of answer buffer */ 224*aa6411e2SAugustin Cavalier { 225*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 226*aa6411e2SAugustin Cavalier RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 227*aa6411e2SAugustin Cavalier return (-1); 228*aa6411e2SAugustin Cavalier } 229*aa6411e2SAugustin Cavalier return (res_nquery(&_nres, name, class, type, answer, anslen)); 230*aa6411e2SAugustin Cavalier } 231*aa6411e2SAugustin Cavalier 232*aa6411e2SAugustin Cavalier void 233*aa6411e2SAugustin Cavalier res_send_setqhook(res_send_qhook hook) { 234*aa6411e2SAugustin Cavalier _nres.qhook = hook; 235*aa6411e2SAugustin Cavalier } 236*aa6411e2SAugustin Cavalier 237*aa6411e2SAugustin Cavalier void 238*aa6411e2SAugustin Cavalier res_send_setrhook(res_send_rhook hook) { 239*aa6411e2SAugustin Cavalier _nres.rhook = hook; 240*aa6411e2SAugustin Cavalier } 241*aa6411e2SAugustin Cavalier 242*aa6411e2SAugustin Cavalier int 243*aa6411e2SAugustin Cavalier res_isourserver(const struct sockaddr_in *inp) { 244*aa6411e2SAugustin Cavalier return (res_ourserver_p(&_nres, (const struct sockaddr *)(const void *)inp)); 245*aa6411e2SAugustin Cavalier } 246*aa6411e2SAugustin Cavalier 247*aa6411e2SAugustin Cavalier int 248*aa6411e2SAugustin Cavalier res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) { 249*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 250*aa6411e2SAugustin Cavalier /* errno should have been set by res_init() in this case. */ 251*aa6411e2SAugustin Cavalier return (-1); 252*aa6411e2SAugustin Cavalier } 253*aa6411e2SAugustin Cavalier 254*aa6411e2SAugustin Cavalier return (res_nsend(&_nres, buf, buflen, ans, anssiz)); 255*aa6411e2SAugustin Cavalier } 256*aa6411e2SAugustin Cavalier 257*aa6411e2SAugustin Cavalier #ifdef _LIBRESOLV 258*aa6411e2SAugustin Cavalier int 259*aa6411e2SAugustin Cavalier res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key, 260*aa6411e2SAugustin Cavalier u_char *ans, int anssiz) 261*aa6411e2SAugustin Cavalier { 262*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 263*aa6411e2SAugustin Cavalier /* errno should have been set by res_init() in this case. */ 264*aa6411e2SAugustin Cavalier return (-1); 265*aa6411e2SAugustin Cavalier } 266*aa6411e2SAugustin Cavalier 267*aa6411e2SAugustin Cavalier return (res_nsendsigned(&_nres, buf, buflen, key, ans, anssiz)); 268*aa6411e2SAugustin Cavalier } 269*aa6411e2SAugustin Cavalier #endif 270*aa6411e2SAugustin Cavalier 271*aa6411e2SAugustin Cavalier void 272*aa6411e2SAugustin Cavalier res_close(void) { 273*aa6411e2SAugustin Cavalier res_nclose(&_nres); 274*aa6411e2SAugustin Cavalier } 275*aa6411e2SAugustin Cavalier 276*aa6411e2SAugustin Cavalier #ifdef _LIBRESOLV 277*aa6411e2SAugustin Cavalier int 278*aa6411e2SAugustin Cavalier res_update(ns_updrec *rrecp_in) { 279*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 280*aa6411e2SAugustin Cavalier RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 281*aa6411e2SAugustin Cavalier return (-1); 282*aa6411e2SAugustin Cavalier } 283*aa6411e2SAugustin Cavalier 284*aa6411e2SAugustin Cavalier return (res_nupdate(&_nres, rrecp_in, NULL)); 285*aa6411e2SAugustin Cavalier } 286*aa6411e2SAugustin Cavalier #endif 287*aa6411e2SAugustin Cavalier 288*aa6411e2SAugustin Cavalier int 289*aa6411e2SAugustin Cavalier res_search(const char *name, /*!< domain name */ 290*aa6411e2SAugustin Cavalier int class, int type, /*!< class and type of query */ 291*aa6411e2SAugustin Cavalier u_char *answer, /*!< buffer to put answer */ 292*aa6411e2SAugustin Cavalier int anslen) /*!< size of answer */ 293*aa6411e2SAugustin Cavalier { 294*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 295*aa6411e2SAugustin Cavalier RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 296*aa6411e2SAugustin Cavalier return (-1); 297*aa6411e2SAugustin Cavalier } 298*aa6411e2SAugustin Cavalier 299*aa6411e2SAugustin Cavalier return (res_nsearch(&_nres, name, class, type, answer, anslen)); 300*aa6411e2SAugustin Cavalier } 301*aa6411e2SAugustin Cavalier 302*aa6411e2SAugustin Cavalier int 303*aa6411e2SAugustin Cavalier res_querydomain(const char *name, 304*aa6411e2SAugustin Cavalier const char *domain, 305*aa6411e2SAugustin Cavalier int class, int type, /*!< class and type of query */ 306*aa6411e2SAugustin Cavalier u_char *answer, /*!< buffer to put answer */ 307*aa6411e2SAugustin Cavalier int anslen) /*!< size of answer */ 308*aa6411e2SAugustin Cavalier { 309*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 310*aa6411e2SAugustin Cavalier RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 311*aa6411e2SAugustin Cavalier return (-1); 312*aa6411e2SAugustin Cavalier } 313*aa6411e2SAugustin Cavalier 314*aa6411e2SAugustin Cavalier return (res_nquerydomain(&_nres, name, domain, 315*aa6411e2SAugustin Cavalier class, type, 316*aa6411e2SAugustin Cavalier answer, anslen)); 317*aa6411e2SAugustin Cavalier } 318*aa6411e2SAugustin Cavalier 319*aa6411e2SAugustin Cavalier u_int 320*aa6411e2SAugustin Cavalier res_randomid(void) { 321*aa6411e2SAugustin Cavalier if ((_nres.options & RES_INIT) == 0U && res_init() == -1) { 322*aa6411e2SAugustin Cavalier RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); 323*aa6411e2SAugustin Cavalier return (u_int)-1; 324*aa6411e2SAugustin Cavalier } 325*aa6411e2SAugustin Cavalier 326*aa6411e2SAugustin Cavalier return (res_nrandomid(&_nres)); 327*aa6411e2SAugustin Cavalier } 328*aa6411e2SAugustin Cavalier 329*aa6411e2SAugustin Cavalier const char * 330*aa6411e2SAugustin Cavalier hostalias(const char *name) { 331*aa6411e2SAugustin Cavalier static char abuf[MAXDNAME]; 332*aa6411e2SAugustin Cavalier 333*aa6411e2SAugustin Cavalier return (res_hostalias(&_nres, name, abuf, sizeof abuf)); 334*aa6411e2SAugustin Cavalier } 335*aa6411e2SAugustin Cavalier 336*aa6411e2SAugustin Cavalier #ifdef ultrix 337*aa6411e2SAugustin Cavalier int 338*aa6411e2SAugustin Cavalier local_hostname_length(const char *hostname) { 339*aa6411e2SAugustin Cavalier int len_host, len_domain; 340*aa6411e2SAugustin Cavalier 341*aa6411e2SAugustin Cavalier if (!*_nres.defdname) 342*aa6411e2SAugustin Cavalier res_init(); 343*aa6411e2SAugustin Cavalier len_host = strlen(hostname); 344*aa6411e2SAugustin Cavalier len_domain = strlen(_nres.defdname); 345*aa6411e2SAugustin Cavalier if (len_host > len_domain && 346*aa6411e2SAugustin Cavalier !strcasecmp(hostname + len_host - len_domain, _nres.defdname) && 347*aa6411e2SAugustin Cavalier hostname[len_host - len_domain - 1] == '.') 348*aa6411e2SAugustin Cavalier return (len_host - len_domain - 1); 349*aa6411e2SAugustin Cavalier return (0); 350*aa6411e2SAugustin Cavalier } 351*aa6411e2SAugustin Cavalier #endif /*ultrix*/ 352*aa6411e2SAugustin Cavalier 353*aa6411e2SAugustin Cavalier #endif 354*aa6411e2SAugustin Cavalier 355*aa6411e2SAugustin Cavalier /*! \file */ 356