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#ifdef HAVE_NETINET_IN_H
27#include <netinet/in.h>
28#endif
29#ifdef HAVE_ARPA_INET_H
30#include <arpa/inet.h>
31#endif
32#ifdef HAVE_NET_IF_H
33#include <net/if.h>
34#endif
35#ifdef HAVE_SYS_IOCTL_H
36#include <sys/ioctl.h>
37#endif
38#ifdef HAVE_NETDB_H
39#include <netdb.h>
40#endif
41#ifdef HAVE_SYS_SOCKIO_H
42#include <sys/sockio.h>
43#endif
44#ifdef HAVE_IFADDRS_H
45#include <ifaddrs.h>
46#endif
47#ifdef HAVE_STROPTS_H
48#include <stropts.h>
49#endif
50#ifdef __VMS
51#include <inet.h>
52#endif
54#include "curlx/inet_ntop.h"
55#include "if2ip.h"
57/* ------------------------------------------------------------------ */
59#ifdef USE_IPV6
60/* Return the scope of the given address. */
61unsigned int Curl_ipv6_scope(const struct sockaddr *sa)
62{
63 if(sa->sa_family == AF_INET6) {
64 const struct sockaddr_in6 *sa6 =
65 (const struct sockaddr_in6 *)(const void *)sa;
66 const unsigned char *b = sa6->sin6_addr.s6_addr;
67 unsigned short w = (unsigned short)((b[0] << 8) | b[1]);
69 if((b[0] & 0xFE) == 0xFC) /* Handle ULAs */
70 return IPV6_SCOPE_UNIQUELOCAL;
71 switch(w & 0xFFC0) {
72 case 0xFE80:
73 return IPV6_SCOPE_LINKLOCAL;
74 case 0xFEC0:
75 return IPV6_SCOPE_SITELOCAL;
76 case 0x0000:
77 w = b[1] | b[2] | b[3] | b[4] | b[5] | b[6] | b[7] | b[8] | b[9] |
78 b[10] | b[11] | b[12] | b[13] | b[14];
79 if(w || b[15] != 0x01)
80 break;
81 return IPV6_SCOPE_NODELOCAL;
82 default:
83 break;
84 }
85 }
86 return IPV6_SCOPE_GLOBAL;
87}
88#endif
90#if !defined(CURL_DISABLE_BINDLOCAL) || !defined(CURL_DISABLE_FTP)
92#ifdef HAVE_GETIFADDRS
94if2ip_result_t Curl_if2ip(int af,
95#ifdef USE_IPV6
96 unsigned int remote_scope,
97 unsigned int local_scope_id,
98#endif
99 const char *interf,
100 char *buf, size_t buf_size)
101{
102 struct ifaddrs *iface, *head;
103 if2ip_result_t res = IF2IP_NOT_FOUND;
105#if defined(USE_IPV6) && !defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
106 (void)local_scope_id;
107#endif
109 if(getifaddrs(&head) >= 0) {
110 for(iface = head; iface; iface = iface->ifa_next) {
111 if(iface->ifa_addr) {
112 if(iface->ifa_addr->sa_family == af) {
113 if(!strcmp(iface->ifa_name, interf)) {
114 void *addr;
115 char scope[12] = "";
116 char ipstr[64];
117 CURLcode result;
118#ifdef USE_IPV6
119 if(af == AF_INET6) {
120#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
121 unsigned int scopeid = 0;
122#endif
123 unsigned int ifscope = Curl_ipv6_scope(iface->ifa_addr);
125 if(ifscope != remote_scope) {
126 /* We are interested only in interface addresses whose scope
127 matches the remote address we want to connect to: global
128 for global, link-local for link-local, etc... */
129 if(res == IF2IP_NOT_FOUND)
130 res = IF2IP_AF_NOT_SUPPORTED;
131 continue;
132 }
134 addr =
135 &((struct sockaddr_in6 *)(void *)iface->ifa_addr)->sin6_addr;
136#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
137 /* Include the scope of this interface as part of the address */
138 scopeid = ((struct sockaddr_in6 *)(void *)iface->ifa_addr)
139 ->sin6_scope_id;
141 /* If given, scope id should match. */
142 if(local_scope_id && scopeid != local_scope_id) {
143 if(res == IF2IP_NOT_FOUND)
144 res = IF2IP_AF_NOT_SUPPORTED;
146 continue;
147 }
149 if(scopeid)
150 curl_msnprintf(scope, sizeof(scope), "%%%u", scopeid);
151#endif
152 }
153 else
154#endif
155 addr =
156 &((struct sockaddr_in *)(void *)iface->ifa_addr)->sin_addr;
157 res = IF2IP_FOUND;
158 result = curlx_inet_ntop(af, addr, ipstr, sizeof(ipstr));
159 curl_msnprintf(buf, buf_size, "%s%s", result ? "" : ipstr, scope);
160 break;
161 }
162 }
163 else if((res == IF2IP_NOT_FOUND) &&
164 !strcmp(iface->ifa_name, interf)) {
165 res = IF2IP_AF_NOT_SUPPORTED;
166 }
167 }
168 }
170 freeifaddrs(head);
171 }
173 return res;
174}
176#elif defined(HAVE_IOCTL_SIOCGIFADDR)
178if2ip_result_t Curl_if2ip(int af,
179#ifdef USE_IPV6
180 unsigned int remote_scope,
181 unsigned int local_scope_id,
182#endif
183 const char *interf,
184 char *buf, size_t buf_size)
185{
186 struct ifreq req;
187 struct in_addr in;
188 struct sockaddr_in *s;
189 curl_socket_t dummy;
190 size_t len;
191 CURLcode result;
193#ifdef USE_IPV6
194 (void)remote_scope;
195 (void)local_scope_id;
196#endif
198 if(!interf || (af != AF_INET))
199 return IF2IP_NOT_FOUND;
201 len = strlen(interf);
202 if(len >= sizeof(req.ifr_name))
203 return IF2IP_NOT_FOUND;
205 dummy = CURL_SOCKET(AF_INET, SOCK_STREAM, 0);
206 if(dummy == CURL_SOCKET_BAD)
207 return IF2IP_NOT_FOUND;
209 memset(&req, 0, sizeof(req));
210 memcpy(req.ifr_name, interf, len + 1);
211 req.ifr_addr.sa_family = AF_INET;
213#if defined(CURL_HAVE_DIAG) && defined(_AIX)
214/* Suppress warning inside system headers */
215#pragma GCC diagnostic push
216#pragma GCC diagnostic ignored "-Wshift-sign-overflow"
217#endif
218 if(ioctl(dummy, SIOCGIFADDR, &req) < 0) {
219#if defined(CURL_HAVE_DIAG) && defined(_AIX)
220#pragma GCC diagnostic pop
221#endif
222 sclose(dummy);
223 /* With SIOCGIFADDR, we cannot tell the difference between an interface
224 that does not exist and an interface that has no address of the
225 correct family. Assume the interface does not exist */
226 return IF2IP_NOT_FOUND;
227 }
229 s = (struct sockaddr_in *)(void *)&req.ifr_addr;
230 memcpy(&in, &s->sin_addr, sizeof(in));
231 result = curlx_inet_ntop(s->sin_family, &in, buf, buf_size);
233 sclose(dummy);
234 if(result)
235 return IF2IP_NOT_FOUND;
236 return IF2IP_FOUND;
237}
239#else
241if2ip_result_t Curl_if2ip(int af,
242#ifdef USE_IPV6
243 unsigned int remote_scope,
244 unsigned int local_scope_id,
245#endif
246 const char *interf,
247 char *buf, size_t buf_size)
248{
249 (void)af;
250#ifdef USE_IPV6
251 (void)remote_scope;
252 (void)local_scope_id;
253#endif
254 (void)interf;
255 (void)buf;
256 (void)buf_size;
257 return IF2IP_NOT_FOUND;
258}
260#endif
262#endif /* CURL_DISABLE_BINDLOCAL && CURL_DISABLE_FTP */
Diagnostics4 git calls · 32 ms
CallStatusSizeTime032 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 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=26 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
fetch2002.4 KiB · hit26 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2505 git.response.cache=HIT git.response.duration_ms=26 git.fetch.wants=fee49ca3648be275423dc6347a8c907754e3b65b 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=2505 git.pkt.payload.max=2484 git.sideband.band1.bytes=2483 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
- a5e16facefbb6102
- Request
- d3a584a7…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format