~ubuntu-branches/ubuntu/utopic/sflphone/utopic-proposed

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjlib/include/pj/addr_resolv.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: addr_resolv.h 3553 2011-05-05 06:14:19Z nanang $ */
 
2
/*
 
3
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
 
4
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
#ifndef __PJ_ADDR_RESOLV_H__
 
21
#define __PJ_ADDR_RESOLV_H__
 
22
 
 
23
/**
 
24
 * @file addr_resolv.h
 
25
 * @brief IP address resolution.
 
26
 */
 
27
 
 
28
#include <pj/sock.h>
 
29
 
 
30
PJ_BEGIN_DECL
 
31
 
 
32
/**
 
33
 * @defgroup pj_addr_resolve Network Address Resolution
 
34
 * @ingroup PJ_IO
 
35
 * @{
 
36
 *
 
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().
 
40
 *
 
41
 * Example:
 
42
 * <pre>
 
43
 *   ...
 
44
 *   pj_hostent he;
 
45
 *   pj_status_t rc;
 
46
 *   pj_str_t host = pj_str("host.example.com");
 
47
 *
 
48
 *   rc = pj_gethostbyname( &host, &he);
 
49
 *   if (rc != PJ_SUCCESS) {
 
50
 *      char errbuf[80];
 
51
 *      pj_strerror( rc, errbuf, sizeof(errbuf));
 
52
 *      PJ_LOG(2,("sample", "Unable to resolve host, error=%s", errbuf));
 
53
 *      return rc;
 
54
 *   }
 
55
 *
 
56
 *   // process address...
 
57
 *   addr.sin_addr.s_addr = *(pj_uint32_t*)he.h_addr;
 
58
 *   ...
 
59
 * </pre>
 
60
 *
 
61
 * It's pretty simple really...
 
62
 */
 
63
 
 
64
/** This structure describes an Internet host address. */
 
65
typedef struct pj_hostent
 
66
{
 
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. */
 
72
} pj_hostent;
 
73
 
 
74
/** Shortcut to h_addr_list[0] */
 
75
#define h_addr h_addr_list[0]
 
76
 
 
77
/**
 
78
 * This structure describes address information pj_getaddrinfo().
 
79
 */
 
80
typedef struct pj_addrinfo
 
81
{
 
82
    char         ai_canonname[PJ_MAX_HOSTNAME]; /**< Canonical name for host*/
 
83
    pj_sockaddr  ai_addr;                       /**< Binary address.        */
 
84
} pj_addrinfo;
 
85
 
 
86
 
 
87
/**
 
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
 
90
 * #pj_getaddrinfo().
 
91
 *
 
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
 
97
 *                  invocation.
 
98
 *
 
99
 * @return          PJ_SUCCESS, or the appropriate error codes.
 
100
 */
 
101
PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
 
102
 
 
103
 
 
104
/**
 
105
 * Resolve the primary IP address of local host.
 
106
 *
 
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.
 
113
 *
 
114
 * @return          PJ_SUCCESS on success, or the appropriate error code.
 
115
 */
 
116
PJ_DECL(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr);
 
117
 
 
118
 
 
119
/**
 
120
 * Get the IP address of the default interface. Default interface is the
 
121
 * interface of the default route.
 
122
 *
 
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.
 
129
 *
 
130
 * @return          PJ_SUCCESS on success, or the appropriate error code.
 
131
 */
 
132
PJ_DECL(pj_status_t) pj_getdefaultipinterface(int af,
 
133
                                              pj_sockaddr *addr);
 
134
 
 
135
 
 
136
/**
 
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
 
140
 * service.
 
141
 *
 
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
 
145
 *                  name.
 
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
 
149
 *                  specified name.
 
150
 * @param ai        Array of address info to be filled with the information
 
151
 *                  about the host.
 
152
 *
 
153
 * @return          PJ_SUCCESS on success, or the appropriate error code.
 
154
 */
 
155
PJ_DECL(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *name,
 
156
                                    unsigned *count, pj_addrinfo ai[]);
 
157
 
 
158
 
 
159
 
 
160
/** @} */
 
161
 
 
162
PJ_END_DECL
 
163
 
 
164
#endif  /* __PJ_ADDR_RESOLV_H__ */