summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjaredy <>2005-07-23 04:15:49 +0000
committerjaredy <>2005-07-23 04:15:49 +0000
commit2c2fe16031333976a7e95d7e0caf5fc7f8c32412 (patch)
treeebbed1ec9881199a73693c582c1f3c304d4f5e42 /src
parent3553ae132550867ea92f1c819130713a94c9aa57 (diff)
downloadopenbsd-2c2fe16031333976a7e95d7e0caf5fc7f8c32412.tar.gz
openbsd-2c2fe16031333976a7e95d7e0caf5fc7f8c32412.tar.bz2
openbsd-2c2fe16031333976a7e95d7e0caf5fc7f8c32412.zip
*hostent() fixes:
- Make _gethtent() static - _gethtbyname() is dead code (succeeded by _gethtbyname2), kill it - _gethtent() requires setting the address family field of the file-scope variable `host' to that of the desired type of the entry being searched for. Change the behavior to enforce this if it is not AF_UNSPEC, which will now allow stepping through entries, and set it to specific values everywhere else. help & ok millert
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/net/gethostnamadr.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c
index b036efe2d1..626f9a6e65 100644
--- a/src/lib/libc/net/gethostnamadr.c
+++ b/src/lib/libc/net/gethostnamadr.c
@@ -48,7 +48,7 @@
48 */ 48 */
49 49
50#if defined(LIBC_SCCS) && !defined(lint) 50#if defined(LIBC_SCCS) && !defined(lint)
51static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.63 2005/06/08 18:32:34 millert Exp $"; 51static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.64 2005/07/23 04:15:49 jaredy Exp $";
52#endif /* LIBC_SCCS and not lint */ 52#endif /* LIBC_SCCS and not lint */
53 53
54#include <sys/param.h> 54#include <sys/param.h>
@@ -786,7 +786,7 @@ _endhtent(void)
786 } 786 }
787} 787}
788 788
789struct hostent * 789static struct hostent *
790_gethtent(void) 790_gethtent(void)
791{ 791{
792 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); 792 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
@@ -832,10 +832,12 @@ _gethtent(void)
832 goto again; 832 goto again;
833 } 833 }
834 /* if this is not something we're looking for, skip it. */ 834 /* if this is not something we're looking for, skip it. */
835 if (host.h_addrtype != af) 835 if (host.h_addrtype != AF_UNSPEC) {
836 goto again; 836 if (host.h_addrtype != af)
837 if (host.h_length != len) 837 goto again;
838 goto again; 838 if (host.h_length != len)
839 goto again;
840 }
839 h_addr_ptrs[0] = (char *)host_addr; 841 h_addr_ptrs[0] = (char *)host_addr;
840 h_addr_ptrs[1] = NULL; 842 h_addr_ptrs[1] = NULL;
841 host.h_addr_list = h_addr_ptrs; 843 host.h_addr_list = h_addr_ptrs;
@@ -869,26 +871,13 @@ _gethtent(void)
869} 871}
870 872
871struct hostent * 873struct hostent *
872_gethtbyname(const char *name)
873{
874 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
875 struct hostent *hp;
876 extern struct hostent *_gethtbyname2(const char *, int);
877
878 if (_resp->options & RES_USE_INET6) {
879 hp = _gethtbyname2(name, AF_INET6);
880 if (hp)
881 return (hp);
882 }
883 return (_gethtbyname2(name, AF_INET));
884}
885
886struct hostent *
887_gethtbyname2(const char *name, int af) 874_gethtbyname2(const char *name, int af)
888{ 875{
889 struct hostent *p; 876 struct hostent *p;
890 char **cp; 877 char **cp;
891 878
879 host.h_addrtype = af;
880
892 _sethtent(0); 881 _sethtent(0);
893 while ((p = _gethtent())) { 882 while ((p = _gethtent())) {
894 if (p->h_addrtype != af) 883 if (p->h_addrtype != af)
@@ -914,7 +903,8 @@ _gethtbyaddr(const void *addr, socklen_t len, int af)
914 903
915 _sethtent(0); 904 _sethtent(0);
916 while ((p = _gethtent())) 905 while ((p = _gethtent()))
917 if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len)) 906 if (p->h_addrtype == af && p->h_length == len &&
907 !bcmp(p->h_addr, addr, len))
918 break; 908 break;
919 _endhtent(); 909 _endhtent();
920 return (p); 910 return (p);
@@ -1093,6 +1083,7 @@ map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep)
1093struct hostent * 1083struct hostent *
1094gethostent(void) 1084gethostent(void)
1095{ 1085{
1086 host.h_addrtype = AF_UNSPEC;
1096 return (_gethtent()); 1087 return (_gethtent());
1097} 1088}
1098 1089