]> git.ozlabs.org Git - ccan/blob - ccan/net/net.h
tdb2: begin tdb1 to tdb2 porting guide.
[ccan] / ccan / net / net.h
1 #ifndef CCAN_NET_H
2 #define CCAN_NET_H
3 /**
4  * net_client_lookup - look up a network name to connect to.
5  * @hostname: the name to look up
6  * @service: the service to look up
7  * @family: Usually AF_UNSPEC, otherwise AF_INET or AF_INET6.
8  * @socktype: SOCK_DGRAM or SOCK_STREAM.
9  *
10  * This will do a synchronous lookup of a given name, returning a linked list
11  * of results, or NULL on error.  You should use freeaddrinfo() to free it.
12  *
13  * Example:
14  *      #include <sys/types.h>
15  *      #include <sys/socket.h>
16  *      #include <stdio.h>
17  *      #include <netdb.h>
18  *      #include <err.h>
19  *      ...
20  *      struct addrinfo *addr;
21  *
22  *      // Get a TCP connection to ccan.ozlabs.org daytime port.
23  *      addr = net_client_lookup("ccan.ozlabs.org", "daytime",
24  *                               AF_UNSPEC, SOCK_STREAM);
25  *      if (!addr)
26  *              errx(1, "Failed to look up daytime at ccan.ozlabs.org");
27  */
28 struct addrinfo *net_client_lookup(const char *hostname,
29                                    const char *service,
30                                    int family,
31                                    int socktype);
32
33 /**
34  * net_connect - connect to a server
35  * @addrinfo: linked list struct addrinfo (usually from net_client_lookup).
36  *
37  * This synchronously connects to a server described by @addrinfo, or returns
38  * -1 on error (and sets errno).
39  *
40  * Example:
41  *      int fd;
42  *      ...
43  *      fd = net_connect(addr);
44  *      if (fd < 0)
45  *              err(1, "Failed to connect to ccan.ozlabs.org");
46  *      freeaddrinfo(addr);
47  */
48 int net_connect(const struct addrinfo *addrinfo);
49 #endif /* CCAN_NET_H */