blob: e69abcf8ec3887bf5d0d68c519f1b5e0eaa5e186 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00004 *
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
Benny Prijono594e4c52006-09-14 18:51:01 +000024 * @brief IP address resolution.
Benny Prijono5dcb38d2005-11-21 01:55:47 +000025 */
26
Benny Prijono594e4c52006-09-14 18:51:01 +000027#include <pj/sock.h>
Benny Prijono5dcb38d2005-11-21 01:55:47 +000028
29PJ_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. */
64typedef 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
Benny Prijonoc16c6e32007-11-18 14:53:47 +000076/**
77 * This structure describes address information pj_getaddrinfo().
78 */
79typedef 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
Benny Prijono5dcb38d2005-11-21 01:55:47 +000086/**
87 * This function fills the structure of type pj_hostent for a given host name.
88 *
89 * @param name Host name, or IPv4 or IPv6 address in standard dot notation.
90 * @param he The pj_hostent structure to be filled.
91 *
92 * @return PJ_SUCCESS, or the appropriate error codes.
93 */
94PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
95
96
Benny Prijono594e4c52006-09-14 18:51:01 +000097/**
98 * Resolve the primary IP address of local host.
99 *
100 * @param ip_addr On successful resolution, this will be filled up with
101 * the host IP address, in network byte order.
102 *
103 * @return PJ_SUCCESS on success, or the appropriate error code.
104 */
105PJ_DECL(pj_status_t) pj_gethostip(pj_in_addr *ip_addr);
106
107
Benny Prijonoc16c6e32007-11-18 14:53:47 +0000108/**
109 * This function translates the name of a service location (for example,
110 * a host name) and returns a set of addresses and associated information
111 * to be used in creating a socket with which to address the specified
112 * service.
113 *
114 * @param name Descriptive name or an address string, such as host
115 * name.
116 * @param af The desired address family to query.
117 * @param count On input, it specifies the number of elements in
118 * \a ai array. On output, this will be set with the
119 * number of address informations found for the
120 * specified name.
121 *
122 * @return PJ_SUCCESS on success, or the appropriate error code.
123 */
124PJ_DECL(pj_status_t) pj_getaddrinfo(const pj_str_t *nodename, int af,
125 unsigned *count, pj_addrinfo ai[]);
126
127
128
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000129/** @} */
130
131PJ_END_DECL
132
133#endif /* __PJ_ADDR_RESOLV_H__ */
134