33#include <sys/socket.h>
39#ifdef HAVE_GETADDRINFO_A
49static struct addrinfo *mutt_getaddrinfo_a(
const char *node,
const struct addrinfo *hints)
53 struct addrinfo *result = NULL;
58 struct timespec timeout = { 0, 100000000 };
59 struct gaicb req = { 0 };
61 req.ar_request = hints;
62 struct gaicb *reqs[1] = { &req };
63 if (getaddrinfo_a(GAI_NOWAIT, reqs, 1, NULL) == 0)
65 gai_suspend((
const struct gaicb *
const *) reqs, 1, &timeout);
66 const int status = gai_error(reqs[0]);
69 result = reqs[0]->ar_result;
71 else if (status == EAI_INPROGRESS)
75 if (gai_cancel(reqs[0]) == EAI_NOTCANCELED)
79 gai_suspend((
const struct gaicb *
const *) reqs, 1, &timeout);
90#elif defined(HAVE_GETADDRINFO)
104 struct addrinfo *result = NULL;
106 int rc = getaddrinfo(node, NULL, hints, &result);
127#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETADDRINFO_A)
128 char node[256] = { 0 };
129 if (gethostname(node,
sizeof(node)) != 0)
132 struct addrinfo *lookup_result = NULL;
133 struct addrinfo hints;
136 memset(&hints, 0,
sizeof(
struct addrinfo));
137 hints.ai_flags = AI_CANONNAME;
138 hints.ai_family = AF_UNSPEC;
140#ifdef HAVE_GETADDRINFO_A
141 lookup_result = mutt_getaddrinfo_a(node, &hints);
146 if (lookup_result && lookup_result->ai_canonname)
148 const char *hostname = strchr(lookup_result->ai_canonname,
'.');
149 if (hostname && hostname[1] !=
'\0')
157 freeaddrinfo(lookup_result);
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
int getdnsdomainname(struct Buffer *result)
Lookup the host's name using DNS.
static struct addrinfo * mutt_getaddrinfo(const char *node, const struct addrinfo *hints)
Lookup the host's name using getaddrinfo()
#define mutt_debug(LEVEL,...)
@ LL_DEBUG3
Log at debug level 3.
@ LL_DEBUG1
Log at debug level 1.
Convenience wrapper for the library headers.
String manipulation buffer.
Time value with nanosecond precision.
long tv_nsec
Number of nanosecond, on top.