X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fnet%2F_info;h=9ce0e150dfe3b53f26bc2c293497b6cf4e10e20d;hb=cf86c1e30648c9b482b92444c39ea6ea0ff936a8;hp=0b38c440061fd77776091e8813c26e10f14c4937;hpb=04a42d50a02645aca83d7dc02d8e9838540e818d;p=ccan diff --git a/ccan/net/_info b/ccan/net/_info index 0b38c440..9ce0e150 100644 --- a/ccan/net/_info +++ b/ccan/net/_info @@ -2,9 +2,11 @@ #include "config.h" /** - * net - simple IPv4/IPv6 client library + * net - simple IPv4/IPv6 socket library * - * This code makes it simple to support IPv4 and IPv6 without speed penalty. + * This code makes it simple to support IPv4 and IPv6 without speed penalty + * in clients by using non-blocking simultaneous connect, and using + * a convenience function to create both IPv4 and IPv6 sockets for servers. * * License: MIT * @@ -14,6 +16,7 @@ * #include * #include * #include + * #include * #include * #include * @@ -22,8 +25,12 @@ * struct addrinfo *addr; * const char *dest, *port; * int fd; - * struct sockaddr saddr; - * socklen_t slen = sizeof(saddr); + * union { + * struct sockaddr s; + * struct sockaddr_in v4; + * struct sockaddr_in6 v6; + * } u; + * socklen_t slen = sizeof(u); * * if (argc == 2) { * dest = argv[1]; @@ -42,10 +49,10 @@ * if (fd < 0) * err(1, "Failed to connect to %s", dest); * - * if (getsockname(fd, &saddr, &slen) == 0) + * if (getsockname(fd, &u.s, &slen) == 0) * printf("Connected via %s\n", - * saddr.sa_family == AF_INET6 ? "IPv6" - * : saddr.sa_family == AF_INET ? "IPv4" + * u.s.sa_family == AF_INET6 ? "IPv6" + * : u.s.sa_family == AF_INET ? "IPv4" * : "UNKNOWN??"); * else * err(1, "Failed to get socket type for connection"); @@ -59,7 +66,6 @@ int main(int argc, char *argv[]) return 1; if (strcmp(argv[1], "depends") == 0) { - printf("ccan/noerr\n"); return 0; }