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 <sys/types.h>
19 * #include <sys/socket.h>
20 * #include <netinet/in.h>
24 * int main(int argc, char *argv[])
26 * struct addrinfo *addr;
27 * const char *dest, *port;
31 * struct sockaddr_in v4;
32 * struct sockaddr_in6 v6;
34 * socklen_t slen = sizeof(u);
39 * } else if (argc == 3) {
43 * errx(1, "Usage: test-net <target> [<port>]");
45 * addr = net_client_lookup(dest, port, AF_UNSPEC, SOCK_STREAM);
47 * err(1, "Failed to look up %s", dest);
49 * fd = net_connect(addr);
51 * err(1, "Failed to connect to %s", dest);
53 * if (getsockname(fd, &u.s, &slen) == 0)
54 * printf("Connected via %s\n",
55 * u.s.sa_family == AF_INET6 ? "IPv6"
56 * : u.s.sa_family == AF_INET ? "IPv4"
59 * err(1, "Failed to get socket type for connection");
63 int main(int argc, char *argv[])
65 /* Expect exactly one argument */
69 if (strcmp(argv[1], "depends") == 0) {
70 printf("ccan/noerr\n");