1NE_ADDR_RESOLVE(3) neon API reference NE_ADDR_RESOLVE(3)
2
3
4
6 ne_addr_resolve, ne_addr_result, ne_addr_first, ne_addr_next,
7 ne_addr_error, ne_addr_destroy - functions to resolve hostnames to
8 addresses
9
11 #include <ne_socket.h>
12
13 ne_sock_addr *ne_addr_resolve(const char *hostname, int flags);
14
15 int ne_addr_result(const ne_sock_addr *addr);
16
17 const ne_inet_addr *ne_addr_first(ne_sock_addr *addr);
18
19 const ne_inet_addr *ne_addr_next(ne_sock_addr *addr);
20
21 char *ne_addr_error(const ne_sock_addr *addr, char *buffer,
22 size_t bufsiz);
23
24 void ne_addr_destroy(ne_sock_addr *addr);
25
27 The ne_addr_resolve function resolves the given hostname, returning an
28 ne_sock_addr object representing the address (or addresses) associated
29 with the hostname. The flags parameter is currently unused, and must be
30 passed as 0.
31
32 The hostname passed to ne_addr_resolve can be a DNS hostname (e.g.
33 "www.example.com") or an IPv4 dotted quad (e.g. "192.0.34.72"); or, on
34 systems which support IPv6, an IPv6 hex address, which may be enclosed
35 in brackets, e.g. "[::1]".
36
37 To determine whether the hostname was successfully resolved, the
38 ne_addr_result function is used, which returns non-zero if an error
39 occurred. If an error did occur, the ne_addr_error function can be
40 used, which will copy the error string into a given buffer (of size
41 bufsiz).
42
43 The functions ne_addr_first and ne_addr_next are used to retrieve the
44 Internet addresses associated with an address object which has been
45 successfully resolved. ne_addr_first returns the first address;
46 ne_addr_next returns the next address after the most recent call to
47 ne_addr_next or ne_addr_first, or NULL if there are no more addresses.
48 The ne_inet_addr pointer returned by these functions can be passed to
49 ne_sock_connect to connect a socket.
50
51 After the address object has been used, it should be destroyed using
52 ne_addr_destroy.
53
55 ne_addr_resolve returns a pointer to an address object, and never NULL.
56 ne_addr_error returns the buffer parameter .
57
59 The code below prints out the set of addresses associated with the
60 hostname www.google.com.
61
62 ne_sock_addr *addr;
63 char buf[256];
64
65 addr = ne_addr_resolve("www.google.com", 0);
66 if (ne_addr_result(addr)) {
67 printf("Could not resolve www.google.com: %s\n",
68 ne_addr_error(addr, buf, sizeof buf));
69 } else {
70 const ne_inet_addr *ia;
71 printf("www.google.com:");
72 for (ia = ne_addr_first(addr); ia != NULL; ia = ne_addr_next(addr)) {
73 printf(" %s", ne_iaddr_print(ia, buf, sizeof buf));
74 }
75 putchar('\n');
76 }
77 ne_addr_destroy(addr);
78
80 ne_iaddr_print
81
83 Joe Orton
84 Author.
85
87neon 0.32.5 21 January 2023 NE_ADDR_RESOLVE(3)