xref: /third_party/musl/src/network/gethostbyname2.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/musl/src/network/
1570af302Sopenharmony_ci#define _GNU_SOURCE
2570af302Sopenharmony_ci
3570af302Sopenharmony_ci#include <sys/socket.h>
4570af302Sopenharmony_ci#include <netdb.h>
5570af302Sopenharmony_ci#include <errno.h>
6570af302Sopenharmony_ci#include <stdlib.h>
7570af302Sopenharmony_ci
8570af302Sopenharmony_cistruct hostent *gethostbyname2(const char *name, int af)
9570af302Sopenharmony_ci{
10570af302Sopenharmony_ci	static struct hostent *h;
11570af302Sopenharmony_ci	size_t size = 63;
12570af302Sopenharmony_ci	struct hostent *res;
13570af302Sopenharmony_ci	int err;
14570af302Sopenharmony_ci	do {
15570af302Sopenharmony_ci		free(h);
16570af302Sopenharmony_ci		h = malloc(size+=size+1);
17570af302Sopenharmony_ci		if (!h) {
18570af302Sopenharmony_ci			h_errno = NO_RECOVERY;
19570af302Sopenharmony_ci			return 0;
20570af302Sopenharmony_ci		}
21570af302Sopenharmony_ci		err = gethostbyname2_r(name, af, h,
22570af302Sopenharmony_ci			(void *)(h+1), size-sizeof *h, &res, &h_errno);
23570af302Sopenharmony_ci	} while (err == ERANGE);
24570af302Sopenharmony_ci	return res;
25570af302Sopenharmony_ci}
26

Indexes created Thu Nov 07 10:32:03 CST 2024