Debian Codegraph @

Xpjproject/pjlib/include/pj/addr_resolv.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __PJ_ADDR_RESOLV_H__
20 #define __PJ_ADDR_RESOLV_H__
21
22 /**
23 * @file addr_resolv.h
24 * @brief IP address resolution.
25 */
26
27 #include <pj/sock.h>
28
29 PJ_BEGIN_DECL
30
31 /**
32 * @defgroup pj_addr_resolve Network Address Resolution
33 * @ingroup PJ_IO
34 * @{
35 *
36 * This module provides function to resolve Internet address of the
37 * specified host name. To resolve a particular host name, application
38 * can just call #pj_gethostbyname().
39 *
40 * Example:
41 * <pre>
42 * ...
43 * pj_hostent he;
44 * pj_status_t rc;
45 * pj_str_t host = pj_str("host.example.com");
46 *
47 * rc = pj_gethostbyname( &host, &he);
48 * if (rc != PJ_SUCCESS) {
49 * char errbuf[80];
50 * pj_strerror( rc, errbuf, sizeof(errbuf));
51 * PJ_LOG(2,("sample", "Unable to resolve host, error=%s", errbuf));
52 * return rc;
53 * }
54 *
55 * // process address...
56 * addr.sin_addr.s_addr = *(pj_uint32_t*)he.h_addr;
57 * ...
58 * </pre>
59 *
60 * It's pretty simple really...
61 */
62
63 /** This structure describes an Internet host address. */
64 typedef struct pj_hostent
65 {
66 char *h_name; /**< The official name of the host. */
67 char **h_aliases; /**< Aliases list. */
68 int h_addrtype; /**< Host address type. */
69 int h_length; /**< Length of address. */
70 char **h_addr_list; /**< List of addresses. */
71 } pj_hostent;
72
73 /** Shortcut to h_addr_list[0] */
74 #define h_addr h_addr_list[0]
75
76 /**
77 * This structure describes address information pj_getaddrinfo().
78 */
79 typedef struct pj_addrinfo
80 {
81 char ai_canonname[PJ_MAX_HOSTNAME]; /**< Canonical name for host*/
82 pj_sockaddr ai_addr; /**< Binary address. */
83 } pj_addrinfo;
84
85
86 /**
87 * This function fills the structure of type pj_hostent for a given host name.
88 * For host resolution function that also works with IPv6, please see
89 * #pj_getaddrinfo().
90 *
91 * @param name Host name to resolve. Specifying IPv4 address here
92 * may fail on some platforms (e.g. Windows)
93 * @param he The pj_hostent structure to be filled. Note that
94 * the pointers in this structure points to temporary
95 * variables which value will be reset upon subsequent
96 * invocation.
97 *
98 * @return PJ_SUCCESS, or the appropriate error codes.
99 */
100 PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
101
102
103 /**
104 * Resolve the primary IP address of local host.
105 *
106 * @param af The desired address family to query. Valid values
107 * are pj_AF_INET() or pj_AF_INET6().
108 * @param addr On successful resolution, the address family and address
109 * part of this socket address will be filled up with the host
110 * IP address, in network byte order. Other parts of the socket
111 * address are untouched.
112 *
113 * @return PJ_SUCCESS on success, or the appropriate error code.
114 */
115 PJ_DECL(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr);
116
117
118 /**
119 * Get the interface IP address to send data to the specified destination.
120 *
121 * @param af The desired address family to query. Valid values
122 * are pj_AF_INET() or pj_AF_INET6().
123 * @param dst The destination host.
124 * @param itf_addr On successful resolution, the address family and address
125 * part of this socket address will be filled up with the host
126 * IP address, in network byte order. Other parts of the socket
127 * address should be ignored.
128 * @param allow_resolve If \a dst may contain hostname (instead of IP
129 * address), specify whether hostname resolution should
130 * be performed. If not, default interface address will
131 * be returned.
132 * @param p_dst_addr If not NULL, it will be filled with the IP address of
133 * the destination host.
134 *
135 * @return PJ_SUCCESS on success, or the appropriate error code.
136 */
137 PJ_DECL(pj_status_t) pj_getipinterface(int af,
138 const pj_str_t *dst,
139 pj_sockaddr *itf_addr,
140 pj_bool_t allow_resolve,
141 pj_sockaddr *p_dst_addr);
142
143 /**
144 * Get the IP address of the default interface. Default interface is the
145 * interface of the default route.
146 *
147 * @param af The desired address family to query. Valid values
148 * are pj_AF_INET() or pj_AF_INET6().
149 * @param addr On successful resolution, the address family and address
150 * part of this socket address will be filled up with the host
151 * IP address, in network byte order. Other parts of the socket
152 * address are untouched.
153 *
154 * @return PJ_SUCCESS on success, or the appropriate error code.
155 */
156 PJ_DECL(pj_status_t) pj_getdefaultipinterface(int af,
157 pj_sockaddr *addr);
158
159
160 /**
161 * This function translates the name of a service location (for example,
162 * a host name) and returns a set of addresses and associated information
163 * to be used in creating a socket with which to address the specified
164 * service.
165 *
166 * @param af The desired address family to query. Valid values
167 * are pj_AF_INET(), pj_AF_INET6(), or pj_AF_UNSPEC().
168 * @param name Descriptive name or an address string, such as host
169 * name.
170 * @param count On input, it specifies the number of elements in
171 * \a ai array. On output, this will be set with the
172 * number of address informations found for the
173 * specified name.
174 * @param ai Array of address info to be filled with the information
175 * about the host.
176 *
177 * @return PJ_SUCCESS on success, or the appropriate error code.
178 */
179 PJ_DECL(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *name,
180 unsigned *count, pj_addrinfo ai[]);
181
182
183 /**
184 * Enumeration of IP address type.
185 */
186 typedef enum pj_addr_type
187 {
188 /**
189 * Disabled: 0.0.0.0/8 or ::/128
190 */
191 PJ_ADDR_TYPE_DISABLED = 1,
192
193 /**
194 * Loopback: 127.0.0.0/8 or ::1/128
195 */
196 PJ_ADDR_TYPE_LOOPBACK = 2,
197
198 /**
199 * Link-local: 169.254.0.0/16 or fe80::/64
200 */
201 PJ_ADDR_TYPE_LINK_LOCAL = 4,
202
203 /**
204 * Private: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 or fc00::/7
205 */
206 PJ_ADDR_TYPE_PRIVATE = 8,
207
208 /**
209 * Multicast: 224.0.0.0/3 or ff00::/8
210 */
211 PJ_ADDR_TYPE_MULTICAST = 16,
212
213 } pj_addr_type;
214
215
216
217 /**
218 * Check IP address type.
219 *
220 * @param addr The IP address to check, must be IPv4 or IPv6 address.
221 * @param type Bit mask of address type pj_addr_type.
222 *
223 * @return PJ_TRUE if the type of specified address \addr match to
224 * the specified types \a type.
225 */
226 PJ_DECL(pj_bool_t) pj_check_addr_type(const pj_sockaddr *addr, unsigned type);
227
228
229 /** @} */
230
231 PJ_END_DECL
232
233 #endif /* __PJ_ADDR_RESOLV_H__ */
234