summaryrefslogtreecommitdiff
path: root/lib/libcrypto/bio/b_sock.c
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2017-04-30 05:43:06 +0000
committerBob Beck <beck@cvs.openbsd.org>2017-04-30 05:43:06 +0000
commit4f92ebab78078f7c8bd039422c61225b280897ae (patch)
treefad514a3da9d56a80f15af5c6bfe5d765fd1e6bf /lib/libcrypto/bio/b_sock.c
parentb08e795a4562f83254d29eaeeae405e56ee80996 (diff)
Make BIO_get_host_ip just yet another getaddrinfo wrapper
Diffstat (limited to 'lib/libcrypto/bio/b_sock.c')
-rw-r--r--lib/libcrypto/bio/b_sock.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/lib/libcrypto/bio/b_sock.c b/lib/libcrypto/bio/b_sock.c
index b8aba395782..af3e35e66bf 100644
--- a/lib/libcrypto/bio/b_sock.c
+++ b/lib/libcrypto/bio/b_sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: b_sock.c,v 1.65 2017/04/30 05:09:22 beck Exp $ */
+/* $OpenBSD: b_sock.c,v 1.66 2017/04/30 05:43:05 beck Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -78,36 +78,29 @@
int
BIO_get_host_ip(const char *str, unsigned char *ip)
{
- int i;
- int err = 1;
- struct hostent *he;
-
- if (inet_pton(AF_INET, str, ip) == 1)
- return (1);
+ struct addrinfo *res = NULL;
+ struct addrinfo hints = {
+ .ai_family = AF_INET,
+ .ai_socktype = SOCK_STREAM,
+ .ai_flags = AI_PASSIVE,
+ };
+ uint32_t *iap = (in_addr_t *)ip;
+ int error;
- /* do a gethostbyname */
- CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
- he = BIO_gethostbyname(str);
- if (he == NULL) {
- BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP);
- goto err;
+ if (str == NULL) {
+ ERR_asprintf_error_data("NULL host provided");
+ return (0);
}
- if (he->h_addrtype != AF_INET) {
- BIOerror(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
- goto err;
+ if ((error = getaddrinfo(str, NULL, &hints, &res)) != 0) {
+ BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP);
+ ERR_asprintf_error_data("getaddrinfo: host='%s' : %s'", str,
+ gai_strerror(error));
+ return (0);
}
- for (i = 0; i < 4; i++)
- ip[i] = he->h_addr_list[0][i];
- err = 0;
-
-err:
- CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
- if (err) {
- ERR_asprintf_error_data("host=%s", str);
- return 0;
- } else
- return 1;
+ *iap = (uint32_t)(((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr);
+ freeaddrinfo(res);
+ return (1);
}
int