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