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 "unitcheck.h"
26#ifdef HAVE_ARPA_INET_H
27#include <arpa/inet.h>
28#endif
29#ifdef HAVE_NETINET_IN_H
30#include <netinet/in.h>
31#endif
32#ifdef HAVE_NETINET_IN6_H
33#include <netinet/in6.h>
34#endif
36/*
37 * If USE_IPV6 is disabled, we still want to parse IPv6 addresses, so make
38 * sure we have _some_ value for AF_INET6 without polluting our fake value
39 * everywhere.
40 */
41#if !defined(USE_IPV6) && !defined(AF_INET6)
42#define AF_INET6 (AF_INET + 1)
43#endif
45static int test_ntop(void)
46{
47 char ipv6res[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
48 char ipv4res[sizeof("255.255.255.255")];
49 unsigned char ipv6a[26];
50 unsigned char ipv4a[5];
52 ipv4res[0] = '\0';
53 ipv4a[0] = 0xc0;
54 ipv4a[1] = 0xa8;
55 ipv4a[2] = 0x64;
56 ipv4a[3] = 0x01;
57 ipv4a[4] = 0x01;
58 if(curlx_inet_ntop(AF_INET, ipv4a, ipv4res, sizeof(ipv4res)))
59 return 1; /* fail */
60 if(!ipv4res[0])
61 return 1; /* fail */
62 if(memcmp(ipv4res, "192.168.100.1", 13))
63 return 1; /* fail */
65 ipv6res[0] = '\0';
66 memset(ipv6a, 0, sizeof(ipv6a));
67 ipv6a[0] = 0xfe;
68 ipv6a[1] = 0x80;
69 ipv6a[8] = 0x02;
70 ipv6a[9] = 0x14;
71 ipv6a[10] = 0x4f;
72 ipv6a[11] = 0xff;
73 ipv6a[12] = 0xfe;
74 ipv6a[13] = 0x0b;
75 ipv6a[14] = 0x76;
76 ipv6a[15] = 0xc8;
77 ipv6a[25] = 0x01;
78 if(curlx_inet_ntop(AF_INET6, ipv6a, ipv6res, sizeof(ipv6res)))
79 return 1; /* fail */
80 if(!ipv6res[0])
81 return 1; /* fail */
82 if(memcmp(ipv6res, "fe80::214:4fff:fe0b:76c8", 24))
83 return 1; /* fail */
85 /* verify working RFC 4291 zero prefixed IPv4 - mapped format */
86 memset(ipv6a, 0, sizeof(ipv6a));
87 ipv6a[12] = 0x7f;
88 ipv6a[13] = 0x0;
89 ipv6a[14] = 0x0;
90 ipv6a[15] = 0x01;
91 if(curlx_inet_ntop(AF_INET6, ipv6a, ipv6res, sizeof(ipv6res)))
92 return 1; /* fail */
93 if(!ipv6res[0])
94 return 1; /* fail */
95 if(memcmp(ipv6res, "::127.0.0.1", 11))
96 return 1; /* fail */
98 return 0;
99}
101static int test_pton(void)
102{
103 unsigned char ipv6a[16 + 1];
104 unsigned char ipv4a[4 + 1];
105 const char *ipv6src = "fe80::214:4fff:fe0b:76c8";
106 const char *ipv4src = "192.168.100.1";
108 memset(ipv4a, 1, sizeof(ipv4a));
109 if(curlx_inet_pton(AF_INET, ipv4src, ipv4a) != 1)
110 return 1; /* fail */
112 if((ipv4a[0] != 0xc0) ||
113 (ipv4a[1] != 0xa8) ||
114 (ipv4a[2] != 0x64) ||
115 (ipv4a[3] != 0x01) ||
116 (ipv4a[4] != 0x01))
117 return 1; /* fail */
119 memset(ipv6a, 1, sizeof(ipv6a));
120 if(curlx_inet_pton(AF_INET6, ipv6src, ipv6a) != 1)
121 return 1; /* fail */
123 if((ipv6a[0] != 0xfe) ||
124 (ipv6a[1] != 0x80) ||
125 (ipv6a[8] != 0x02) ||
126 (ipv6a[9] != 0x14) ||
127 (ipv6a[10] != 0x4f) ||
128 (ipv6a[11] != 0xff) ||
129 (ipv6a[12] != 0xfe) ||
130 (ipv6a[13] != 0x0b) ||
131 (ipv6a[14] != 0x76) ||
132 (ipv6a[15] != 0xc8) ||
133 (ipv6a[16] != 0x01))
134 return 1; /* fail */
136 if((ipv6a[2] != 0x0) ||
137 (ipv6a[3] != 0x0) ||
138 (ipv6a[4] != 0x0) ||
139 (ipv6a[5] != 0x0) ||
140 (ipv6a[6] != 0x0) ||
141 (ipv6a[7] != 0x0))
142 return 1; /* fail */
144 return 0;
145}
147struct pton6_case {
148 const char *addr;
149 int valid;
150};
152static const struct pton6_case pton6_cases[] = {
153 { "1:2:3:4:5:6:7:8:", 0 }, /* AISLE-2026-0115-00325 */
154 { "::1:", 0 }, /* AISLE-2026-0115-00290 */
155 { "1:2:3:", 0 },
156 { "1:", 0 },
157 { ":1", 0 },
158 { ":::", 0 },
159 { "1:2:3:4:5:6:7:8::", 0 },
160 { "1:2:3:4:5:6:7::8:9", 0 },
161 { "", 0 },
162 { "::", 1 },
163 { "::1", 1 },
164 { "1::", 1 },
165 { "1::8", 1 },
166 { "1:2:3:4:5:6:7:8", 1 },
167 { "1:2:3:4:5:6::", 1 },
168 { "1:2:3:4:5:6::8", 1 },
169 { "fe80::1", 1 },
170 { "::ffff:192.0.2.1", 1 },
171 { "::127.0.0.1", 1 }
172};
174static int test_pton_cases(void)
175{
176 unsigned char ipv6a[16];
177 size_t i;
179 for(i = 0; i < CURL_ARRAYSIZE(pton6_cases); i++) {
180 int rc = curlx_inet_pton(AF_INET6, pton6_cases[i].addr, ipv6a);
181 int got_valid = (rc == 1);
182 if(got_valid != pton6_cases[i].valid)
183 return 1; /* fail */
184 }
186 return 0;
187}
189static CURLcode test_unit1961(const char *arg)
190{
191 UNITTEST_BEGIN_SIMPLE
193 fail_if(test_ntop(), "curlx_inet_ntop()");
194 fail_if(test_pton(), "curlx_inet_pton()");
195 fail_if(test_pton_cases(), "curlx_inet_pton() IPv6 edge cases");
197 UNITTEST_END_SIMPLE
198}
Diagnostics4 git calls · 371 ms
CallStatusSizeTime0371 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=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 · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=363 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=5 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
fetch2001.8 KiB363 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1851 git.response.cache=MISS git.response.duration_ms=363 git.fetch.wants=ade713435f6eb0063cd1172838987bcb3ca73bf1 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=1851 git.pkt.payload.max=1830 git.sideband.band1.bytes=1829 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
- a5e2ebe67f5a4bc2
- Request
- 55ce4082…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format