getrpcent_r.c 459 B

123456789101112131415161718192021222324
  1. #include <netdb.h>
  2. #include <stdio.h>
  3. #include <errno.h>
  4. int main(int argc, char *argv[])
  5. {
  6. int ret;
  7. char rpcdata[1024];
  8. struct rpcent rpcbuf, *ent;
  9. while ((ret = getrpcent_r(&rpcbuf, rpcdata, sizeof(rpcdata), &ent)) == 0) {
  10. printf("%s: %i", ent->r_name, ent->r_number);
  11. while (ent->r_aliases[0])
  12. printf(" %s", *ent->r_aliases++);
  13. printf("\n");
  14. }
  15. if (ret != ENOENT)
  16. printf("Test failed: %s\n", strerror(ret));
  17. endrpcent();
  18. return 0;
  19. }