123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #if 0
- static char sccsid[] = "@(#)getrpcport.c 1.3 87/08/11 SMI";
- #endif
- #define __FORCE_GLIBC
- #include <features.h>
- #include <alloca.h>
- #include <errno.h>
- #include <stdio.h>
- #include <netdb.h>
- #include <string.h>
- #include <rpc/rpc.h>
- #include <rpc/clnt.h>
- #include <rpc/pmap_clnt.h>
- #include <sys/socket.h>
- libc_hidden_proto(memcpy)
- libc_hidden_proto(pmap_getport)
- libc_hidden_proto(gethostbyname_r)
- int
- getrpcport (const char *host, u_long prognum, u_long versnum, u_int proto)
- {
- struct sockaddr_in addr;
- struct hostent hostbuf, *hp;
- size_t buflen;
- char *buffer;
- int herr;
- buflen = 1024;
- buffer = alloca (buflen);
- while (gethostbyname_r (host, &hostbuf, buffer, buflen, &hp, &herr) != 0
- || hp == NULL)
- if (herr != NETDB_INTERNAL || errno != ERANGE)
- return 0;
- else
- {
-
- buflen *= 2;
- buffer = alloca (buflen);
- }
- memcpy ((char *) &addr.sin_addr, hp->h_addr, hp->h_length);
- addr.sin_family = AF_INET;
- addr.sin_port = 0;
- return pmap_getport (&addr, prognum, versnum, proto);
- }
|