lib/libc/rpc/getrpcport.c

http://www.minix3.org/ · C · 85 lines · 41 code · 11 blank · 33 comment · 5 complexity · 4e965a90b15eb20a49339f8656cc52a2 MD5 · raw file

  1. /* $NetBSD: getrpcport.c,v 1.16 2000/01/22 22:19:18 mycroft Exp $ */
  2. /*
  3. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4. * unrestricted use provided that this legend is included on all tape
  5. * media and as a part of the software program in whole or part. Users
  6. * may copy or modify Sun RPC without charge, but are not authorized
  7. * to license or distribute it to anyone else except as part of a product or
  8. * program developed by the user.
  9. *
  10. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13. *
  14. * Sun RPC is provided with no support and without any obligation on the
  15. * part of Sun Microsystems, Inc. to assist in its use, correction,
  16. * modification or enhancement.
  17. *
  18. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20. * OR ANY PART THEREOF.
  21. *
  22. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23. * or profits or other special, indirect and consequential damages, even if
  24. * Sun has been advised of the possibility of such damages.
  25. *
  26. * Sun Microsystems, Inc.
  27. * 2550 Garcia Avenue
  28. * Mountain View, California 94043
  29. */
  30. #include <sys/cdefs.h>
  31. #if defined(LIBC_SCCS) && !defined(lint)
  32. #if 0
  33. static char *sccsid = "@(#)getrpcport.c 1.3 87/08/11 SMI";
  34. static char *sccsid = "@(#)getrpcport.c 2.1 88/07/29 4.0 RPCSRC";
  35. #else
  36. __RCSID("$NetBSD: getrpcport.c,v 1.16 2000/01/22 22:19:18 mycroft Exp $");
  37. #endif
  38. #endif
  39. /*
  40. * Copyright (c) 1985 by Sun Microsystems, Inc.
  41. */
  42. #include "namespace.h"
  43. #include <sys/types.h>
  44. #include <sys/socket.h>
  45. #include <assert.h>
  46. #include <netdb.h>
  47. #include <stdio.h>
  48. #include <string.h>
  49. #include <rpc/rpc.h>
  50. #include <rpc/pmap_clnt.h>
  51. #ifdef __weak_alias
  52. __weak_alias(getrpcport,_getrpcport)
  53. #endif
  54. int
  55. getrpcport(host, prognum, versnum, proto)
  56. char *host;
  57. int prognum, versnum, proto;
  58. {
  59. struct sockaddr_in addr;
  60. struct hostent *hp;
  61. _DIAGASSERT(host != NULL);
  62. if ((hp = gethostbyname(host)) == NULL)
  63. return (0);
  64. memset(&addr, 0, sizeof(addr));
  65. addr.sin_len = sizeof(struct sockaddr_in);
  66. addr.sin_family = AF_INET;
  67. addr.sin_port = 0;
  68. if (hp->h_length > addr.sin_len)
  69. hp->h_length = addr.sin_len;
  70. memcpy(&addr.sin_addr.s_addr, hp->h_addr, (size_t)hp->h_length);
  71. /* Inconsistent interfaces need casts! :-( */
  72. return (pmap_getport(&addr, (u_long)prognum, (u_long)versnum,
  73. (u_int)proto));
  74. }