···11+ GNU LESSER GENERAL PUBLIC LICENSE
22+ Version 3, 29 June 2007
33+44+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
55+ Everyone is permitted to copy and distribute verbatim copies
66+ of this license document, but changing it is not allowed.
77+88+99+ This version of the GNU Lesser General Public License incorporates
1010+the terms and conditions of version 3 of the GNU General Public
1111+License, supplemented by the additional permissions listed below.
1212+1313+ 0. Additional Definitions.
1414+1515+ As used herein, "this License" refers to version 3 of the GNU Lesser
1616+General Public License, and the "GNU GPL" refers to version 3 of the GNU
1717+General Public License.
1818+1919+ "The Library" refers to a covered work governed by this License,
2020+other than an Application or a Combined Work as defined below.
2121+2222+ An "Application" is any work that makes use of an interface provided
2323+by the Library, but which is not otherwise based on the Library.
2424+Defining a subclass of a class defined by the Library is deemed a mode
2525+of using an interface provided by the Library.
2626+2727+ A "Combined Work" is a work produced by combining or linking an
2828+Application with the Library. The particular version of the Library
2929+with which the Combined Work was made is also called the "Linked
3030+Version".
3131+3232+ The "Minimal Corresponding Source" for a Combined Work means the
3333+Corresponding Source for the Combined Work, excluding any source code
3434+for portions of the Combined Work that, considered in isolation, are
3535+based on the Application, and not on the Linked Version.
3636+3737+ The "Corresponding Application Code" for a Combined Work means the
3838+object code and/or source code for the Application, including any data
3939+and utility programs needed for reproducing the Combined Work from the
4040+Application, but excluding the System Libraries of the Combined Work.
4141+4242+ 1. Exception to Section 3 of the GNU GPL.
4343+4444+ You may convey a covered work under sections 3 and 4 of this License
4545+without being bound by section 3 of the GNU GPL.
4646+4747+ 2. Conveying Modified Versions.
4848+4949+ If you modify a copy of the Library, and, in your modifications, a
5050+facility refers to a function or data to be supplied by an Application
5151+that uses the facility (other than as an argument passed when the
5252+facility is invoked), then you may convey a copy of the modified
5353+version:
5454+5555+ a) under this License, provided that you make a good faith effort to
5656+ ensure that, in the event an Application does not supply the
5757+ function or data, the facility still operates, and performs
5858+ whatever part of its purpose remains meaningful, or
5959+6060+ b) under the GNU GPL, with none of the additional permissions of
6161+ this License applicable to that copy.
6262+6363+ 3. Object Code Incorporating Material from Library Header Files.
6464+6565+ The object code form of an Application may incorporate material from
6666+a header file that is part of the Library. You may convey such object
6767+code under terms of your choice, provided that, if the incorporated
6868+material is not limited to numerical parameters, data structure
6969+layouts and accessors, or small macros, inline functions and templates
7070+(ten or fewer lines in length), you do both of the following:
7171+7272+ a) Give prominent notice with each copy of the object code that the
7373+ Library is used in it and that the Library and its use are
7474+ covered by this License.
7575+7676+ b) Accompany the object code with a copy of the GNU GPL and this license
7777+ document.
7878+7979+ 4. Combined Works.
8080+8181+ You may convey a Combined Work under terms of your choice that,
8282+taken together, effectively do not restrict modification of the
8383+portions of the Library contained in the Combined Work and reverse
8484+engineering for debugging such modifications, if you also do each of
8585+the following:
8686+8787+ a) Give prominent notice with each copy of the Combined Work that
8888+ the Library is used in it and that the Library and its use are
8989+ covered by this License.
9090+9191+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
9292+ document.
9393+9494+ c) For a Combined Work that displays copyright notices during
9595+ execution, include the copyright notice for the Library among
9696+ these notices, as well as a reference directing the user to the
9797+ copies of the GNU GPL and this license document.
9898+9999+ d) Do one of the following:
100100+101101+ 0) Convey the Minimal Corresponding Source under the terms of this
102102+ License, and the Corresponding Application Code in a form
103103+ suitable for, and under terms that permit, the user to
104104+ recombine or relink the Application with a modified version of
105105+ the Linked Version to produce a modified Combined Work, in the
106106+ manner specified by section 6 of the GNU GPL for conveying
107107+ Corresponding Source.
108108+109109+ 1) Use a suitable shared library mechanism for linking with the
110110+ Library. A suitable mechanism is one that (a) uses at run time
111111+ a copy of the Library already present on the user's computer
112112+ system, and (b) will operate properly with a modified version
113113+ of the Library that is interface-compatible with the Linked
114114+ Version.
115115+116116+ e) Provide Installation Information, but only if you would otherwise
117117+ be required to provide such information under section 6 of the
118118+ GNU GPL, and only to the extent that such information is
119119+ necessary to install and execute a modified version of the
120120+ Combined Work produced by recombining or relinking the
121121+ Application with a modified version of the Linked Version. (If
122122+ you use option 4d0, the Installation Information must accompany
123123+ the Minimal Corresponding Source and Corresponding Application
124124+ Code. If you use option 4d1, you must provide the Installation
125125+ Information in the manner specified by section 6 of the GNU GPL
126126+ for conveying Corresponding Source.)
127127+128128+ 5. Combined Libraries.
129129+130130+ You may place library facilities that are a work based on the
131131+Library side by side in a single library together with other library
132132+facilities that are not Applications and are not covered by this
133133+License, and convey such a combined library under terms of your
134134+choice, if you do both of the following:
135135+136136+ a) Accompany the combined library with a copy of the same work based
137137+ on the Library, uncombined with any other library facilities,
138138+ conveyed under the terms of this License.
139139+140140+ b) Give prominent notice with the combined library that part of it
141141+ is a work based on the Library, and explaining where to find the
142142+ accompanying uncombined form of the same work.
143143+144144+ 6. Revised Versions of the GNU Lesser General Public License.
145145+146146+ The Free Software Foundation may publish revised and/or new versions
147147+of the GNU Lesser General Public License from time to time. Such new
148148+versions will be similar in spirit to the present version, but may
149149+differ in detail to address new problems or concerns.
150150+151151+ Each version is given a distinguishing version number. If the
152152+Library as you received it specifies that a certain numbered version
153153+of the GNU Lesser General Public License "or any later version"
154154+applies to it, you have the option of following the terms and
155155+conditions either of that published version or of any later version
156156+published by the Free Software Foundation. If the Library as you
157157+received it does not specify a version number of the GNU Lesser
158158+General Public License, you may choose any version of the GNU Lesser
159159+General Public License ever published by the Free Software Foundation.
160160+161161+ If the Library as you received it specifies that a proxy can decide
162162+whether future versions of the GNU Lesser General Public License shall
163163+apply, that proxy's public statement of acceptance of any version is
164164+permanent authorization for you to choose that version for the
165165+Library.
+221
src/libinfo/darling-resolver/resolver.c
···11+/*
22+ * Darling - DNS resolver module
33+ * Copyright (c) 2015 Lubos Dolezel, All rights reserved.
44+ *
55+ * This library is free software; you can redistribute it and/or
66+ * modify it under the terms of the GNU Lesser General Public
77+ * License as published by the Free Software Foundation; either
88+ * version 3.0 of the License, or (at your option) any later version.
99+ *
1010+ * This library is distributed in the hope that it will be useful,
1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1313+ * Lesser General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU Lesser General Public
1616+ * License along with this library.
1717+ */
1818+1919+#include "../lookup.subproj/si_module.h"
2020+#include <dispatch/dispatch.h>
2121+#include <resolv.h>
2222+#include <stdio.h>
2323+2424+static int
2525+dr_is_valid(si_mod_t *si, si_item_t *item)
2626+{
2727+ return 0;
2828+}
2929+3030+static void
3131+dr_close(si_mod_t *si)
3232+{
3333+}
3434+3535+static si_item_t *
3636+dr_hostbyname(si_mod_t *si, const char *name, int af, const char *interface, uint32_t *err)
3737+{
3838+ int type, l, i, elem_length;
3939+ unsigned char buf[4096];
4040+ ns_msg msg;
4141+ ns_rr rr;
4242+ char* addr_buf;
4343+ void** addr_ptrs;
4444+ uint64_t ttl_end;
4545+4646+ if (af == AF_INET)
4747+ {
4848+ elem_length = 4;
4949+ type = ns_t_a;
5050+ }
5151+ else if (af == AF_INET6)
5252+ {
5353+ elem_length = 16;
5454+ type = ns_t_aaaa;
5555+ }
5656+ else
5757+ return NULL;
5858+5959+ l = res_query(name, ns_c_any, type, buf, sizeof(buf));
6060+ if (l < 0)
6161+ return NULL;
6262+6363+ ns_initparse(buf, l, &msg);
6464+ l = ns_msg_count(msg, ns_s_an);
6565+6666+ addr_buf = (char*) __builtin_alloca(l * elem_length);
6767+ addr_ptrs = (void**) __builtin_alloca((l+1) * sizeof(void*));
6868+ addr_ptrs[l] = NULL;
6969+7070+ for (i = 0; i < l; i++)
7171+ {
7272+ const unsigned char* data;
7373+ int type;
7474+7575+ ns_parserr(&msg, ns_s_an, i, &rr);
7676+ data = ns_rr_rdata(rr);
7777+ type = ns_rr_type(rr);
7878+7979+ if ((af == AF_INET && type == ns_t_a)
8080+ || (af == AF_INET6 && type == ns_t_aaaa))
8181+ {
8282+ memcpy(addr_buf + (i*elem_length), data, elem_length);
8383+ addr_ptrs[i] = addr_buf + (i*elem_length);
8484+ }
8585+ }
8686+8787+ ttl_end = time(NULL) + rr.ttl;
8888+ if (af == AF_INET)
8989+ {
9090+ return (si_item_t *)LI_ils_create("L4488s*44a", (unsigned long)si, CATEGORY_HOST_IPV4, 1, ttl_end,
9191+ 0LL, name, NULL, af, elem_length, addr_ptrs);
9292+ }
9393+ else if (af == AF_INET6)
9494+ {
9595+ return (si_item_t *)LI_ils_create("L4488s*44c", (unsigned long)si, CATEGORY_HOST_IPV6, 1, ttl_end,
9696+ 0LL, name, NULL, af, elem_length, addr_ptrs);
9797+ }
9898+ return NULL;
9999+}
100100+101101+static si_item_t *
102102+dr_hostbyaddr(si_mod_t *si, const void *addr, int af, const char *interface, uint32_t *err)
103103+{
104104+ char ptr[100];
105105+ unsigned char buf[4096];
106106+ int l, i;
107107+ ns_msg msg;
108108+ ns_rr rr;
109109+ char** name_ptrs;
110110+111111+ if (af == AF_INET)
112112+ {
113113+ const unsigned char* ip = (const unsigned char*) addr;
114114+ sprintf(ptr, "%d.%d.%d.%d.in-addr.arpa", ip[3], ip[2], ip[1], ip[0]);
115115+ }
116116+ else if (af == AF_INET6)
117117+ {
118118+ if (memcmp(addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12) == 0)
119119+ {
120120+ // This is a mapped IPv4 address
121121+ const unsigned char* ip = ((const unsigned char*) addr) + 12;
122122+ sprintf(ptr, "%d.%d.%d.%d.in-addr.arpa", ip[3], ip[2], ip[1], ip[0]);
123123+ }
124124+ else
125125+ {
126126+ const unsigned char* ip = (const unsigned char*) addr;
127127+ const char* dig = "0123456789abcdef";
128128+ int i;
129129+130130+ for (i = 0; i < 16; i++)
131131+ {
132132+ ptr[i*4] = dig[ip[i] & 0xf];
133133+ ptr[i*4+1] = '.';
134134+ ptr[i*4+2] = dig[ip[i] >> 4];
135135+ ptr[i*4+3] = '.';
136136+ }
137137+ strcpy(&ptr[64], "ip6.arpa");
138138+ }
139139+ }
140140+ else
141141+ return NULL;
142142+143143+ l = res_query(ptr, ns_c_any, ns_t_ptr, buf, sizeof(buf));
144144+ if (l < 0)
145145+ return NULL;
146146+147147+ ns_initparse(buf, l, &msg);
148148+ l = ns_msg_count(msg, ns_s_an);
149149+150150+ name_ptrs = (char**) __builtin_alloca((l+1) * sizeof(char*));
151151+ name_ptrs[l] = NULL;
152152+153153+ for (i = 0; i < l; i++)
154154+ {
155155+ const unsigned char* data;
156156+ int type;
157157+158158+ ns_parserr(&msg, ns_s_an, i, &rr);
159159+ data = ns_rr_rdata(rr);
160160+ type = ns_rr_type(rr);
161161+162162+ if (type == ns_t_ptr)
163163+ {
164164+ // TODO
165165+ }
166166+ }
167167+168168+ return NULL;
169169+}
170170+171171+static si_list_t *
172172+dr_addrinfo(si_mod_t *si, const void *node, const void *serv, uint32_t family, uint32_t socktype, uint32_t proto, uint32_t flags, const char *interface, uint32_t *err)
173173+{
174174+ return NULL;
175175+}
176176+177177+static si_item_t *
178178+dr_item_call(si_mod_t *si, int call, const char *name, const char *ignored, const char *interface, uint32_t class, uint32_t type, uint32_t *err)
179179+{
180180+ return NULL;
181181+}
182182+183183+static si_list_t *
184184+dr_srv_byname(si_mod_t* si, const char *qname, const char *interface, uint32_t *err)
185185+{
186186+ return NULL;
187187+}
188188+189189+si_mod_t *si_module_static_darling(void)
190190+{
191191+ static const struct si_mod_vtable_s dr_vtable =
192192+ {
193193+ .sim_close = &dr_close,
194194+ .sim_is_valid = &dr_is_valid,
195195+ .sim_host_byname = &dr_hostbyname,
196196+ .sim_host_byaddr = &dr_hostbyaddr,
197197+ .sim_item_call = &dr_item_call,
198198+ .sim_addrinfo = &dr_addrinfo,
199199+ .sim_srv_byname = &dr_srv_byname,
200200+ };
201201+202202+ static si_mod_t si =
203203+ {
204204+ .vers = 1,
205205+ .refcount = 1,
206206+ .flags = SI_MOD_FLAG_STATIC,
207207+208208+ .private = NULL,
209209+ .vtable = &dr_vtable,
210210+ };
211211+212212+ static dispatch_once_t once;
213213+214214+ dispatch_once(&once, ^{
215215+ si.name = strdup("darling-resolver");
216216+ });
217217+218218+ return (si_mod_t*)&si;
219219+220220+}
221221+
+3
src/libinfo/dns.subproj/res_query.c
···11+// Modified by Lubos Dolezel for Darling
12/*
23 * Copyright (c) 1999, 2012 Apple Inc. All rights reserved.
34 *
···4445#endif
4546char _res[RES_9_STATE_SIZE] = {0};
46474848+#ifndef DARLING
4749int
4850res_init(void)
4951{
···128130{
129131 return _mdns_query(SI_CALL_DNS_SEARCH, name, class, type, answer, anslen);
130132}
133133+#endif