master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
26/***********************************************************************
27 * Only for plain IPv4 builds
28 **********************************************************************/
29#ifdef CURLRES_IPV4 /* plain IPv4 code coming up */
31#ifdef HAVE_NETINET_IN_H
32#include <netinet/in.h>
33#endif
34#ifdef HAVE_NETDB_H
35#include <netdb.h>
36#endif
37#ifdef HAVE_ARPA_INET_H
38#include <arpa/inet.h>
39#endif
40#ifdef __VMS
41#include <in.h>
42#include <inet.h>
43#endif
45#include "urldata.h"
46#include "curl_addrinfo.h"
47#include "curl_trc.h"
48#include "vdns/hostip.h"
49#include "url.h"
52#ifdef CURLRES_SYNCH
54/*
55 * Curl_sync_getaddrinfo() - the IPv4 synchronous version.
56 *
57 * The original code to this function was from the Dancer source code, written
58 * by Bjorn Reese, it has since been patched and modified considerably.
59 *
60 * gethostbyname_r() is the thread-safe version of the gethostbyname()
61 * function. When we build for plain IPv4, we attempt to use this
62 * function. There are _three_ different gethostbyname_r() versions, and we
63 * detect which one this platform supports in the configure script and set up
64 * the HAVE_GETHOSTBYNAME_R_3, HAVE_GETHOSTBYNAME_R_5 or
65 * HAVE_GETHOSTBYNAME_R_6 defines accordingly. Note that HAVE_GETADDRBYNAME
66 * has the corresponding rules. This is primarily on *nix. Note that some Unix
67 * flavors have thread-safe versions of the plain gethostbyname() etc.
68 *
69 */
70struct Curl_addrinfo *Curl_sync_getaddrinfo(struct Curl_easy *data,
71 uint8_t dns_queries,
72 const char *hostname,
73 uint16_t port,
74 uint8_t transport)
75{
76 struct Curl_addrinfo *ai = NULL;
78 (void)dns_queries;
79 (void)transport;
81 ai = Curl_ipv4_resolve_r(hostname, port);
82 if(!ai)
83 infof(data, "Curl_ipv4_resolve_r failed for %s", hostname);
85 return ai;
86}
87#endif /* CURLRES_SYNCH */
88#endif /* CURLRES_IPV4 */
90#if defined(CURLRES_IPV4) && !defined(USE_RESOLV_ARES) && \
91 !defined(CURLRES_AMIGA)
93/*
94 * Curl_ipv4_resolve_r() - IPv4 thread-safe resolver function.
95 *
96 * This is used for both synchronous and asynchronous resolver builds,
97 * implying that only thread-safe code and function calls may be used.
98 *
99 */
100struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
101 uint16_t port)
102{
103#if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE)) && \
104 defined(HAVE_GETHOSTBYNAME_R_3)
105 int res;
106#endif
107 struct Curl_addrinfo *ai = NULL;
108#if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE))
109 struct hostent *h = NULL;
110 struct hostent *buf = NULL;
111#endif
113#if defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE)
114 struct addrinfo hints;
115 char sbuf[12];
116 char *sbufptr = NULL;
118 memset(&hints, 0, sizeof(hints));
119 hints.ai_family = PF_INET;
120 hints.ai_socktype = SOCK_STREAM;
121 if(port) {
122 curl_msnprintf(sbuf, sizeof(sbuf), "%d", port);
123 sbufptr = sbuf;
124 }
126 (void)Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &ai);
128#elif defined(HAVE_GETHOSTBYNAME_R)
129 /*
130 * gethostbyname_r() is the preferred resolve function for many platforms.
131 * Since there are three different versions of it, the following code is
132 * somewhat #ifdef-ridden.
133 */
134 int h_errnop;
136 buf = curlx_calloc(1, CURL_HOSTENT_SIZE);
137 if(!buf)
138 return NULL; /* major failure */
139 /*
140 * The clearing of the buffer is a workaround for a gethostbyname_r bug in
141 * QNX Neutrino and it is also _required_ for some of these functions on some
142 * platforms.
143 */
145#ifdef HAVE_GETHOSTBYNAME_R_5
146 /* Solaris, IRIX and more */
147 h = gethostbyname_r(hostname,
148 (struct hostent *)buf,
149 (char *)buf + sizeof(struct hostent),
150 CURL_HOSTENT_SIZE - sizeof(struct hostent),
151 &h_errnop);
153 /* If the buffer is too small, it returns NULL and sets errno to
154 * ERANGE. The errno is thread-safe if this is compiled with
155 * -D_REENTRANT as then the 'errno' variable is a macro defined to get
156 * used properly for threads.
157 */
159 if(h) {
160 ;
161 }
162 else
163#elif defined(HAVE_GETHOSTBYNAME_R_6)
164 /* Linux */
166 (void)gethostbyname_r(hostname,
167 (struct hostent *)buf,
168 (char *)buf + sizeof(struct hostent),
169 CURL_HOSTENT_SIZE - sizeof(struct hostent),
170 &h, /* DIFFERENCE */
171 &h_errnop);
172 /* Redhat 8, using glibc 2.2.93 changed the behavior. Now all of a
173 * sudden this function returns EAGAIN if the given buffer size is too
174 * small. Previous versions are known to return ERANGE for the same
175 * problem.
176 *
177 * This would not be such a big problem if older versions would not
178 * sometimes return EAGAIN on a common failure case. Alas, we cannot
179 * assume that EAGAIN *or* ERANGE means ERANGE for any given version of
180 * glibc.
181 *
182 * For now, we do that and thus we may call the function repeatedly and
183 * fail for older glibc versions that return EAGAIN, until we run out of
184 * buffer size (step_size grows beyond CURL_HOSTENT_SIZE).
185 *
186 * If anyone has a better fix, please tell us!
187 *
188 * -------------------------------------------------------------------
189 *
190 * On October 23rd 2003, Dan C dug up more details on the mysteries of
191 * gethostbyname_r() in glibc:
192 *
193 * In glibc 2.2.5 the interface is different (this has also been
194 * discovered in glibc 2.1.1-6 as shipped by Redhat 6). What I cannot
195 * explain, is that tests performed on glibc 2.2.4-34 and 2.2.4-32
196 * (shipped/upgraded by Redhat 7.2) do not show this behavior!
197 *
198 * In this "buggy" version, the return code is -1 on error and 'errno'
199 * is set to the ERANGE or EAGAIN code. Note that 'errno' is not a
200 * thread-safe variable.
201 */
203 if(!h) /* failure */
204#elif defined(HAVE_GETHOSTBYNAME_R_3)
205 /* AIX, Digital UNIX/Tru64, HP-UX 10, more? */
207 /* For AIX 4.3 or later, we do not use gethostbyname_r() at all, because of
208 * the plain fact that it does not return unique full buffers on each
209 * call, but instead several of the pointers in the hostent structs will
210 * point to the same actual data! This have the unfortunate down-side that
211 * our caching system breaks down horribly. Luckily for us though, AIX 4.3
212 * and more recent versions have a "completely thread-safe"[*] libc where
213 * all the data is stored in thread-specific memory areas making calls to
214 * the plain old gethostbyname() work fine even for multi-threaded
215 * programs.
216 *
217 * This AIX 4.3 or later detection is all made in the configure script.
218 *
219 * Troels Walsted Hansen helped us work this out on March 3rd, 2003.
220 *
221 * [*] = much later we have found out that it is not at all "completely
222 * thread-safe", but at least the gethostbyname() function is.
223 */
225 if(CURL_HOSTENT_SIZE >=
226 (sizeof(struct hostent) + sizeof(struct hostent_data))) {
228 /* August 22nd, 2000: Albert Chin-A-Young brought an updated version
229 * that should work! September 20: Richard Prescott worked on the buffer
230 * size dilemma.
231 */
233 res = gethostbyname_r(hostname,
234 (struct hostent *)buf,
235 (struct hostent_data *)((char *)buf +
236 sizeof(struct hostent)));
237 h_errnop = SOCKERRNO; /* we do not deal with this, but set it anyway */
238 }
239 else
240 res = -1; /* failure, too smallish buffer size */
242 if(!res) { /* success */
244 h = buf; /* result expected in h */
246 /* This is the worst kind of the different gethostbyname_r() interfaces.
247 * Since we do not know how big buffer this particular lookup required,
248 * we cannot realloc down the huge alloc without doing closer analysis of
249 * the returned data. Thus, we always use CURL_HOSTENT_SIZE for every
250 * name lookup. Fixing this would require an extra allocation and then
251 * calling Curl_addrinfo_copy() that subsequent reallocation down the new
252 * memory area to the actually used amount.
253 */
254 }
255 else
256#endif /* HAVE_...BYNAME_R_5 || HAVE_...BYNAME_R_6 || HAVE_...BYNAME_R_3 */
257 {
258 h = NULL; /* set return code to NULL */
259 curlx_free(buf);
260 }
261#else /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) ||
262 HAVE_GETHOSTBYNAME_R */
263 /*
264 * Here is code for platforms that do not have a thread-safe
265 * getaddrinfo() nor gethostbyname_r() function or for which
266 * gethostbyname() is the preferred one.
267 */
268 h = gethostbyname(CURL_UNCONST(hostname));
269#endif /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) ||
270 HAVE_GETHOSTBYNAME_R */
272#if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE))
273 if(h) {
274 ai = Curl_he2ai(h, port);
276 if(buf) /* used a *_r() function */
277 curlx_free(buf);
278 }
279#endif
281 return ai;
282}
283#endif /* CURLRES_IPV4 && !USE_RESOLV_ARES && !CURLRES_AMIGA */
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2003.6 KiB · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=23 git.response.bytes=3726 git.response.cache=HIT git.response.duration_ms=23 git.fetch.wants=83896a82b27fa2626cc4a79c79400b69dbfae05d git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3726 git.pkt.payload.max=3705 git.sideband.band1.bytes=3704 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e9ef580adc0acb
- Request
- 070e5729…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format