| 1 | /* |
| 2 | * dns.h |
| 3 | * |
| 4 | * Copyright (C) 2018 Aerospike, Inc. |
| 5 | * |
| 6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
| 7 | * license agreements. |
| 8 | * |
| 9 | * This program is free software: you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU Affero General Public License as published by the Free |
| 11 | * Software Foundation, either version 3 of the License, or (at your option) any |
| 12 | * later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
| 17 | * details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | #include <limits.h> |
| 26 | #include <netdb.h> |
| 27 | #include <stdbool.h> |
| 28 | #include <sys/types.h> |
| 29 | #include <sys/socket.h> |
| 30 | |
| 31 | #define DNS_NAME_MAX_LEN 255 |
| 32 | #define DNS_NAME_MAX_SIZE (DNS_NAME_MAX_LEN + 1) |
| 33 | |
| 34 | #define CF_MUST_CHECK __attribute__((warn_unused_result)) |
| 35 | |
| 36 | typedef struct addrinfo addrinfo; |
| 37 | |
| 38 | /** |
| 39 | * Callback after asynchronous name resolution. |
| 40 | * |
| 41 | * @param status 0 iff the name resolution succeeded, else an error code. |
| 42 | * @param hostname the hostname being resolved. |
| 43 | * @param addrs the result of dns resolution. Should be freed using cf_dns_free |
| 44 | * once the addresses are no longer required. Will not be NULL when status is |
| 45 | * zero. |
| 46 | * @param udata udata passed to the asynchronous resolve function. |
| 47 | */ |
| 48 | typedef void (*cf_dns_resolve_cb)(const int status, const char* hostname, addrinfo* addrs, void* udata); |
| 49 | |
| 50 | void cf_dns_init(); |
| 51 | void cf_dns_resolve_a(const char* hostname, addrinfo* hints, cf_dns_resolve_cb cb, |
| 52 | void* udata); |
| 53 | CF_MUST_CHECK int cf_dns_resolve(const char* hostname, addrinfo* hints, addrinfo** addrs); |
| 54 | const char* cf_dns_strerror(int errcode); |
| 55 | void cf_dns_free(addrinfo* addrs); |
| 56 | |