6 * net - simple IPv4/IPv6 socket library
8 * This code makes it simple to support IPv4 and IPv6 without speed penalty
9 * in clients by using non-blocking simultaneous connect, and using
10 * a convenience function to create both IPv4 and IPv6 sockets for servers.
14 * Author: Rusty Russell <rusty@rustcorp.com.au>
17 * #include <ccan/net/net.h>
18 * #include <netinet/in.h>
22 * int main(int argc, char *argv[])
24 * struct addrinfo *addr;
25 * const char *dest, *port;
29 * struct sockaddr_in v4;
30 * struct sockaddr_in6 v6;
32 * socklen_t slen = sizeof(u);
37 * } else if (argc == 3) {
41 * errx(1, "Usage: test-net <target> [<port>]");
43 * addr = net_client_lookup(dest, port, AF_UNSPEC, SOCK_STREAM);
45 * err(1, "Failed to look up %s", dest);
47 * fd = net_connect(addr);
49 * err(1, "Failed to connect to %s", dest);
52 * if (getsockname(fd, &u.s, &slen) == 0)
53 * printf("Connected via %s\n",
54 * u.s.sa_family == AF_INET6 ? "IPv6"
55 * : u.s.sa_family == AF_INET ? "IPv4"
58 * err(1, "Failed to get socket type for connection");
62 int main(int argc, char *argv[])
64 /* Expect exactly one argument */
68 if (strcmp(argv[1], "depends") == 0) {
69 printf("ccan/noerr\n");