1
/* $Id: addr_resolv.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJ_ADDR_RESOLV_H__
21
#define __PJ_ADDR_RESOLV_H__
25
* @brief IP address resolution.
33
* @defgroup pj_addr_resolve Network Address Resolution
37
* This module provides function to resolve Internet address of the
38
* specified host name. To resolve a particular host name, application
39
* can just call #pj_gethostbyname().
46
* pj_str_t host = pj_str("host.example.com");
48
* rc = pj_gethostbyname( &host, &he);
49
* if (rc != PJ_SUCCESS) {
51
* pj_strerror( rc, errbuf, sizeof(errbuf));
52
* PJ_LOG(2,("sample", "Unable to resolve host, error=%s", errbuf));
56
* // process address...
57
* addr.sin_addr.s_addr = *(pj_uint32_t*)he.h_addr;
61
* It's pretty simple really...
64
/** This structure describes an Internet host address. */
65
typedef struct pj_hostent
67
char *h_name; /**< The official name of the host. */
68
char **h_aliases; /**< Aliases list. */
69
int h_addrtype; /**< Host address type. */
70
int h_length; /**< Length of address. */
71
char **h_addr_list; /**< List of addresses. */
74
/** Shortcut to h_addr_list[0] */
75
#define h_addr h_addr_list[0]
78
* This structure describes address information pj_getaddrinfo().
80
typedef struct pj_addrinfo
82
char ai_canonname[PJ_MAX_HOSTNAME]; /**< Canonical name for host*/
83
pj_sockaddr ai_addr; /**< Binary address. */
88
* This function fills the structure of type pj_hostent for a given host name.
89
* For host resolution function that also works with IPv6, please see
92
* @param name Host name to resolve. Specifying IPv4 address here
93
* may fail on some platforms (e.g. Windows)
94
* @param he The pj_hostent structure to be filled. Note that
95
* the pointers in this structure points to temporary
96
* variables which value will be reset upon subsequent
99
* @return PJ_SUCCESS, or the appropriate error codes.
101
PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
105
* Resolve the primary IP address of local host.
107
* @param af The desired address family to query. Valid values
108
* are pj_AF_INET() or pj_AF_INET6().
109
* @param addr On successful resolution, the address family and address
110
* part of this socket address will be filled up with the host
111
* IP address, in network byte order. Other parts of the socket
112
* address are untouched.
114
* @return PJ_SUCCESS on success, or the appropriate error code.
116
PJ_DECL(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr);
120
* Get the IP address of the default interface. Default interface is the
121
* interface of the default route.
123
* @param af The desired address family to query. Valid values
124
* are pj_AF_INET() or pj_AF_INET6().
125
* @param addr On successful resolution, the address family and address
126
* part of this socket address will be filled up with the host
127
* IP address, in network byte order. Other parts of the socket
128
* address are untouched.
130
* @return PJ_SUCCESS on success, or the appropriate error code.
132
PJ_DECL(pj_status_t) pj_getdefaultipinterface(int af,
137
* This function translates the name of a service location (for example,
138
* a host name) and returns a set of addresses and associated information
139
* to be used in creating a socket with which to address the specified
142
* @param af The desired address family to query. Valid values
143
* are pj_AF_INET(), pj_AF_INET6(), or pj_AF_UNSPEC().
144
* @param name Descriptive name or an address string, such as host
146
* @param count On input, it specifies the number of elements in
147
* \a ai array. On output, this will be set with the
148
* number of address informations found for the
150
* @param ai Array of address info to be filled with the information
153
* @return PJ_SUCCESS on success, or the appropriate error code.
155
PJ_DECL(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *name,
156
unsigned *count, pj_addrinfo ai[]);
164
#endif /* __PJ_ADDR_RESOLV_H__ */