clnt_generic.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. /* @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC */
  10. /*
  11. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  12. * unrestricted use provided that this legend is included on all tape
  13. * media and as a part of the software program in whole or part. Users
  14. * may copy or modify Sun RPC without charge, but are not authorized
  15. * to license or distribute it to anyone else except as part of a product or
  16. * program developed by the user.
  17. *
  18. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  19. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  21. *
  22. * Sun RPC is provided with no support and without any obligation on the
  23. * part of Sun Microsystems, Inc. to assist in its use, correction,
  24. * modification or enhancement.
  25. *
  26. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  27. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  28. * OR ANY PART THEREOF.
  29. *
  30. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  31. * or profits or other special, indirect and consequential damages, even if
  32. * Sun has been advised of the possibility of such damages.
  33. *
  34. * Sun Microsystems, Inc.
  35. * 2550 Garcia Avenue
  36. * Mountain View, California 94043
  37. */
  38. #if !defined(lint) && defined(SCCSIDS)
  39. static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
  40. #endif
  41. /*
  42. * Copyright (C) 1987, Sun Microsystems, Inc.
  43. */
  44. #include <rpc/rpc.h>
  45. #include <string.h>
  46. /*
  47. * Generic client creation: takes (hostname, program-number, protocol) and
  48. * returns client handle. Default options are set, which the user can
  49. * change using the rpc equivalent of ioctl()'s.
  50. */
  51. CLIENT *clnt_create(const char *hostname, const unsigned long prog,
  52. const unsigned long vers, const char *proto)
  53. {
  54. int sock;
  55. struct sockaddr_in server;
  56. struct addrinfo hint, *res = NULL;
  57. struct timeval tv;
  58. CLIENT *client;
  59. int ret;
  60. memset(&hint, 0, sizeof(hint));
  61. ret = getaddrinfo(hostname, NULL, &hint, &res);
  62. if (ret != 0)
  63. {
  64. rt_kprintf("getaddrinfo err: %d '%s'\n", ret, hostname);
  65. return NULL;
  66. }
  67. memcpy(&server, res->ai_addr, sizeof(struct sockaddr_in));
  68. freeaddrinfo(res);
  69. sock = -1;
  70. if (strcmp(proto, "udp") == 0)
  71. {
  72. tv.tv_sec = 5;
  73. tv.tv_usec = 0;
  74. client = clntudp_create(&server, prog, vers, tv, &sock);
  75. if (client == NULL) return NULL;
  76. tv.tv_sec = 1;
  77. clnt_control(client, CLSET_TIMEOUT, (char *)&tv);
  78. }
  79. else
  80. {
  81. rt_kprintf("unknow protocol\n");
  82. return NULL;
  83. }
  84. return (client);
  85. }
  86. void clnt_perror(CLIENT *rpch, const char *s)
  87. {
  88. rt_kprintf("rpc client error:%s\n", s);
  89. }