master
1/* This is from the BIND 4.9.4 release, modified to compile by itself */
3/* Copyright (c) Internet Software Consortium.
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
10 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
11 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
12 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16 * SOFTWARE.
17 *
18 * SPDX-License-Identifier: ISC
19 */
20#include "curl_setup.h"
22#ifdef HAVE_SYS_PARAM_H
23#include <sys/param.h>
24#endif
25#ifdef HAVE_NETINET_IN_H
26#include <netinet/in.h>
27#endif
28#ifdef HAVE_ARPA_INET_H
29#include <arpa/inet.h>
30#endif
32#include "curlx/inet_pton.h"
33#include "curlx/strparse.h"
35#define IN6ADDRSZ 16
36#define INADDRSZ 4
37#define INT16SZ 2
39/*
40 * If USE_IPV6 is disabled, we still want to parse IPv6 addresses, so make
41 * sure we have _some_ value for AF_INET6 without polluting our fake value
42 * everywhere.
43 */
44#if !defined(USE_IPV6) && !defined(AF_INET6)
45#define AF_INET6 (AF_INET + 1)
46#endif
48/*
49 * WARNING: Do not even consider trying to compile this on a system where
50 * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
51 */
53/* int inet_pton4(src, dst)
54 * like inet_aton() but without all the hexadecimal and shorthand.
55 * return:
56 * 1 if `src' is a valid dotted quad, else 0.
57 * notice:
58 * does not touch `dst' unless it is returning 1.
59 * author:
60 * Paul Vixie, 1996.
61 */
62static int inet_pton4(const char *src, unsigned char *dst)
63{
64 int saw_digit, octets, ch;
65 unsigned char tmp[INADDRSZ], *tp;
67 saw_digit = 0;
68 octets = 0;
69 tp = tmp;
70 *tp = 0;
71 while((ch = (unsigned char)*src++) != '\0') {
72 if(ISDIGIT(ch)) {
73 unsigned int val = (*tp * 10) + (ch - '0');
75 if(saw_digit && *tp == 0)
76 return 0;
77 if(val > 255)
78 return 0;
79 *tp = (unsigned char)val;
80 if(!saw_digit) {
81 if(++octets > 4)
82 return 0;
83 saw_digit = 1;
84 }
85 }
86 else if(ch == '.' && saw_digit) {
87 if(octets == 4)
88 return 0;
89 *++tp = 0;
90 saw_digit = 0;
91 }
92 else
93 return 0;
94 }
95 if(octets < 4)
96 return 0;
97 memcpy(dst, tmp, INADDRSZ);
98 return 1;
99}
101/* int inet_pton6(src, dst)
102 * convert presentation level address to network order binary form.
103 * return:
104 * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
105 * notice:
106 * (1) does not touch `dst' unless it is returning 1.
107 * (2) :: in a full address is silently ignored.
108 * credit:
109 * inspired by Mark Andrews.
110 * author:
111 * Paul Vixie, 1996.
112 */
113static int inet_pton6(const char *src, unsigned char *dst)
114{
115 unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
116 const char *curtok;
117 int ch, saw_xdigit;
118 size_t val;
120 memset((tp = tmp), 0, IN6ADDRSZ);
121 endp = tp + IN6ADDRSZ;
122 colonp = NULL;
123 /* Leading :: requires some special handling. */
124 if(*src == ':' && *++src != ':')
125 return 0;
126 curtok = src;
127 saw_xdigit = 0;
128 val = 0;
129 while((ch = (unsigned char)*src++) != '\0') {
130 if(ISXDIGIT(ch)) {
131 val <<= 4;
132 val |= curlx_hexval(ch);
133 if(++saw_xdigit > 4)
134 return 0;
135 continue;
136 }
137 if(ch == ':') {
138 curtok = src;
139 if(!saw_xdigit) {
140 if(colonp)
141 return 0;
142 colonp = tp;
143 continue;
144 }
145 if(!*src)
146 return 0;
147 if(tp + INT16SZ > endp)
148 return 0;
149 *tp++ = (unsigned char)((val >> 8) & 0xff);
150 *tp++ = (unsigned char)(val & 0xff);
151 saw_xdigit = 0;
152 val = 0;
153 continue;
154 }
155 if(ch == '.' && ((tp + INADDRSZ) <= endp) &&
156 inet_pton4(curtok, tp) > 0) {
157 tp += INADDRSZ;
158 saw_xdigit = 0;
159 break; /* '\0' was seen by inet_pton4(). */
160 }
161 return 0;
162 }
163 if(saw_xdigit) {
164 if(tp + INT16SZ > endp)
165 return 0;
166 *tp++ = (unsigned char)((val >> 8) & 0xff);
167 *tp++ = (unsigned char)(val & 0xff);
168 }
169 if(colonp) {
170 /*
171 * Since some memmove()'s erroneously fail to handle
172 * overlapping regions, we do the shift by hand.
173 */
174 const ssize_t n = tp - colonp;
175 ssize_t i;
177 if(tp == endp)
178 return 0;
179 for(i = 1; i <= n; i++) {
180 *(endp - i) = *(colonp + n - i);
181 *(colonp + n - i) = 0;
182 }
183 tp = endp;
184 }
185 if(tp != endp)
186 return 0;
187 memcpy(dst, tmp, IN6ADDRSZ);
188 return 1;
189}
191/*
192 * Convert from presentation format (which usually means ASCII printable)
193 * to network format (which is usually some kind of binary format).
194 *
195 * Return:
196 * 1 if the address was valid for the specified address family
197 * 0 if the address was not valid (`dst' is untouched in this case)
198 * -1 if some other error occurred (`dst' is untouched in this case, too)
199 *
200 * author:
201 * Paul Vixie, 1996.
202 */
203int curlx_inet_pton(int af, const char *src, void *dst)
204{
205 switch(af) {
206 case AF_INET:
207 return inet_pton4(src, (unsigned char *)dst);
208 case AF_INET6:
209 return inet_pton6(src, (unsigned char *)dst);
210 default:
211 return -1;
212 }
213 /* NOTREACHED */
214}
Diagnostics4 git calls · 346 ms
CallStatusSizeTime0346 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 · hit25 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=25 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 KiB318 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=318 git.response.bytes=2408 git.response.cache=MISS git.response.duration_ms=318 git.fetch.wants=c2a6eecbb9390a590a846dd4c579faf08a86ff6b 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=2408 git.pkt.payload.max=2387 git.sideband.band1.bytes=2386 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
- a5e35a8a1ca0dfff
- Request
- 17226fdd…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format