Back to index

glibc  2.9
getrpcport.c
Go to the documentation of this file.
00001 /* @(#)getrpcport.c  2.1 88/07/29 4.0 RPCSRC */
00002 #if !defined(lint) && defined(SCCSIDS)
00003 static  char sccsid[] = "@(#)getrpcport.c 1.3 87/08/11 SMI";
00004 #endif
00005 /*
00006  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00007  * unrestricted use provided that this legend is included on all tape
00008  * media and as a part of the software program in whole or part.  Users
00009  * may copy or modify Sun RPC without charge, but are not authorized
00010  * to license or distribute it to anyone else except as part of a product or
00011  * program developed by the user.
00012  *
00013  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00014  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00015  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00016  *
00017  * Sun RPC is provided with no support and without any obligation on the
00018  * part of Sun Microsystems, Inc. to assist in its use, correction,
00019  * modification or enhancement.
00020  *
00021  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00022  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00023  * OR ANY PART THEREOF.
00024  *
00025  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00026  * or profits or other special, indirect and consequential damages, even if
00027  * Sun has been advised of the possibility of such damages.
00028  *
00029  * Sun Microsystems, Inc.
00030  * 2550 Garcia Avenue
00031  * Mountain View, California  94043
00032  */
00033 
00034 /*
00035  * Copyright (c) 1985 by Sun Microsystems, Inc.
00036  */
00037 
00038 #include <alloca.h>
00039 #include <errno.h>
00040 #include <stdio.h>
00041 #include <netdb.h>
00042 #include <string.h>
00043 #include <rpc/rpc.h>
00044 #include <rpc/clnt.h>
00045 #include <rpc/pmap_clnt.h>
00046 #include <sys/socket.h>
00047 
00048 int
00049 getrpcport (const char *host, u_long prognum, u_long versnum, u_int proto)
00050 {
00051   struct sockaddr_in addr;
00052   struct hostent hostbuf, *hp;
00053   size_t buflen;
00054   char *buffer;
00055   int herr;
00056 
00057   buflen = 1024;
00058   buffer = __alloca (buflen);
00059   while (__gethostbyname_r (host, &hostbuf, buffer, buflen, &hp, &herr) != 0
00060         || hp == NULL)
00061     if (herr != NETDB_INTERNAL || errno != ERANGE)
00062       return 0;
00063     else
00064       {
00065        /* Enlarge the buffer.  */
00066        buflen *= 2;
00067        buffer = __alloca (buflen);
00068       }
00069 
00070   memcpy ((char *) &addr.sin_addr, hp->h_addr, hp->h_length);
00071   addr.sin_family = AF_INET;
00072   addr.sin_port = 0;
00073   return pmap_getport (&addr, prognum, versnum, proto);
00074 }