summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbeck <>2017-04-30 05:43:05 +0000
committerbeck <>2017-04-30 05:43:05 +0000
commitab6489f9fe1d54c4799bb9b1897f63682f710529 (patch)
treecab1a916afbeb80fc28426c7fa4bc878b35e2e96 /src
parentb6c1bd93474354589e68df26b2f8a85cb2010603 (diff)
downloadopenbsd-ab6489f9fe1d54c4799bb9b1897f63682f710529.tar.gz
openbsd-ab6489f9fe1d54c4799bb9b1897f63682f710529.tar.bz2
openbsd-ab6489f9fe1d54c4799bb9b1897f63682f710529.zip
Make BIO_get_host_ip just yet another getaddrinfo wrapper
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bio/b_sock.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
index b8aba39578..af3e35e66b 100644
--- a/src/lib/libcrypto/bio/b_sock.c
+++ b/src/lib/libcrypto/bio/b_sock.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: b_sock.c,v 1.65 2017/04/30 05:09:22 beck Exp $ */ 1/* $OpenBSD: b_sock.c,v 1.66 2017/04/30 05:43:05 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -78,36 +78,29 @@
78int 78int
79BIO_get_host_ip(const char *str, unsigned char *ip) 79BIO_get_host_ip(const char *str, unsigned char *ip)
80{ 80{
81 int i; 81 struct addrinfo *res = NULL;
82 int err = 1; 82 struct addrinfo hints = {
83 struct hostent *he; 83 .ai_family = AF_INET,
84 84 .ai_socktype = SOCK_STREAM,
85 if (inet_pton(AF_INET, str, ip) == 1) 85 .ai_flags = AI_PASSIVE,
86 return (1); 86 };
87 uint32_t *iap = (in_addr_t *)ip;
88 int error;
87 89
88 /* do a gethostbyname */ 90 if (str == NULL) {
89 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); 91 ERR_asprintf_error_data("NULL host provided");
90 he = BIO_gethostbyname(str); 92 return (0);
91 if (he == NULL) {
92 BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP);
93 goto err;
94 } 93 }
95 94
96 if (he->h_addrtype != AF_INET) { 95 if ((error = getaddrinfo(str, NULL, &hints, &res)) != 0) {
97 BIOerror(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); 96 BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP);
98 goto err; 97 ERR_asprintf_error_data("getaddrinfo: host='%s' : %s'", str,
98 gai_strerror(error));
99 return (0);
99 } 100 }
100 for (i = 0; i < 4; i++) 101 *iap = (uint32_t)(((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr);
101 ip[i] = he->h_addr_list[0][i]; 102 freeaddrinfo(res);
102 err = 0; 103 return (1);
103
104err:
105 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
106 if (err) {
107 ERR_asprintf_error_data("host=%s", str);
108 return 0;
109 } else
110 return 1;
111} 104}
112 105
113int 106int