net: use freeaddrinfo() in _info example.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 23 Jul 2014 23:50:21 +0000 (09:20 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 25 Jul 2014 23:26:41 +0000 (08:56 +0930)
In fact, almost everyone will want to do this, so include the required
headers in net.h.  This makes usage simpler.

Reported-by: Jeremy Visser <jeremy@visser.name>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/net/_info
ccan/net/net.c
ccan/net/net.h

index 5ac83f95cec1763d27490512c4cfa98d1bf594a9..cfa58f842830fd07ce4c89effa95e203e4248234 100644 (file)
@@ -15,8 +15,6 @@
  *
  * Example:
  *     #include <ccan/net/net.h>
- *     #include <sys/types.h>
- *     #include <sys/socket.h>
  *     #include <netinet/in.h>
  *     #include <stdio.h>
  *     #include <err.h>
@@ -49,6 +47,7 @@
  *             fd = net_connect(addr);
  *             if (fd < 0)
  *                     err(1, "Failed to connect to %s", dest);
+ *             freeaddrinfo(addr);
  *     
  *             if (getsockname(fd, &u.s, &slen) == 0)
  *                     printf("Connected via %s\n",
index 7867054d9adf6c39bb48d68d8221c09c19925b86..61efd5b8fd4b55643b157d3cf90e73818b2a20f4 100644 (file)
@@ -1,10 +1,7 @@
 /* Licensed under BSD-MIT - see LICENSE file for details */
 #include <ccan/net/net.h>
 #include <ccan/noerr/noerr.h>
-#include <sys/types.h>
-#include <sys/socket.h>
 #include <poll.h>
-#include <netdb.h>
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
index 5e02fc36e7d09a329484ac5bfebf582c8c400cf3..05d552dcff823214b67fc46218226639088ee875 100644 (file)
@@ -1,6 +1,9 @@
 /* Licensed under BSD-MIT - see LICENSE file for details */
 #ifndef CCAN_NET_H
 #define CCAN_NET_H
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
 #include <stdbool.h>
 
 struct pollfd;
@@ -16,10 +19,7 @@ struct pollfd;
  * of results, or NULL on error.  You should use freeaddrinfo() to free it.
  *
  * Example:
- *     #include <sys/types.h>
- *     #include <sys/socket.h>
  *     #include <stdio.h>
- *     #include <netdb.h>
  *     #include <poll.h>
  *     #include <err.h>
  *     ...
@@ -124,10 +124,7 @@ void net_connect_abort(struct pollfd *pfds);
  * of results, or NULL on error.  You should use freeaddrinfo() to free it.
  *
  * Example:
- *     #include <sys/types.h>
- *     #include <sys/socket.h>
  *     #include <stdio.h>
- *     #include <netdb.h>
  *     #include <err.h>
  *     ...
  *     struct addrinfo *addr;