res_gethost.c (d67944fb) | res_gethost.c (bd0e95e6) |
---|---|
1/* | 1/* |
2 * Copyright 2015 Gary Mills |
|
2 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6/* 7 * Copyright (c) 1985, 1988 Regents of the University of California. 8 * All rights reserved. 9 * --- 8 unchanged lines hidden (view full) --- 18 19#include <sys/param.h> 20#include <sys/socket.h> 21#include <netinet/in.h> 22#include <ctype.h> 23#include <netdb.h> 24#include <stdio.h> 25#include <errno.h> | 3 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 4 * Use is subject to license terms. 5 */ 6 7/* 8 * Copyright (c) 1985, 1988 Regents of the University of California. 9 * All rights reserved. 10 * --- 8 unchanged lines hidden (view full) --- 19 20#include <sys/param.h> 21#include <sys/socket.h> 22#include <netinet/in.h> 23#include <ctype.h> 24#include <netdb.h> 25#include <stdio.h> 26#include <errno.h> |
27#include <string.h> |
|
26#include <arpa/inet.h> 27#include <arpa/nameser.h> 28#include <resolv.h> 29#include <syslog.h> | 28#include <arpa/inet.h> 29#include <arpa/nameser.h> 30#include <resolv.h> 31#include <syslog.h> |
32#include "crossl.h" |
|
30 31/* 32 * When the name service switch calls libresolv, it doesn't want fallback 33 * to /etc/hosts, so we provide a method to turn it off. 34 */ 35static int no_hosts_fallback = 0; 36 37void --- 60 unchanged lines hidden (view full) --- 98 hp = &answer->hdr; 99 ancount = ntohs(hp->ancount); 100 qdcount = ntohs(hp->qdcount); 101 bp = hostbuf; 102 buflen = sizeof (hostbuf); 103 cp = answer->buf + sizeof (HEADER); 104 if (qdcount) { 105 if (iquery) { | 33 34/* 35 * When the name service switch calls libresolv, it doesn't want fallback 36 * to /etc/hosts, so we provide a method to turn it off. 37 */ 38static int no_hosts_fallback = 0; 39 40void --- 60 unchanged lines hidden (view full) --- 101 hp = &answer->hdr; 102 ancount = ntohs(hp->ancount); 103 qdcount = ntohs(hp->qdcount); 104 bp = hostbuf; 105 buflen = sizeof (hostbuf); 106 cp = answer->buf + sizeof (HEADER); 107 if (qdcount) { 108 if (iquery) { |
106 if ((n = dn_expand((char *)answer->buf, eom, 107 cp, bp, buflen)) < 0) { | 109 if ((n = dn_expand(answer->buf, eom, 110 cp, (u_char *)bp, buflen)) < 0) { |
108 h_errno = NO_RECOVERY; 109 return ((struct hostent *) NULL); 110 } 111 cp += n + QFIXEDSZ; 112 host.h_name = bp; 113 n = strlen(bp) + 1; 114 bp += n; 115 buflen -= n; --- 11 unchanged lines hidden (view full) --- 127 ap = host_aliases; 128 host.h_aliases = host_aliases; 129 hap = h_addr_ptrs; 130#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */ 131 host.h_addr_list = h_addr_ptrs; 132#endif 133 haveanswer = 0; 134 while (--ancount >= 0 && cp < eom && haveanswer < MAXADDRS) { | 111 h_errno = NO_RECOVERY; 112 return ((struct hostent *) NULL); 113 } 114 cp += n + QFIXEDSZ; 115 host.h_name = bp; 116 n = strlen(bp) + 1; 117 bp += n; 118 buflen -= n; --- 11 unchanged lines hidden (view full) --- 130 ap = host_aliases; 131 host.h_aliases = host_aliases; 132 hap = h_addr_ptrs; 133#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */ 134 host.h_addr_list = h_addr_ptrs; 135#endif 136 haveanswer = 0; 137 while (--ancount >= 0 && cp < eom && haveanswer < MAXADDRS) { |
135 if ((n = dn_expand((char *)answer->buf, eom, 136 cp, bp, buflen)) < 0) | 138 if ((n = dn_expand(answer->buf, eom, 139 cp, (u_char *)bp, buflen)) < 0) |
137 break; 138 cp += n; 139 type = _getshort(cp); 140 cp += sizeof (u_short); 141 class = _getshort(cp); 142 cp += sizeof (u_short) + sizeof (u_long); 143 n = _getshort(cp); 144 cp += sizeof (u_short); 145 if (type == T_CNAME) { 146 cp += n; 147 if (ap >= &host_aliases[MAXALIASES-1]) 148 continue; 149 *ap++ = bp; 150 n = strlen(bp) + 1; 151 bp += n; 152 buflen -= n; 153 continue; 154 } 155 if (iquery && type == T_PTR) { | 140 break; 141 cp += n; 142 type = _getshort(cp); 143 cp += sizeof (u_short); 144 class = _getshort(cp); 145 cp += sizeof (u_short) + sizeof (u_long); 146 n = _getshort(cp); 147 cp += sizeof (u_short); 148 if (type == T_CNAME) { 149 cp += n; 150 if (ap >= &host_aliases[MAXALIASES-1]) 151 continue; 152 *ap++ = bp; 153 n = strlen(bp) + 1; 154 bp += n; 155 buflen -= n; 156 continue; 157 } 158 if (iquery && type == T_PTR) { |
156 if ((n = dn_expand((char *)answer->buf, eom, 157 cp, bp, buflen)) < 0) { | 159 if ((n = dn_expand(answer->buf, eom, 160 cp, (u_char *)bp, buflen)) < 0) { |
158 cp += n; 159 continue; 160 } 161 cp += n; 162 host.h_name = bp; 163 return (&host); 164 } 165 if (iquery || type != T_A) { --- 60 unchanged lines hidden (view full) --- 226 227struct hostent * 228res_gethostbyname(name) 229 char *name; 230{ 231 querybuf buf; 232 register char *cp; 233 int n; | 161 cp += n; 162 continue; 163 } 164 cp += n; 165 host.h_name = bp; 166 return (&host); 167 } 168 if (iquery || type != T_A) { --- 60 unchanged lines hidden (view full) --- 229 230struct hostent * 231res_gethostbyname(name) 232 char *name; 233{ 234 querybuf buf; 235 register char *cp; 236 int n; |
234 struct hostent *hp, *gethostdomain(); | |
235 236 /* 237 * disallow names consisting only of digits/dots, unless 238 * they end in a dot. 239 */ 240 if (isdigit(name[0])) 241 for (cp = name; /*EMPTY*/; ++cp) { 242 if (!*cp) { --- 33 unchanged lines hidden (view full) --- 276 277 if (type != AF_INET) 278 return ((struct hostent *) NULL); 279 (void) sprintf(qbuf, "%d.%d.%d.%d.in-addr.arpa", 280 ((unsigned)addr[3] & 0xff), 281 ((unsigned)addr[2] & 0xff), 282 ((unsigned)addr[1] & 0xff), 283 ((unsigned)addr[0] & 0xff)); | 237 238 /* 239 * disallow names consisting only of digits/dots, unless 240 * they end in a dot. 241 */ 242 if (isdigit(name[0])) 243 for (cp = name; /*EMPTY*/; ++cp) { 244 if (!*cp) { --- 33 unchanged lines hidden (view full) --- 278 279 if (type != AF_INET) 280 return ((struct hostent *) NULL); 281 (void) sprintf(qbuf, "%d.%d.%d.%d.in-addr.arpa", 282 ((unsigned)addr[3] & 0xff), 283 ((unsigned)addr[2] & 0xff), 284 ((unsigned)addr[1] & 0xff), 285 ((unsigned)addr[0] & 0xff)); |
284 n = res_query(qbuf, C_IN, T_PTR, (char *)&buf, sizeof (buf)); | 286 n = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof (buf)); |
285 if (n < 0) { 286#ifdef DEBUG 287 if (_res.options & RES_DEBUG) 288 printf("res_query failed\n"); 289#endif 290 if (errno == ECONNREFUSED) 291 return (_gethtbyaddr(addr, len, type)); 292 return ((struct hostent *) NULL); --- 182 unchanged lines hidden --- | 287 if (n < 0) { 288#ifdef DEBUG 289 if (_res.options & RES_DEBUG) 290 printf("res_query failed\n"); 291#endif 292 if (errno == ECONNREFUSED) 293 return (_gethtbyaddr(addr, len, type)); 294 return ((struct hostent *) NULL); --- 182 unchanged lines hidden --- |