aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:44:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:49 +0300
commit718c552901d703c502ccbefdfc3c9028d608b947 (patch)
tree46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c
parente9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff)
downloadydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c')
-rw-r--r--contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c236
1 files changed, 118 insertions, 118 deletions
diff --git a/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c b/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c
index 6594723bb8..e9604107d7 100644
--- a/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c
+++ b/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c
@@ -1,118 +1,118 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/io/host_resolver.h>
-
-#include <aws/io/logging.h>
-
-#include <aws/common/string.h>
-
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-int aws_default_dns_resolve(
- struct aws_allocator *allocator,
- const struct aws_string *host_name,
- struct aws_array_list *output_addresses,
- void *user_data) {
-
- (void)user_data;
- struct addrinfo *result = NULL;
- struct addrinfo *iter = NULL;
- /* max string length for ipv6. */
- socklen_t max_len = INET6_ADDRSTRLEN;
- char address_buffer[max_len];
-
- const char *hostname_cstr = aws_string_c_str(host_name);
- AWS_LOGF_DEBUG(AWS_LS_IO_DNS, "static: resolving host %s", hostname_cstr);
-
- /* Android would prefer NO HINTS IF YOU DON'T MIND, SIR */
-#ifdef ANDROID
- int err_code = getaddrinfo(hostname_cstr, NULL, NULL, &result);
-#else
- struct addrinfo hints;
- AWS_ZERO_STRUCT(hints);
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_ALL | AI_V4MAPPED;
-
- int err_code = getaddrinfo(hostname_cstr, NULL, &hints, &result);
-#endif
-
- if (err_code) {
- AWS_LOGF_ERROR(AWS_LS_IO_DNS, "static: getaddrinfo failed with error_code %d", err_code);
- goto clean_up;
- }
-
- for (iter = result; iter != NULL; iter = iter->ai_next) {
- struct aws_host_address host_address;
-
- AWS_ZERO_ARRAY(address_buffer);
-
- if (iter->ai_family == AF_INET6) {
- host_address.record_type = AWS_ADDRESS_RECORD_TYPE_AAAA;
- inet_ntop(iter->ai_family, &((struct sockaddr_in6 *)iter->ai_addr)->sin6_addr, address_buffer, max_len);
- } else {
- host_address.record_type = AWS_ADDRESS_RECORD_TYPE_A;
- inet_ntop(iter->ai_family, &((struct sockaddr_in *)iter->ai_addr)->sin_addr, address_buffer, max_len);
- }
-
- size_t address_len = strlen(address_buffer);
- const struct aws_string *address =
- aws_string_new_from_array(allocator, (const uint8_t *)address_buffer, address_len);
-
- if (!address) {
- goto clean_up;
- }
-
- const struct aws_string *host_cpy = aws_string_new_from_string(allocator, host_name);
-
- if (!host_cpy) {
- aws_string_destroy((void *)address);
- goto clean_up;
- }
-
- AWS_LOGF_DEBUG(AWS_LS_IO_DNS, "static: resolved record: %s", address_buffer);
-
- host_address.address = address;
- host_address.weight = 0;
- host_address.allocator = allocator;
- host_address.use_count = 0;
- host_address.connection_failure_count = 0;
- host_address.host = host_cpy;
-
- if (aws_array_list_push_back(output_addresses, &host_address)) {
- aws_host_address_clean_up(&host_address);
- goto clean_up;
- }
- }
-
- freeaddrinfo(result);
- return AWS_OP_SUCCESS;
-
-clean_up:
- if (result) {
- freeaddrinfo(result);
- }
-
- if (err_code) {
- switch (err_code) {
- case EAI_FAIL:
- case EAI_AGAIN:
- return aws_raise_error(AWS_IO_DNS_QUERY_FAILED);
- case EAI_MEMORY:
- return aws_raise_error(AWS_ERROR_OOM);
- case EAI_NONAME:
- case EAI_SERVICE:
- return aws_raise_error(AWS_IO_DNS_INVALID_NAME);
- default:
- return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
- }
- }
-
- return AWS_OP_ERR;
-}
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+
+#include <aws/io/host_resolver.h>
+
+#include <aws/io/logging.h>
+
+#include <aws/common/string.h>
+
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+int aws_default_dns_resolve(
+ struct aws_allocator *allocator,
+ const struct aws_string *host_name,
+ struct aws_array_list *output_addresses,
+ void *user_data) {
+
+ (void)user_data;
+ struct addrinfo *result = NULL;
+ struct addrinfo *iter = NULL;
+ /* max string length for ipv6. */
+ socklen_t max_len = INET6_ADDRSTRLEN;
+ char address_buffer[max_len];
+
+ const char *hostname_cstr = aws_string_c_str(host_name);
+ AWS_LOGF_DEBUG(AWS_LS_IO_DNS, "static: resolving host %s", hostname_cstr);
+
+ /* Android would prefer NO HINTS IF YOU DON'T MIND, SIR */
+#ifdef ANDROID
+ int err_code = getaddrinfo(hostname_cstr, NULL, NULL, &result);
+#else
+ struct addrinfo hints;
+ AWS_ZERO_STRUCT(hints);
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_ALL | AI_V4MAPPED;
+
+ int err_code = getaddrinfo(hostname_cstr, NULL, &hints, &result);
+#endif
+
+ if (err_code) {
+ AWS_LOGF_ERROR(AWS_LS_IO_DNS, "static: getaddrinfo failed with error_code %d", err_code);
+ goto clean_up;
+ }
+
+ for (iter = result; iter != NULL; iter = iter->ai_next) {
+ struct aws_host_address host_address;
+
+ AWS_ZERO_ARRAY(address_buffer);
+
+ if (iter->ai_family == AF_INET6) {
+ host_address.record_type = AWS_ADDRESS_RECORD_TYPE_AAAA;
+ inet_ntop(iter->ai_family, &((struct sockaddr_in6 *)iter->ai_addr)->sin6_addr, address_buffer, max_len);
+ } else {
+ host_address.record_type = AWS_ADDRESS_RECORD_TYPE_A;
+ inet_ntop(iter->ai_family, &((struct sockaddr_in *)iter->ai_addr)->sin_addr, address_buffer, max_len);
+ }
+
+ size_t address_len = strlen(address_buffer);
+ const struct aws_string *address =
+ aws_string_new_from_array(allocator, (const uint8_t *)address_buffer, address_len);
+
+ if (!address) {
+ goto clean_up;
+ }
+
+ const struct aws_string *host_cpy = aws_string_new_from_string(allocator, host_name);
+
+ if (!host_cpy) {
+ aws_string_destroy((void *)address);
+ goto clean_up;
+ }
+
+ AWS_LOGF_DEBUG(AWS_LS_IO_DNS, "static: resolved record: %s", address_buffer);
+
+ host_address.address = address;
+ host_address.weight = 0;
+ host_address.allocator = allocator;
+ host_address.use_count = 0;
+ host_address.connection_failure_count = 0;
+ host_address.host = host_cpy;
+
+ if (aws_array_list_push_back(output_addresses, &host_address)) {
+ aws_host_address_clean_up(&host_address);
+ goto clean_up;
+ }
+ }
+
+ freeaddrinfo(result);
+ return AWS_OP_SUCCESS;
+
+clean_up:
+ if (result) {
+ freeaddrinfo(result);
+ }
+
+ if (err_code) {
+ switch (err_code) {
+ case EAI_FAIL:
+ case EAI_AGAIN:
+ return aws_raise_error(AWS_IO_DNS_QUERY_FAILED);
+ case EAI_MEMORY:
+ return aws_raise_error(AWS_ERROR_OOM);
+ case EAI_NONAME:
+ case EAI_SERVICE:
+ return aws_raise_error(AWS_IO_DNS_INVALID_NAME);
+ default:
+ return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
+ }
+ }
+
+ return AWS_OP_ERR;
+}