5 * net - simple IPv4/IPv6 client library
7 * This code makes it simple to support IPv4 and IPv6 without speed penalty.
11 * Author: Rusty Russell <rusty@rustcorp.com.au>
14 * #include <ccan/net/net.h>
15 * #include <sys/types.h>
16 * #include <sys/socket.h>
17 * #include <netinet/in.h>
21 * int main(int argc, char *argv[])
23 * struct addrinfo *addr;
24 * const char *dest, *port;
28 * struct sockaddr_in v4;
29 * struct sockaddr_in6 v6;
31 * socklen_t slen = sizeof(u);
36 * } else if (argc == 3) {
40 * errx(1, "Usage: test-net <target> [<port>]");
42 * addr = net_client_lookup(dest, port, AF_UNSPEC, SOCK_STREAM);
44 * err(1, "Failed to look up %s", dest);
46 * fd = net_connect(addr);
48 * err(1, "Failed to connect to %s", dest);
50 * if (getsockname(fd, &u.s, &slen) == 0)
51 * printf("Connected via %s\n",
52 * u.s.sa_family == AF_INET6 ? "IPv6"
53 * : u.s.sa_family == AF_INET ? "IPv4"
56 * err(1, "Failed to get socket type for connection");
60 int main(int argc, char *argv[])
62 /* Expect exactly one argument */
66 if (strcmp(argv[1], "depends") == 0) {