gethostbyaddr.c 524 字节
Newer Older
R
Rich Felker 已提交
1 2 3
#define _GNU_SOURCE

#include <netdb.h>
4 5
#include <errno.h>
#include <stdlib.h>
W
w00349915 已提交
6
#include <unsupported_api.h>
R
Rich Felker 已提交
7 8 9

struct hostent *gethostbyaddr(const void *a, socklen_t l, int af)
{
10 11
	static struct hostent *h;
	size_t size = 63;
R
Rich Felker 已提交
12
	struct hostent *res;
13
	int err;
W
w00349915 已提交
14
	unsupported_api(__FUNCTION__);
15 16 17 18 19 20 21 22 23 24 25
	do {
		free(h);
		h = malloc(size+=size+1);
		if (!h) {
			h_errno = NO_RECOVERY;
			return 0;
		}
		err = gethostbyaddr_r(a, l, af, h,
			(void *)(h+1), size-sizeof *h, &res, &h_errno);
	} while (err == ERANGE);
	return err ? 0 : h;
R
Rich Felker 已提交
26
}