36#include <sys/socket.h>
42#ifdef HAVE_GETADDRINFO_A
52static struct addrinfo *mutt_getaddrinfo_a(
const char *node,
const struct addrinfo *hints)
56 struct addrinfo *result = NULL;
61 struct timespec timeout = { 0, 100000000 };
62 struct gaicb req = { 0 };
64 req.ar_request = hints;
65 struct gaicb *reqs[1] = { &req };
66 if (getaddrinfo_a(GAI_NOWAIT, reqs, 1, NULL) == 0)
68 gai_suspend((
const struct gaicb *
const *) reqs, 1, &timeout);
69 const int status = gai_error(reqs[0]);
72 result = reqs[0]->ar_result;
74 else if (status == EAI_INPROGRESS)
78 if (gai_cancel(reqs[0]) == EAI_NOTCANCELED)
82 gai_suspend((
const struct gaicb *
const *) reqs, 1, &timeout);
93#elif defined(HAVE_GETADDRINFO)
107 struct addrinfo *result = NULL;
109 int rc = getaddrinfo(node, NULL, hints, &result);
130#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETADDRINFO_A)
131 char node[256] = { 0 };
132 if (gethostname(node,
sizeof(node)) != 0)
135 struct addrinfo *lookup_result = NULL;
136 struct addrinfo hints = { 0 };
139 hints.ai_flags = AI_CANONNAME;
140 hints.ai_family = AF_UNSPEC;
142#ifdef HAVE_GETADDRINFO_A
143 lookup_result = mutt_getaddrinfo_a(node, &hints);
148 if (lookup_result && lookup_result->ai_canonname)
150 const char *hostname = strchr(lookup_result->ai_canonname,
'.');
151 if (hostname && hostname[1] !=
'\0')
159 freeaddrinfo(lookup_result);
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a 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.