35#include <sys/socket.h>
41#ifdef HAVE_GETADDRINFO_A
51static struct addrinfo *mutt_getaddrinfo_a(
const char *node,
const struct addrinfo *hints)
55 struct addrinfo *result = NULL;
60 struct timespec timeout = { 0, 100000000 };
61 struct gaicb req = { 0 };
63 req.ar_request = hints;
64 struct gaicb *reqs[1] = { &req };
65 if (getaddrinfo_a(GAI_NOWAIT, reqs, 1, NULL) == 0)
67 gai_suspend((
const struct gaicb *
const *) reqs, 1, &timeout);
68 const int status = gai_error(reqs[0]);
71 result = reqs[0]->ar_result;
73 else if (status == EAI_INPROGRESS)
77 if (gai_cancel(reqs[0]) == EAI_NOTCANCELED)
80 timeout.tv_nsec = 50000000;
81 gai_suspend((
const struct gaicb *
const *) reqs, 1, &timeout);
92#elif defined(HAVE_GETADDRINFO)
106 struct addrinfo *result = NULL;
108 int rc = getaddrinfo(node, NULL, hints, &result);
129#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETADDRINFO_A)
130 char node[256] = { 0 };
131 if (gethostname(node,
sizeof(node)) != 0)
134 struct addrinfo *lookup_result = NULL;
135 struct addrinfo hints = { 0 };
138 hints.ai_flags = AI_CANONNAME;
139 hints.ai_family = AF_UNSPEC;
141#ifdef HAVE_GETADDRINFO_A
142 lookup_result = mutt_getaddrinfo_a(node, &hints);
147 if (lookup_result && lookup_result->ai_canonname)
149 const char *hostname = strchr(lookup_result->ai_canonname,
'.');
150 if (hostname && hostname[1] !=
'\0')
158 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.