~ubuntu-branches/ubuntu/intrepid/curl/intrepid-security

« back to all changes in this revision

Viewing changes to lib/hostip6.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-10-30 10:56:48 UTC
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20061030105648-kfd50jram0rzbtlo
Tags: upstream-7.15.5
ImportĀ upstreamĀ versionĀ 7.15.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: hostip6.c,v 1.27 2006-05-05 10:24:27 bagder Exp $
 
21
 * $Id: hostip6.c,v 1.37 2006-07-27 22:28:53 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
25
25
 
26
26
#include <string.h>
27
27
 
28
 
#ifdef HAVE_MALLOC_H
 
28
#ifdef NEED_MALLOC_H
29
29
#include <malloc.h>
30
30
#endif
31
31
#ifdef HAVE_SYS_TYPES_H
88
88
 * Only for ipv6-enabled builds
89
89
 **********************************************************************/
90
90
#ifdef CURLRES_IPV6
 
91
#ifndef CURLRES_ARES
91
92
/*
92
93
 * This is a wrapper function for freeing name information in a protocol
93
94
 * independent way. This takes care of using the appropriate underlaying
104
105
 * address. But this is an ipv6 build and then we don't copy the address, we
105
106
 * just return the same pointer!
106
107
 */
107
 
Curl_addrinfo *Curl_addrinfo_copy(void *source, int port)
 
108
Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port)
108
109
{
109
110
  (void) port;
110
 
  return source;
 
111
  return (Curl_addrinfo*)orig;
111
112
}
112
 
#endif
 
113
#endif  /* CURLRES_ASYNCH */
 
114
#endif  /* CURLRES_ARES */
113
115
 
114
116
#ifdef CURLDEBUG
115
117
/* These are strictly for memory tracing and are using the same style as the
116
118
 * family otherwise present in memdebug.c. I put these ones here since they
117
119
 * require a bunch of structs I didn't wanna include in memdebug.c
118
120
 */
119
 
int curl_dogetaddrinfo(char *hostname, char *service,
 
121
int curl_dogetaddrinfo(const char *hostname, const char *service,
120
122
                       struct addrinfo *hints,
121
123
                       struct addrinfo **result,
122
124
                       int line, const char *source)
136
138
  return res;
137
139
}
138
140
 
139
 
int curl_dogetnameinfo(const struct sockaddr *sa, socklen_t salen,
140
 
                       char *host, size_t hostlen,
141
 
                       char *serv, size_t servlen, int flags,
 
141
/*
 
142
 * For CURLRES_ARS, this should be written using ares_gethostbyaddr()
 
143
 * (ignoring the fact c-ares doesn't return 'serv').
 
144
 */
 
145
#ifdef HAVE_GETNAMEINFO
 
146
int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
 
147
                       GETNAMEINFO_TYPE_ARG2 salen,
 
148
                       char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
 
149
                       char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
 
150
                       GETNAMEINFO_TYPE_ARG7 flags,
142
151
                       int line, const char *source)
143
152
{
144
153
  int res = (getnameinfo)(sa, salen,
158
167
  }
159
168
  return res;
160
169
}
 
170
#endif
161
171
 
162
172
void curl_dofreeaddrinfo(struct addrinfo *freethis,
163
173
                         int line, const char *source)
167
177
    fprintf(logfile, "ADDR %s:%d freeaddrinfo(%p)\n",
168
178
            source, line, (void *)freethis);
169
179
}
170
 
 
171
 
#endif
 
180
#endif  /* CURLDEBUG */
172
181
 
173
182
/*
174
183
 * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
187
196
  return TRUE;
188
197
}
189
198
 
190
 
#ifndef USE_THREADING_GETADDRINFO
 
199
#if !defined(USE_THREADING_GETADDRINFO) && !defined(CURLRES_ARES)
191
200
 
192
201
#ifdef DEBUG_ADDRINFO
193
202
static void dump_addrinfo(struct connectdata *conn, const struct addrinfo *ai)
209
218
#endif
210
219
 
211
220
/*
212
 
 * Curl_getaddrinfo() when built ipv6-enabled (non-threading version).
 
221
 * Curl_getaddrinfo() when built ipv6-enabled (non-threading and
 
222
 * non-ares version).
213
223
 *
214
224
 * Returns name information about the given hostname and port number. If
215
225
 * successful, the 'addrinfo' is returned and the forth argument will point to
217
227
 * Curl_freeaddrinfo(), nothing else.
218
228
 */
219
229
Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
220
 
                                char *hostname,
 
230
                                const char *hostname,
221
231
                                int port,
222
232
                                int *waitp)
223
233
{
234
244
 
235
245
  /* see if we have an IPv6 stack */
236
246
  s = socket(PF_INET6, SOCK_DGRAM, 0);
237
 
  if (s < 0) {
 
247
  if (s == CURL_SOCKET_BAD) {
238
248
    /* Some non-IPv6 stacks have been found to make very slow name resolves
239
249
     * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
240
250
     * the stack seems to be a non-ipv6 one. */
291
301
 
292
302
  return res;
293
303
}
294
 
#endif /* USE_THREADING_GETADDRINFO */
 
304
#endif /* !USE_THREADING_GETADDRINFO && !CURLRES_ARES */
295
305
#endif /* ipv6 */
296
306