test-rpcent.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Test getrpcent and friends.
  2. Copyright (C) 2015-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /* This is taken from nss/test-netdb.c and is intended to follow that
  16. test's model for everything. This test is separate only because
  17. the <rpc/netdb.h> interfaces do not exist in configurations that
  18. omit sunrpc/ from the build. */
  19. #include <stdio.h>
  20. #include <rpc/netdb.h>
  21. static void
  22. output_rpcent (const char *call, struct rpcent *rptr)
  23. {
  24. char **pptr;
  25. if (rptr == NULL)
  26. printf ("Call: %s returned NULL\n", call);
  27. else
  28. {
  29. printf ("Call: %s, returned: r_name: %s, r_number: %d\n",
  30. call, rptr->r_name, rptr->r_number);
  31. for (pptr = rptr->r_aliases; *pptr != NULL; pptr++)
  32. printf (" alias: %s\n", *pptr);
  33. }
  34. }
  35. static void
  36. test_rpc (void)
  37. {
  38. struct rpcent *rptr;
  39. rptr = getrpcbyname ("portmap");
  40. output_rpcent ("getrpcyname (\"portmap\")", rptr);
  41. rptr = getrpcbynumber (100000);
  42. output_rpcent ("getrpcbynumber (100000)", rptr);
  43. setrpcent (0);
  44. do
  45. {
  46. rptr = getrpcent ();
  47. output_rpcent ("getrpcent ()", rptr);
  48. }
  49. while (rptr != NULL);
  50. endrpcent ();
  51. }
  52. static int
  53. do_test (void)
  54. {
  55. test_rpc ();
  56. return 0;
  57. }
  58. #define TEST_FUNCTION do_test ()
  59. #include "../test-skeleton.c"