xref: /freebsd/lib/libc/rpc/getrpcport.c (revision 990647991e51c0f93ad5d9985587a60f322f543a)
199064799SGarrett Wollman /*
299064799SGarrett Wollman  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
399064799SGarrett Wollman  * unrestricted use provided that this legend is included on all tape
499064799SGarrett Wollman  * media and as a part of the software program in whole or part.  Users
599064799SGarrett Wollman  * may copy or modify Sun RPC without charge, but are not authorized
699064799SGarrett Wollman  * to license or distribute it to anyone else except as part of a product or
799064799SGarrett Wollman  * program developed by the user.
899064799SGarrett Wollman  *
999064799SGarrett Wollman  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
1099064799SGarrett Wollman  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1199064799SGarrett Wollman  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
1299064799SGarrett Wollman  *
1399064799SGarrett Wollman  * Sun RPC is provided with no support and without any obligation on the
1499064799SGarrett Wollman  * part of Sun Microsystems, Inc. to assist in its use, correction,
1599064799SGarrett Wollman  * modification or enhancement.
1699064799SGarrett Wollman  *
1799064799SGarrett Wollman  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
1899064799SGarrett Wollman  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
1999064799SGarrett Wollman  * OR ANY PART THEREOF.
2099064799SGarrett Wollman  *
2199064799SGarrett Wollman  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
2299064799SGarrett Wollman  * or profits or other special, indirect and consequential damages, even if
2399064799SGarrett Wollman  * Sun has been advised of the possibility of such damages.
2499064799SGarrett Wollman  *
2599064799SGarrett Wollman  * Sun Microsystems, Inc.
2699064799SGarrett Wollman  * 2550 Garcia Avenue
2799064799SGarrett Wollman  * Mountain View, California  94043
2899064799SGarrett Wollman  */
2999064799SGarrett Wollman 
3099064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint)
3199064799SGarrett Wollman /*static char *sccsid = "from: @(#)getrpcport.c 1.3 87/08/11 SMI";*/
3299064799SGarrett Wollman /*static char *sccsid = "from: @(#)getrpcport.c	2.1 88/07/29 4.0 RPCSRC";*/
3399064799SGarrett Wollman static char *rcsid = "$Id: getrpcport.c,v 1.1 1993/10/27 05:40:31 paul Exp $";
3499064799SGarrett Wollman #endif
3599064799SGarrett Wollman 
3699064799SGarrett Wollman /*
3799064799SGarrett Wollman  * Copyright (c) 1985 by Sun Microsystems, Inc.
3899064799SGarrett Wollman  */
3999064799SGarrett Wollman 
4099064799SGarrett Wollman #include <stdio.h>
4199064799SGarrett Wollman #include <rpc/rpc.h>
4299064799SGarrett Wollman #include <netdb.h>
4399064799SGarrett Wollman #include <sys/socket.h>
4499064799SGarrett Wollman 
4599064799SGarrett Wollman getrpcport(host, prognum, versnum, proto)
4699064799SGarrett Wollman 	char *host;
4799064799SGarrett Wollman {
4899064799SGarrett Wollman 	struct sockaddr_in addr;
4999064799SGarrett Wollman 	struct hostent *hp;
5099064799SGarrett Wollman 
5199064799SGarrett Wollman 	if ((hp = gethostbyname(host)) == NULL)
5299064799SGarrett Wollman 		return (0);
5399064799SGarrett Wollman 	bcopy(hp->h_addr, (char *) &addr.sin_addr, hp->h_length);
5499064799SGarrett Wollman 	addr.sin_family = AF_INET;
5599064799SGarrett Wollman 	addr.sin_port =  0;
5699064799SGarrett Wollman 	return (pmap_getport(&addr, prognum, versnum, proto));
5799064799SGarrett Wollman }
58