test-socket-creation.c 613 B

12345678910111213141516171819202122232425262728
  1. #include <netlink/netlink.h>
  2. #include <errno.h>
  3. int main(int argc, char *argv[])
  4. {
  5. struct nl_sock *h[1025];
  6. int i;
  7. h[0] = nl_socket_alloc();
  8. printf("Created handle with port 0x%x\n",
  9. nl_socket_get_local_port(h[0]));
  10. nl_socket_free(h[0]);
  11. h[0] = nl_socket_alloc();
  12. printf("Created handle with port 0x%x\n",
  13. nl_socket_get_local_port(h[0]));
  14. nl_socket_free(h[0]);
  15. for (i = 0; i < 1025; i++) {
  16. h[i] = nl_socket_alloc();
  17. if (h[i] == NULL)
  18. nl_perror(ENOMEM, "Unable to allocate socket");
  19. else
  20. printf("Created handle with port 0x%x\n",
  21. nl_socket_get_local_port(h[i]));
  22. }
  23. return 0;
  24. }