_info 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <string.h>
  2. #include "config.h"
  3. /**
  4. * net - simple IPv4/IPv6 client library
  5. *
  6. * This code makes it simple to support IPv4 and IPv6 without speed penalty.
  7. *
  8. * License: MIT
  9. *
  10. * Author: Rusty Russell <rusty@rustcorp.com.au>
  11. *
  12. * Example:
  13. * #include <ccan/net/net.h>
  14. * #include <sys/types.h>
  15. * #include <sys/socket.h>
  16. * #include <netinet/in.h>
  17. * #include <stdio.h>
  18. * #include <err.h>
  19. *
  20. * int main(int argc, char *argv[])
  21. * {
  22. * struct addrinfo *addr;
  23. * const char *dest, *port;
  24. * int fd;
  25. * union {
  26. * struct sockaddr s;
  27. * struct sockaddr_in v4;
  28. * struct sockaddr_in6 v6;
  29. * } u;
  30. * socklen_t slen = sizeof(u);
  31. *
  32. * if (argc == 2) {
  33. * dest = argv[1];
  34. * port = "http";
  35. * } else if (argc == 3) {
  36. * dest = argv[1];
  37. * port = argv[2];
  38. * } else
  39. * errx(1, "Usage: test-net <target> [<port>]");
  40. *
  41. * addr = net_client_lookup(dest, port, AF_UNSPEC, SOCK_STREAM);
  42. * if (!addr)
  43. * err(1, "Failed to look up %s", dest);
  44. *
  45. * fd = net_connect(addr);
  46. * if (fd < 0)
  47. * err(1, "Failed to connect to %s", dest);
  48. *
  49. * if (getsockname(fd, &u.s, &slen) == 0)
  50. * printf("Connected via %s\n",
  51. * u.s.sa_family == AF_INET6 ? "IPv6"
  52. * : u.s.sa_family == AF_INET ? "IPv4"
  53. * : "UNKNOWN??");
  54. * else
  55. * err(1, "Failed to get socket type for connection");
  56. * return 0;
  57. * }
  58. */
  59. int main(int argc, char *argv[])
  60. {
  61. /* Expect exactly one argument */
  62. if (argc != 2)
  63. return 1;
  64. if (strcmp(argv[1], "depends") == 0) {
  65. return 0;
  66. }
  67. return 1;
  68. }