Annotation of embedaddon/iftop/config/int_ghba_r.c, revision 1.1.1.2
1.1 misho 1: /*
2: * int_ghba_r.c:
3: * Test program to see whether gethostbyaddr_r takes 8 arguments and returns
4: * int.
5: */
6:
1.1.1.2 ! misho 7: static const char rcsid[] = "$Id: int_ghba_r.c,v 1.4 2011/10/03 18:19:13 pdw Exp $";
1.1 misho 8:
1.1.1.2 ! misho 9: #include <sys/socket.h>
1.1 misho 10: #include <sys/types.h>
11:
12: #include <errno.h>
13: #include <netdb.h>
14: #include <stdio.h>
15: #include <stdlib.h>
16: #include <netinet/in.h>
17:
18: int main(void) {
19: struct in_addr localhost;
20: struct hostent hostbuf, *hp;
21: char *buf;
22: int res, herr;
23: size_t buflen = 1024;
24:
25: localhost.s_addr = htonl(INADDR_LOOPBACK);
26: buf = malloc(buflen);
27: while ((res = gethostbyaddr_r((char*)&localhost, sizeof localhost, AF_INET,
28: &hostbuf, buf, buflen, &hp, &herr))
29: == ERANGE)
30: buf = (char*)realloc(buf, buflen *= 2);
31:
32: /* We assume that the loopback address can always be resolved if
33: * gethostbyaddr_r is actually working. */
34: if (res || hp == NULL) {
35: fprintf(stderr, "errno = %d, herr = %d, res = %d\n", errno, herr, res);
36: return -1;
37: } else
38: return 0;
39: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>