ccanlint: fix SEGV when example has format string.
[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 <stdio.h>
18  *      #include <err.h>
19  *
20  *      int main(int argc, char *argv[])
21  *      {
22  *              struct addrinfo *addr;
23  *              const char *dest, *port;
24  *              int fd;
25  *              struct sockaddr saddr;
26  *              socklen_t slen = sizeof(saddr);
27  *      
28  *              if (argc == 2) {
29  *                      dest = argv[1];
30  *                      port = "http";
31  *              } else if (argc == 3) {
32  *                      dest = argv[1];
33  *                      port = argv[2];
34  *              } else
35  *                      errx(1, "Usage: test-net <target> [<port>]");
36  *      
37  *              addr = net_client_lookup(dest, port, AF_UNSPEC, SOCK_STREAM);
38  *              if (!addr)
39  *                      err(1, "Failed to look up %s", dest);
40  *      
41  *              fd = net_connect(addr);
42  *              if (fd < 0)
43  *                      err(1, "Failed to connect to %s", dest);
44  *      
45  *              if (getsockname(fd, &saddr, &slen) == 0)
46  *                      printf("Connected via %s\n",
47  *                             saddr.sa_family == AF_INET6 ? "IPv6"
48  *                             : saddr.sa_family == AF_INET ? "IPv4"
49  *                             : "UNKNOWN??");
50  *              else
51  *                      err(1, "Failed to get socket type for connection");
52  *              return 0;
53  *      }
54  */
55 int main(int argc, char *argv[])
56 {
57         /* Expect exactly one argument */
58         if (argc != 2)
59                 return 1;
60
61         if (strcmp(argv[1], "depends") == 0) {
62                 printf("ccan/noerr\n");
63                 return 0;
64         }
65
66         return 1;
67 }