strlist_sock.c 649 B

1234567891011121314151617181920212223242526272829
  1. #include "unp.h"
  2. #include <stropts.h>
  3. int
  4. main(int argc, char *argv[])
  5. {
  6. int fd, i, nmods;
  7. struct str_list list;
  8. if (argc != 2)
  9. err_quit("usage: a.out { tcp | udp }");
  10. fd = Socket(AF_INET, (strcmp(argv[1], "tcp") == 0)
  11. ? SOCK_STREAM : SOCK_DGRAM, 0);
  12. if (isastream(fd) == 0)
  13. err_quit("%s is not a stream", argv[1]);
  14. list.sl_nmods = nmods = Ioctl(fd, I_LIST, (void *) 0);
  15. printf("%d modules\n", nmods);
  16. list.sl_modlist = Calloc(nmods, sizeof(struct str_mlist));
  17. Ioctl(fd, I_LIST, &list);
  18. for (i = 1; i <= nmods; i++)
  19. printf(" %s: %s\n", (i == nmods) ? "driver" : "module",
  20. list.sl_modlist++);
  21. exit(0);
  22. }