- int ret;
-
- dns_requests = xmalloc (sizeof (struct gaicb*));
- dns_requests[0] = xmalloc (sizeof (struct gaicb));
- dns_requests[0]->ar_name = strdup (SSDATA (host));
- dns_requests[0]->ar_service = strdup (portstring);
- dns_requests[0]->ar_request = hints;
- dns_requests[0]->ar_result = NULL;
-
- ret = getaddrinfo_a (GAI_NOWAIT, dns_requests, 1, NULL);
+ ptrdiff_t hostlen = SBYTES (host);
+ struct req
+ {
+ struct gaicb gaicb;
+ struct addrinfo hints;
+ char str[FLEXIBLE_ARRAY_MEMBER];
+ } *req = xmalloc (offsetof (struct req, str)
+ + hostlen + 1 + portstringlen + 1);
+ dns_request = &req->gaicb;
+ dns_request->ar_name = req->str;
+ dns_request->ar_service = req->str + hostlen + 1;
+ dns_request->ar_request = &req->hints;
+ dns_request->ar_result = NULL;
+ memset (&req->hints, 0, sizeof req->hints);
+ req->hints.ai_family = family;
+ req->hints.ai_socktype = socktype;
+ strcpy (req->str, SSDATA (host));
+ strcpy (req->str + hostlen + 1, portstring);
+
+ int ret = getaddrinfo_a (GAI_NOWAIT, &dns_request, 1, NULL);