]> git.ozlabs.org Git - ccan/blob - ccan/net/_info
ccan/io: keep more io_plan details internal.
[ccan] / ccan / net / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * net - simple IPv4/IPv6 socket library
7  *
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.
11  *
12  * License: MIT
13  *
14  * Author: Rusty Russell <rusty@rustcorp.com.au>
15  *
16  * Example:
17  *      #include <ccan/net/net.h>
18  *      #include <netinet/in.h>
19  *      #include <stdio.h>
20  *      #include <err.h>
21  *
22  *      int main(int argc, char *argv[])
23  *      {
24  *              struct addrinfo *addr;
25  *              const char *dest, *port;
26  *              int fd;
27  *              union {
28  *                      struct sockaddr s;
29  *                      struct sockaddr_in v4;
30  *                      struct sockaddr_in6 v6;
31  *              } u;
32  *              socklen_t slen = sizeof(u);
33  *      
34  *              if (argc == 2) {
35  *                      dest = argv[1];
36  *                      port = "http";
37  *              } else if (argc == 3) {
38  *                      dest = argv[1];
39  *                      port = argv[2];
40  *              } else
41  *                      errx(1, "Usage: test-net <target> [<port>]");
42  *      
43  *              addr = net_client_lookup(dest, port, AF_UNSPEC, SOCK_STREAM);
44  *              if (!addr)
45  *                      err(1, "Failed to look up %s", dest);
46  *      
47  *              fd = net_connect(addr);
48  *              if (fd < 0)
49  *                      err(1, "Failed to connect to %s", dest);
50  *              freeaddrinfo(addr);
51  *      
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"
56  *                             : "UNKNOWN??");
57  *              else
58  *                      err(1, "Failed to get socket type for connection");
59  *              return 0;
60  *      }
61  */
62 int main(int argc, char *argv[])
63 {
64         /* Expect exactly one argument */
65         if (argc != 2)
66                 return 1;
67
68         if (strcmp(argv[1], "depends") == 0) {
69                 printf("ccan/noerr\n");
70                 return 0;
71         }
72
73         return 1;
74 }