visaljs 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/THIRD_PARTY_LICENSES +31 -1
- package/cli.js +962 -68
- package/node/include/js_node.h +11 -1
- package/node/prelude/_http_common.js +29 -0
- package/node/prelude/async_hooks.js +50 -11
- package/node/prelude/child_process.js +31 -4
- package/node/prelude/console.js +311 -143
- package/node/prelude/crypto.js +6 -4
- package/node/prelude/dgram.js +1169 -0
- package/node/prelude/diagnostics_channel.js +3 -1
- package/node/prelude/dns.js +250 -45
- package/node/prelude/dns_promises.js +8 -2
- package/node/prelude/fs_promises.js +9 -1
- package/node/prelude/http.js +395 -86
- package/node/prelude/https.js +13 -4
- package/node/prelude/internal/console_class.js +7 -0
- package/node/prelude/internal/console_global.js +25 -0
- package/node/prelude/internal/crypto/key_encryption.js +217 -0
- package/node/prelude/internal/crypto/keys.js +161 -26
- package/node/prelude/internal/crypto/random.js +24 -0
- package/node/prelude/internal/crypto/util.js +2 -1
- package/node/prelude/internal/crypto_x509.js +161 -0
- package/node/prelude/internal/dns_classes.js +6 -0
- package/node/prelude/internal/dns_resolver.js +371 -0
- package/node/prelude/internal/errors.js +9 -0
- package/node/prelude/internal/events_on.js +82 -37
- package/node/prelude/internal/features.js +8 -4
- package/node/prelude/internal/fs_filehandle.js +10 -4
- package/node/prelude/internal/perf_histogram.js +1 -1
- package/node/prelude/internal/process_more.js +32 -17
- package/node/prelude/internal/process_signals.js +8 -2
- package/node/prelude/internal/punycode.ts +163 -0
- package/node/prelude/internal/readline.js +648 -274
- package/node/prelude/internal/readline_editor.js +1240 -0
- package/node/prelude/internal/string_width.js +43 -0
- package/node/prelude/internal/tls/common.js +145 -33
- package/node/prelude/internal/tls/wrap.js +182 -49
- package/node/prelude/internal/tls/x509.js +4 -1
- package/node/prelude/internal/udp.js +177 -0
- package/node/prelude/net.js +13 -1
- package/node/prelude/os.js +24 -6
- package/node/prelude/perf_hooks.js +37 -2
- package/node/prelude/punycode.js +2 -130
- package/node/prelude/readline.js +113 -4
- package/node/prelude/readline_promises.js +56 -32
- package/node/prelude/tls.js +21 -4
- package/node/prelude/util.js +3 -16
- package/node/src/host_dns.c +623 -0
- package/node/src/host_http.c +12 -0
- package/node/src/host_net.c +46 -0
- package/node/src/host_os.c +1 -6
- package/node/src/host_sys.c +70 -0
- package/node/src/host_udp.c +418 -0
- package/node/third_party/c-ares/LICENSE.md +24 -0
- package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
- package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
- package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
- package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
- package/node/third_party/c-ares/include/ares.h +1237 -0
- package/node/third_party/c-ares/include/ares_build.h +202 -0
- package/node/third_party/c-ares/include/ares_dns.h +127 -0
- package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
- package/node/third_party/c-ares/include/ares_nameser.h +510 -0
- package/node/third_party/c-ares/include/ares_version.h +47 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
- package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
- package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
- package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
- package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
- package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
- package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
- package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
- package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
- package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
- package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
- package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
- package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
- package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
- package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
- package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
- package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
- package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
- package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
- package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
- package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
- package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
- package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
- package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
- package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
- package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
- package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
- package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
- package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
- package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
- package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
- package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
- package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
- package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
- package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
- package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
- package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
- package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
- package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
- package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
- package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
- package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
- package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
- package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
- package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
- package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
- package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
- package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
- package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
- package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
- package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
- package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
- package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
- package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
- package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
- package/package.json +1 -1
- package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_builtins.h +5 -0
- package/runtime/include/js_crypto.h +11 -0
- package/runtime/include/js_gc.h +13 -10
- package/runtime/include/js_jobs.h +2 -0
- package/runtime/include/js_object.h +58 -0
- package/runtime/include/jscontext.h +1 -0
- package/runtime/src/crypto_internal.h +1 -0
- package/runtime/src/crypto_subtle.c +66 -7
- package/runtime/src/crypto_tls.c +265 -19
- package/runtime/src/gc.c +73 -92
- package/runtime/src/inspect.c +18 -1
- package/runtime/src/jobs.c +37 -22
- package/runtime/src/object.c +49 -2
- package/runtime/src/os.c +16 -6
- package/runtime/src/os.h +2 -0
- package/runtime/src/process.c +97 -10
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2012 by Gilles Chehade <gilles@openbsd.org>
|
|
3
|
+
* Copyright (c) 1996,1999 by 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: MIT
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#include "ares_private.h"
|
|
22
|
+
|
|
23
|
+
#ifdef HAVE_NETINET_IN_H
|
|
24
|
+
# include <netinet/in.h>
|
|
25
|
+
#endif
|
|
26
|
+
#ifdef HAVE_ARPA_INET_H
|
|
27
|
+
# include <arpa/inet.h>
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
#include "ares_nameser.h"
|
|
31
|
+
|
|
32
|
+
#include "ares_ipv6.h"
|
|
33
|
+
#include "ares_inet_net_pton.h"
|
|
34
|
+
|
|
35
|
+
#ifdef USE_WINSOCK
|
|
36
|
+
# define SOCKERRNO ((int)WSAGetLastError())
|
|
37
|
+
# define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
|
|
38
|
+
# undef EMSGSIZE
|
|
39
|
+
# define EMSGSIZE WSAEMSGSIZE
|
|
40
|
+
# undef ENOENT
|
|
41
|
+
# define ENOENT WSA_INVALID_PARAMETER
|
|
42
|
+
# undef EAFNOSUPPORT
|
|
43
|
+
# define EAFNOSUPPORT WSAEAFNOSUPPORT
|
|
44
|
+
#else
|
|
45
|
+
# define SOCKERRNO (errno)
|
|
46
|
+
# define SET_SOCKERRNO(x) (errno = (x))
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
const struct ares_in6_addr ares_in6addr_any = { { { 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
50
|
+
0, 0, 0, 0, 0, 0, 0 } } };
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* static int
|
|
54
|
+
* inet_net_pton_ipv4(src, dst, size)
|
|
55
|
+
* convert IPv4 network number from presentation to network format.
|
|
56
|
+
* accepts hex octets, hex strings, decimal octets, and /CIDR.
|
|
57
|
+
* "size" is in bytes and describes "dst".
|
|
58
|
+
* return:
|
|
59
|
+
* number of bits, either imputed classfully or specified with /CIDR,
|
|
60
|
+
* or -1 if some failure occurred (check errno). ENOENT means it was
|
|
61
|
+
* not an IPv4 network specification.
|
|
62
|
+
* note:
|
|
63
|
+
* network byte order assumed. this means 192.5.5.240/28 has
|
|
64
|
+
* 0b11110000 in its fourth octet.
|
|
65
|
+
* note:
|
|
66
|
+
* On Windows we store the error in the thread errno, not
|
|
67
|
+
* in the winsock error code. This is to avoid losing the
|
|
68
|
+
* actual last winsock error. So use macro ERRNO to fetch the
|
|
69
|
+
* errno this function sets when returning (-1), not SOCKERRNO.
|
|
70
|
+
* author:
|
|
71
|
+
* Paul Vixie (ISC), June 1996
|
|
72
|
+
*/
|
|
73
|
+
static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst,
|
|
74
|
+
size_t size)
|
|
75
|
+
{
|
|
76
|
+
static const char xdigits[] = "0123456789abcdef";
|
|
77
|
+
static const char digits[] = "0123456789";
|
|
78
|
+
int n;
|
|
79
|
+
int ch;
|
|
80
|
+
int tmp = 0;
|
|
81
|
+
int dirty;
|
|
82
|
+
int bits;
|
|
83
|
+
const unsigned char *odst = dst;
|
|
84
|
+
|
|
85
|
+
ch = *src++;
|
|
86
|
+
if (ch == '0' && (src[0] == 'x' || src[0] == 'X') && ares_isascii(src[1]) &&
|
|
87
|
+
ares_isxdigit(src[1])) {
|
|
88
|
+
/* Hexadecimal: Eat nybble string. */
|
|
89
|
+
if (!size) {
|
|
90
|
+
goto emsgsize;
|
|
91
|
+
}
|
|
92
|
+
dirty = 0;
|
|
93
|
+
src++; /* skip x or X. */
|
|
94
|
+
while ((ch = *src++) != '\0' && ares_isascii(ch) && ares_isxdigit(ch)) {
|
|
95
|
+
if (ares_isupper(ch)) {
|
|
96
|
+
ch = ares_tolower((unsigned char)ch);
|
|
97
|
+
}
|
|
98
|
+
n = (int)(strchr(xdigits, ch) - xdigits);
|
|
99
|
+
if (dirty == 0) {
|
|
100
|
+
tmp = n;
|
|
101
|
+
} else {
|
|
102
|
+
tmp = (tmp << 4) | n;
|
|
103
|
+
}
|
|
104
|
+
if (++dirty == 2) {
|
|
105
|
+
if (!size--) {
|
|
106
|
+
goto emsgsize;
|
|
107
|
+
}
|
|
108
|
+
*dst++ = (unsigned char)tmp;
|
|
109
|
+
dirty = 0;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (dirty) { /* Odd trailing nybble? */
|
|
113
|
+
if (!size--) {
|
|
114
|
+
goto emsgsize;
|
|
115
|
+
}
|
|
116
|
+
*dst++ = (unsigned char)(tmp << 4);
|
|
117
|
+
}
|
|
118
|
+
} else if (ares_isascii(ch) && ares_isdigit(ch)) {
|
|
119
|
+
/* Decimal: eat dotted digit string. */
|
|
120
|
+
for (;;) {
|
|
121
|
+
tmp = 0;
|
|
122
|
+
do {
|
|
123
|
+
n = (int)(strchr(digits, ch) - digits);
|
|
124
|
+
tmp *= 10;
|
|
125
|
+
tmp += n;
|
|
126
|
+
if (tmp > 255) {
|
|
127
|
+
goto enoent;
|
|
128
|
+
}
|
|
129
|
+
} while ((ch = *src++) != '\0' && ares_isascii(ch) && ares_isdigit(ch));
|
|
130
|
+
if (!size--) {
|
|
131
|
+
goto emsgsize;
|
|
132
|
+
}
|
|
133
|
+
*dst++ = (unsigned char)tmp;
|
|
134
|
+
if (ch == '\0' || ch == '/') {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (ch != '.') {
|
|
138
|
+
goto enoent;
|
|
139
|
+
}
|
|
140
|
+
ch = *src++;
|
|
141
|
+
if (!ares_isascii(ch) || !ares_isdigit(ch)) {
|
|
142
|
+
goto enoent;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
goto enoent;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
bits = -1;
|
|
150
|
+
if (ch == '/' && ares_isascii(src[0]) && ares_isdigit(src[0]) && dst > odst) {
|
|
151
|
+
/* CIDR width specifier. Nothing can follow it. */
|
|
152
|
+
ch = *src++; /* Skip over the /. */
|
|
153
|
+
bits = 0;
|
|
154
|
+
do {
|
|
155
|
+
n = (int)(strchr(digits, ch) - digits);
|
|
156
|
+
bits *= 10;
|
|
157
|
+
bits += n;
|
|
158
|
+
if (bits > 32) {
|
|
159
|
+
goto enoent;
|
|
160
|
+
}
|
|
161
|
+
} while ((ch = *src++) != '\0' && ares_isascii(ch) && ares_isdigit(ch));
|
|
162
|
+
if (ch != '\0') {
|
|
163
|
+
goto enoent;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* Firey death and destruction unless we prefetched EOS. */
|
|
168
|
+
if (ch != '\0') {
|
|
169
|
+
goto enoent;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/* If nothing was written to the destination, we found no address. */
|
|
173
|
+
if (dst == odst) {
|
|
174
|
+
goto enoent; /* LCOV_EXCL_LINE: all valid paths above increment dst */
|
|
175
|
+
}
|
|
176
|
+
/* If no CIDR spec was given, infer width from net class. */
|
|
177
|
+
if (bits == -1) {
|
|
178
|
+
if (*odst >= 240) { /* Class E */
|
|
179
|
+
bits = 32;
|
|
180
|
+
} else if (*odst >= 224) { /* Class D */
|
|
181
|
+
bits = 8;
|
|
182
|
+
} else if (*odst >= 192) { /* Class C */
|
|
183
|
+
bits = 24;
|
|
184
|
+
} else if (*odst >= 128) { /* Class B */
|
|
185
|
+
bits = 16;
|
|
186
|
+
} else { /* Class A */
|
|
187
|
+
bits = 8;
|
|
188
|
+
}
|
|
189
|
+
/* If imputed mask is narrower than specified octets, widen. */
|
|
190
|
+
if (bits < ((dst - odst) * 8)) {
|
|
191
|
+
bits = (int)(dst - odst) * 8;
|
|
192
|
+
}
|
|
193
|
+
/*
|
|
194
|
+
* If there are no additional bits specified for a class D
|
|
195
|
+
* address adjust bits to 4.
|
|
196
|
+
*/
|
|
197
|
+
if (bits == 8 && *odst == 224) {
|
|
198
|
+
bits = 4;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/* Extend network to cover the actual mask. */
|
|
202
|
+
while (bits > ((dst - odst) * 8)) {
|
|
203
|
+
if (!size--) {
|
|
204
|
+
goto emsgsize;
|
|
205
|
+
}
|
|
206
|
+
*dst++ = '\0';
|
|
207
|
+
}
|
|
208
|
+
return bits;
|
|
209
|
+
|
|
210
|
+
enoent:
|
|
211
|
+
SET_SOCKERRNO(ENOENT);
|
|
212
|
+
return -1;
|
|
213
|
+
|
|
214
|
+
emsgsize:
|
|
215
|
+
SET_SOCKERRNO(EMSGSIZE);
|
|
216
|
+
return -1;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
static int getbits(const char *src, size_t *bitsp)
|
|
220
|
+
{
|
|
221
|
+
static const char digits[] = "0123456789";
|
|
222
|
+
size_t n;
|
|
223
|
+
size_t val;
|
|
224
|
+
char ch;
|
|
225
|
+
|
|
226
|
+
val = 0;
|
|
227
|
+
n = 0;
|
|
228
|
+
while ((ch = *src++) != '\0') {
|
|
229
|
+
const char *pch;
|
|
230
|
+
|
|
231
|
+
pch = strchr(digits, ch);
|
|
232
|
+
if (pch != NULL) {
|
|
233
|
+
if (n++ != 0 && val == 0) { /* no leading zeros */
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
236
|
+
val *= 10;
|
|
237
|
+
val += (size_t)(pch - digits);
|
|
238
|
+
if (val > 128) { /* range */
|
|
239
|
+
return 0;
|
|
240
|
+
}
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
if (n == 0) {
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
*bitsp = val;
|
|
249
|
+
return 1;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
static int ares_inet_pton6(const char *src, unsigned char *dst)
|
|
253
|
+
{
|
|
254
|
+
static const char xdigits_l[] = "0123456789abcdef";
|
|
255
|
+
static const char xdigits_u[] = "0123456789ABCDEF";
|
|
256
|
+
unsigned char tmp[NS_IN6ADDRSZ];
|
|
257
|
+
unsigned char *tp;
|
|
258
|
+
unsigned char *endp;
|
|
259
|
+
unsigned char *colonp;
|
|
260
|
+
const char *xdigits;
|
|
261
|
+
const char *curtok;
|
|
262
|
+
int ch;
|
|
263
|
+
int saw_xdigit;
|
|
264
|
+
int count_xdigit;
|
|
265
|
+
unsigned int val;
|
|
266
|
+
|
|
267
|
+
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
|
|
268
|
+
endp = tp + NS_IN6ADDRSZ;
|
|
269
|
+
colonp = NULL;
|
|
270
|
+
/* Leading :: requires some special handling. */
|
|
271
|
+
if (*src == ':') {
|
|
272
|
+
if (*++src != ':') {
|
|
273
|
+
goto enoent;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
curtok = src;
|
|
277
|
+
saw_xdigit = count_xdigit = 0;
|
|
278
|
+
val = 0;
|
|
279
|
+
while ((ch = *src++) != '\0') {
|
|
280
|
+
const char *pch;
|
|
281
|
+
|
|
282
|
+
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) {
|
|
283
|
+
pch = strchr((xdigits = xdigits_u), ch);
|
|
284
|
+
}
|
|
285
|
+
if (pch != NULL) {
|
|
286
|
+
if (count_xdigit >= 4) {
|
|
287
|
+
goto enoent;
|
|
288
|
+
}
|
|
289
|
+
val <<= 4;
|
|
290
|
+
val |= (unsigned int)(pch - xdigits);
|
|
291
|
+
if (val > 0xffff) {
|
|
292
|
+
goto enoent;
|
|
293
|
+
}
|
|
294
|
+
saw_xdigit = 1;
|
|
295
|
+
count_xdigit++;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (ch == ':') {
|
|
299
|
+
curtok = src;
|
|
300
|
+
if (!saw_xdigit) {
|
|
301
|
+
if (colonp) {
|
|
302
|
+
goto enoent;
|
|
303
|
+
}
|
|
304
|
+
colonp = tp;
|
|
305
|
+
continue;
|
|
306
|
+
} else if (*src == '\0') {
|
|
307
|
+
goto enoent;
|
|
308
|
+
}
|
|
309
|
+
if (tp + NS_INT16SZ > endp) {
|
|
310
|
+
goto enoent;
|
|
311
|
+
}
|
|
312
|
+
*tp++ = (unsigned char)(val >> 8) & 0xff;
|
|
313
|
+
*tp++ = (unsigned char)val & 0xff;
|
|
314
|
+
saw_xdigit = 0;
|
|
315
|
+
count_xdigit = 0;
|
|
316
|
+
val = 0;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
|
|
320
|
+
ares_inet_net_pton_ipv4(curtok, tp, NS_INADDRSZ) > 0) {
|
|
321
|
+
tp += NS_INADDRSZ;
|
|
322
|
+
saw_xdigit = 0;
|
|
323
|
+
break; /* '\0' was seen by inet_pton4(). */
|
|
324
|
+
}
|
|
325
|
+
goto enoent;
|
|
326
|
+
}
|
|
327
|
+
if (saw_xdigit) {
|
|
328
|
+
if (tp + NS_INT16SZ > endp) {
|
|
329
|
+
goto enoent;
|
|
330
|
+
}
|
|
331
|
+
*tp++ = (unsigned char)(val >> 8) & 0xff;
|
|
332
|
+
*tp++ = (unsigned char)val & 0xff;
|
|
333
|
+
}
|
|
334
|
+
if (colonp != NULL) {
|
|
335
|
+
/*
|
|
336
|
+
* Since some memmove()'s erroneously fail to handle
|
|
337
|
+
* overlapping regions, we'll do the shift by hand.
|
|
338
|
+
*/
|
|
339
|
+
const int n = (int)(tp - colonp);
|
|
340
|
+
int i;
|
|
341
|
+
|
|
342
|
+
if (tp == endp) {
|
|
343
|
+
goto enoent;
|
|
344
|
+
}
|
|
345
|
+
for (i = 1; i <= n; i++) {
|
|
346
|
+
endp[-i] = colonp[n - i];
|
|
347
|
+
colonp[n - i] = 0;
|
|
348
|
+
}
|
|
349
|
+
tp = endp;
|
|
350
|
+
}
|
|
351
|
+
if (tp != endp) {
|
|
352
|
+
goto enoent;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
memcpy(dst, tmp, NS_IN6ADDRSZ);
|
|
356
|
+
return 1;
|
|
357
|
+
|
|
358
|
+
enoent:
|
|
359
|
+
SET_SOCKERRNO(ENOENT);
|
|
360
|
+
return -1;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
static int ares_inet_net_pton_ipv6(const char *src, unsigned char *dst,
|
|
364
|
+
size_t size)
|
|
365
|
+
{
|
|
366
|
+
struct ares_in6_addr in6;
|
|
367
|
+
int ret;
|
|
368
|
+
size_t bits;
|
|
369
|
+
size_t bytes;
|
|
370
|
+
char buf[INET6_ADDRSTRLEN + sizeof("/128")];
|
|
371
|
+
char *sep;
|
|
372
|
+
|
|
373
|
+
if (ares_strlen(src) >= sizeof buf) {
|
|
374
|
+
SET_SOCKERRNO(EMSGSIZE);
|
|
375
|
+
return -1;
|
|
376
|
+
}
|
|
377
|
+
ares_strcpy(buf, src, sizeof buf);
|
|
378
|
+
|
|
379
|
+
sep = strchr(buf, '/');
|
|
380
|
+
if (sep != NULL) {
|
|
381
|
+
*sep++ = '\0';
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
ret = ares_inet_pton6(buf, (unsigned char *)&in6);
|
|
385
|
+
if (ret != 1) {
|
|
386
|
+
return -1;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (sep == NULL) {
|
|
390
|
+
bits = 128;
|
|
391
|
+
} else {
|
|
392
|
+
if (!getbits(sep, &bits)) {
|
|
393
|
+
SET_SOCKERRNO(ENOENT);
|
|
394
|
+
return -1;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
bytes = (bits + 7) / 8;
|
|
399
|
+
if (bytes > size) {
|
|
400
|
+
SET_SOCKERRNO(EMSGSIZE);
|
|
401
|
+
return -1;
|
|
402
|
+
}
|
|
403
|
+
memcpy(dst, &in6, bytes);
|
|
404
|
+
return (int)bits;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/*
|
|
408
|
+
* int
|
|
409
|
+
* inet_net_pton(af, src, dst, size)
|
|
410
|
+
* convert network number from presentation to network format.
|
|
411
|
+
* accepts hex octets, hex strings, decimal octets, and /CIDR.
|
|
412
|
+
* "size" is in bytes and describes "dst".
|
|
413
|
+
* return:
|
|
414
|
+
* number of bits, either imputed classfully or specified with /CIDR,
|
|
415
|
+
* or -1 if some failure occurred (check errno). ENOENT means it was
|
|
416
|
+
* not a valid network specification.
|
|
417
|
+
* author:
|
|
418
|
+
* Paul Vixie (ISC), June 1996
|
|
419
|
+
*
|
|
420
|
+
*/
|
|
421
|
+
int ares_inet_net_pton(int af, const char *src, void *dst, size_t size)
|
|
422
|
+
{
|
|
423
|
+
switch (af) {
|
|
424
|
+
case AF_INET:
|
|
425
|
+
return ares_inet_net_pton_ipv4(src, dst, size);
|
|
426
|
+
case AF_INET6:
|
|
427
|
+
return ares_inet_net_pton_ipv6(src, dst, size);
|
|
428
|
+
default:
|
|
429
|
+
return -1;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
int ares_inet_pton(int af, const char *src, void *dst)
|
|
434
|
+
{
|
|
435
|
+
int result;
|
|
436
|
+
size_t size;
|
|
437
|
+
|
|
438
|
+
if (af == AF_INET) {
|
|
439
|
+
size = sizeof(struct in_addr);
|
|
440
|
+
} else if (af == AF_INET6) {
|
|
441
|
+
size = sizeof(struct ares_in6_addr);
|
|
442
|
+
} else {
|
|
443
|
+
SET_SOCKERRNO(EAFNOSUPPORT);
|
|
444
|
+
return -1;
|
|
445
|
+
}
|
|
446
|
+
result = ares_inet_net_pton(af, src, dst, size);
|
|
447
|
+
if (result == -1 && SOCKERRNO == ENOENT) {
|
|
448
|
+
return 0;
|
|
449
|
+
}
|
|
450
|
+
return (result > -1) ? 1 : -1;
|
|
451
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
|
3
|
+
* Copyright (c) 1996-1999 by 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 ISC DISCLAIMS ALL WARRANTIES
|
|
10
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
|
12
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
15
|
+
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*
|
|
17
|
+
* SPDX-License-Identifier: MIT
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#include "ares_private.h"
|
|
21
|
+
|
|
22
|
+
#ifdef HAVE_NETINET_IN_H
|
|
23
|
+
# include <netinet/in.h>
|
|
24
|
+
#endif
|
|
25
|
+
#ifdef HAVE_ARPA_INET_H
|
|
26
|
+
# include <arpa/inet.h>
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#include "ares_nameser.h"
|
|
30
|
+
#include "ares_ipv6.h"
|
|
31
|
+
|
|
32
|
+
#ifdef USE_WINSOCK
|
|
33
|
+
# define SOCKERRNO ((int)WSAGetLastError())
|
|
34
|
+
# define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
|
|
35
|
+
# undef EMSGSIZE
|
|
36
|
+
# define EMSGSIZE WSAEMSGSIZE
|
|
37
|
+
# undef ENOENT
|
|
38
|
+
# define ENOENT WSA_INVALID_PARAMETER
|
|
39
|
+
# undef EAFNOSUPPORT
|
|
40
|
+
# define EAFNOSUPPORT WSAEAFNOSUPPORT
|
|
41
|
+
# undef ENOSPC
|
|
42
|
+
# define ENOSPC WSA_INVALID_PARAMETER
|
|
43
|
+
#else
|
|
44
|
+
# define SOCKERRNO (errno)
|
|
45
|
+
# define SET_SOCKERRNO(x) (errno = (x))
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* WARNING: Don't 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
|
+
*/
|
|
52
|
+
|
|
53
|
+
static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size);
|
|
54
|
+
static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size);
|
|
55
|
+
|
|
56
|
+
/* char *
|
|
57
|
+
* inet_ntop(af, src, dst, size)
|
|
58
|
+
* convert a network format address to presentation format.
|
|
59
|
+
* return:
|
|
60
|
+
* pointer to presentation format address (`dst'), or NULL (see errno).
|
|
61
|
+
* author:
|
|
62
|
+
* Paul Vixie, 1996.
|
|
63
|
+
*/
|
|
64
|
+
const char *ares_inet_ntop(int af, const void *src, char *dst,
|
|
65
|
+
ares_socklen_t size)
|
|
66
|
+
{
|
|
67
|
+
switch (af) {
|
|
68
|
+
case AF_INET:
|
|
69
|
+
return inet_ntop4(src, dst, (size_t)size);
|
|
70
|
+
case AF_INET6:
|
|
71
|
+
return inet_ntop6(src, dst, (size_t)size);
|
|
72
|
+
default:
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
SET_SOCKERRNO(EAFNOSUPPORT);
|
|
76
|
+
return NULL;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* const char *
|
|
80
|
+
* inet_ntop4(src, dst, size)
|
|
81
|
+
* format an IPv4 address
|
|
82
|
+
* return:
|
|
83
|
+
* `dst' (as a const)
|
|
84
|
+
* notes:
|
|
85
|
+
* (1) uses no statics
|
|
86
|
+
* (2) takes a unsigned char* not an in_addr as input
|
|
87
|
+
* author:
|
|
88
|
+
* Paul Vixie, 1996.
|
|
89
|
+
*/
|
|
90
|
+
static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size)
|
|
91
|
+
{
|
|
92
|
+
static const char fmt[] = "%u.%u.%u.%u";
|
|
93
|
+
char tmp[sizeof("255.255.255.255")];
|
|
94
|
+
|
|
95
|
+
if (size < sizeof(tmp)) {
|
|
96
|
+
SET_SOCKERRNO(ENOSPC);
|
|
97
|
+
return NULL;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if ((size_t)snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]) >=
|
|
101
|
+
size) {
|
|
102
|
+
SET_SOCKERRNO(ENOSPC);
|
|
103
|
+
return NULL;
|
|
104
|
+
}
|
|
105
|
+
ares_strcpy(dst, tmp, size);
|
|
106
|
+
return dst;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* const char *
|
|
110
|
+
* inet_ntop6(src, dst, size)
|
|
111
|
+
* convert IPv6 binary address into presentation (printable) format
|
|
112
|
+
* author:
|
|
113
|
+
* Paul Vixie, 1996.
|
|
114
|
+
*/
|
|
115
|
+
static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
|
|
116
|
+
{
|
|
117
|
+
/*
|
|
118
|
+
* Note that int32_t and int16_t need only be "at least" large enough
|
|
119
|
+
* to contain a value of the specified size. On some systems, like
|
|
120
|
+
* Crays, there is no such thing as an integer variable with 16 bits.
|
|
121
|
+
* Keep this in mind if you think this function should have been coded
|
|
122
|
+
* to use pointer overlays. All the world's not a VAX.
|
|
123
|
+
*/
|
|
124
|
+
char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
|
|
125
|
+
char *tp;
|
|
126
|
+
|
|
127
|
+
struct {
|
|
128
|
+
ares_ssize_t base;
|
|
129
|
+
size_t len;
|
|
130
|
+
} best, cur;
|
|
131
|
+
|
|
132
|
+
unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
|
|
133
|
+
size_t i;
|
|
134
|
+
|
|
135
|
+
/*
|
|
136
|
+
* Preprocess:
|
|
137
|
+
* Copy the input (bytewise) array into a wordwise array.
|
|
138
|
+
* Find the longest run of 0x00's in src[] for :: shorthanding.
|
|
139
|
+
*/
|
|
140
|
+
memset(words, '\0', sizeof(words));
|
|
141
|
+
for (i = 0; i < NS_IN6ADDRSZ; i++) {
|
|
142
|
+
words[i / 2] |= (unsigned int)(src[i] << ((1 - (i % 2)) << 3));
|
|
143
|
+
}
|
|
144
|
+
best.base = -1;
|
|
145
|
+
best.len = 0;
|
|
146
|
+
cur.base = -1;
|
|
147
|
+
cur.len = 0;
|
|
148
|
+
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
|
|
149
|
+
if (words[i] == 0) {
|
|
150
|
+
if (cur.base == -1) {
|
|
151
|
+
cur.base = (ares_ssize_t)i;
|
|
152
|
+
cur.len = 1;
|
|
153
|
+
} else {
|
|
154
|
+
cur.len++;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
if (cur.base != -1) {
|
|
158
|
+
if (best.base == -1 || cur.len > best.len) {
|
|
159
|
+
best = cur;
|
|
160
|
+
}
|
|
161
|
+
cur.base = -1;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (cur.base != -1) {
|
|
166
|
+
if (best.base == -1 || cur.len > best.len) {
|
|
167
|
+
best = cur;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (best.base != -1 && best.len < 2) {
|
|
171
|
+
best.base = -1;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/*
|
|
175
|
+
* Format the result.
|
|
176
|
+
*/
|
|
177
|
+
tp = tmp;
|
|
178
|
+
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
|
|
179
|
+
/* Are we inside the best run of 0x00's? */
|
|
180
|
+
if (best.base != -1 && i >= (size_t)best.base &&
|
|
181
|
+
i < ((size_t)best.base + best.len)) {
|
|
182
|
+
if (i == (size_t)best.base) {
|
|
183
|
+
*tp++ = ':';
|
|
184
|
+
}
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
/* Are we following an initial run of 0x00s or any real hex? */
|
|
188
|
+
if (i != 0) {
|
|
189
|
+
*tp++ = ':';
|
|
190
|
+
}
|
|
191
|
+
/* Is this address an encapsulated IPv4? */
|
|
192
|
+
if (i == 6 && best.base == 0 &&
|
|
193
|
+
(best.len == 6 || (best.len == 7 && words[7] != 0x0001) ||
|
|
194
|
+
(best.len == 5 && words[5] == 0xffff))) {
|
|
195
|
+
if (!inet_ntop4(src + 12, tp, sizeof(tmp) - (size_t)(tp - tmp))) {
|
|
196
|
+
return (NULL);
|
|
197
|
+
}
|
|
198
|
+
tp += ares_strlen(tp);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
tp += snprintf(tp, sizeof(tmp) - (size_t)(tp - tmp), "%x", words[i]);
|
|
202
|
+
}
|
|
203
|
+
/* Was it a trailing run of 0x00's? */
|
|
204
|
+
if (best.base != -1 &&
|
|
205
|
+
((size_t)best.base + best.len) == (NS_IN6ADDRSZ / NS_INT16SZ)) {
|
|
206
|
+
*tp++ = ':';
|
|
207
|
+
}
|
|
208
|
+
*tp++ = '\0';
|
|
209
|
+
|
|
210
|
+
/*
|
|
211
|
+
* Check for overflow, copy, and we're done.
|
|
212
|
+
*/
|
|
213
|
+
if ((size_t)(tp - tmp) > size) {
|
|
214
|
+
SET_SOCKERRNO(ENOSPC);
|
|
215
|
+
return NULL;
|
|
216
|
+
}
|
|
217
|
+
ares_strcpy(dst, tmp, size);
|
|
218
|
+
return dst;
|
|
219
|
+
}
|