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