this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Initial code for darling-resolver (gethostbyname() now works, rest remains to be done)

+418 -2
+2
src/libinfo/CMakeLists.txt
··· 27 27 add_subdirectory(rpc.subproj) 28 28 add_subdirectory(lookup.subproj) 29 29 add_subdirectory(membership.subproj) 30 + add_subdirectory(darling-resolver) 30 31 31 32 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling") 32 33 SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) ··· 39 40 $<TARGET_OBJECTS:info-rpc> 40 41 $<TARGET_OBJECTS:info-lookup> 41 42 $<TARGET_OBJECTS:info-membership> 43 + $<TARGET_OBJECTS:darling-resolver> 42 44 ) 43 45 target_link_libraries(system_info system_c resolv-darwin) 44 46
+21
src/libinfo/darling-resolver/CMakeLists.txt
··· 1 + project(darling-resolver) 2 + 3 + cmake_minimum_required(VERSION 2.4.0) 4 + 5 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libc/locale) 6 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libc/locale/FreeBSD) 7 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libc/pthreads) 8 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libc/stdtime/FreeBSD) 9 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../external/libdispatch/) 10 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../external/libdispatch/private) 11 + include_directories(${DARLING_TOP_DIRECTORY}/src/libresolv) 12 + include_directories(${DARLING_TOP_DIRECTORY}/src/libresolv/dnsinfo) 13 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lookup.subproj) 14 + 15 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks") 16 + 17 + set(dr_sources 18 + resolver.c 19 + ) 20 + 21 + add_library(darling-resolver OBJECT ${dr_sources})
+165
src/libinfo/darling-resolver/LICENSE
··· 1 + GNU LESSER GENERAL PUBLIC LICENSE 2 + Version 3, 29 June 2007 3 + 4 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> 5 + Everyone is permitted to copy and distribute verbatim copies 6 + of this license document, but changing it is not allowed. 7 + 8 + 9 + This version of the GNU Lesser General Public License incorporates 10 + the terms and conditions of version 3 of the GNU General Public 11 + License, supplemented by the additional permissions listed below. 12 + 13 + 0. Additional Definitions. 14 + 15 + As used herein, "this License" refers to version 3 of the GNU Lesser 16 + General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 + General Public License. 18 + 19 + "The Library" refers to a covered work governed by this License, 20 + other than an Application or a Combined Work as defined below. 21 + 22 + An "Application" is any work that makes use of an interface provided 23 + by the Library, but which is not otherwise based on the Library. 24 + Defining a subclass of a class defined by the Library is deemed a mode 25 + of using an interface provided by the Library. 26 + 27 + A "Combined Work" is a work produced by combining or linking an 28 + Application with the Library. The particular version of the Library 29 + with which the Combined Work was made is also called the "Linked 30 + Version". 31 + 32 + The "Minimal Corresponding Source" for a Combined Work means the 33 + Corresponding Source for the Combined Work, excluding any source code 34 + for portions of the Combined Work that, considered in isolation, are 35 + based on the Application, and not on the Linked Version. 36 + 37 + The "Corresponding Application Code" for a Combined Work means the 38 + object code and/or source code for the Application, including any data 39 + and utility programs needed for reproducing the Combined Work from the 40 + Application, but excluding the System Libraries of the Combined Work. 41 + 42 + 1. Exception to Section 3 of the GNU GPL. 43 + 44 + You may convey a covered work under sections 3 and 4 of this License 45 + without being bound by section 3 of the GNU GPL. 46 + 47 + 2. Conveying Modified Versions. 48 + 49 + If you modify a copy of the Library, and, in your modifications, a 50 + facility refers to a function or data to be supplied by an Application 51 + that uses the facility (other than as an argument passed when the 52 + facility is invoked), then you may convey a copy of the modified 53 + version: 54 + 55 + a) under this License, provided that you make a good faith effort to 56 + ensure that, in the event an Application does not supply the 57 + function or data, the facility still operates, and performs 58 + whatever part of its purpose remains meaningful, or 59 + 60 + b) under the GNU GPL, with none of the additional permissions of 61 + this License applicable to that copy. 62 + 63 + 3. Object Code Incorporating Material from Library Header Files. 64 + 65 + The object code form of an Application may incorporate material from 66 + a header file that is part of the Library. You may convey such object 67 + code under terms of your choice, provided that, if the incorporated 68 + material is not limited to numerical parameters, data structure 69 + layouts and accessors, or small macros, inline functions and templates 70 + (ten or fewer lines in length), you do both of the following: 71 + 72 + a) Give prominent notice with each copy of the object code that the 73 + Library is used in it and that the Library and its use are 74 + covered by this License. 75 + 76 + b) Accompany the object code with a copy of the GNU GPL and this license 77 + document. 78 + 79 + 4. Combined Works. 80 + 81 + You may convey a Combined Work under terms of your choice that, 82 + taken together, effectively do not restrict modification of the 83 + portions of the Library contained in the Combined Work and reverse 84 + engineering for debugging such modifications, if you also do each of 85 + the following: 86 + 87 + a) Give prominent notice with each copy of the Combined Work that 88 + the Library is used in it and that the Library and its use are 89 + covered by this License. 90 + 91 + b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 + document. 93 + 94 + c) For a Combined Work that displays copyright notices during 95 + execution, include the copyright notice for the Library among 96 + these notices, as well as a reference directing the user to the 97 + copies of the GNU GPL and this license document. 98 + 99 + d) Do one of the following: 100 + 101 + 0) Convey the Minimal Corresponding Source under the terms of this 102 + License, and the Corresponding Application Code in a form 103 + suitable for, and under terms that permit, the user to 104 + recombine or relink the Application with a modified version of 105 + the Linked Version to produce a modified Combined Work, in the 106 + manner specified by section 6 of the GNU GPL for conveying 107 + Corresponding Source. 108 + 109 + 1) Use a suitable shared library mechanism for linking with the 110 + Library. A suitable mechanism is one that (a) uses at run time 111 + a copy of the Library already present on the user's computer 112 + system, and (b) will operate properly with a modified version 113 + of the Library that is interface-compatible with the Linked 114 + Version. 115 + 116 + e) Provide Installation Information, but only if you would otherwise 117 + be required to provide such information under section 6 of the 118 + GNU GPL, and only to the extent that such information is 119 + necessary to install and execute a modified version of the 120 + Combined Work produced by recombining or relinking the 121 + Application with a modified version of the Linked Version. (If 122 + you use option 4d0, the Installation Information must accompany 123 + the Minimal Corresponding Source and Corresponding Application 124 + Code. If you use option 4d1, you must provide the Installation 125 + Information in the manner specified by section 6 of the GNU GPL 126 + for conveying Corresponding Source.) 127 + 128 + 5. Combined Libraries. 129 + 130 + You may place library facilities that are a work based on the 131 + Library side by side in a single library together with other library 132 + facilities that are not Applications and are not covered by this 133 + License, and convey such a combined library under terms of your 134 + choice, if you do both of the following: 135 + 136 + a) Accompany the combined library with a copy of the same work based 137 + on the Library, uncombined with any other library facilities, 138 + conveyed under the terms of this License. 139 + 140 + b) Give prominent notice with the combined library that part of it 141 + is a work based on the Library, and explaining where to find the 142 + accompanying uncombined form of the same work. 143 + 144 + 6. Revised Versions of the GNU Lesser General Public License. 145 + 146 + The Free Software Foundation may publish revised and/or new versions 147 + of the GNU Lesser General Public License from time to time. Such new 148 + versions will be similar in spirit to the present version, but may 149 + differ in detail to address new problems or concerns. 150 + 151 + Each version is given a distinguishing version number. If the 152 + Library as you received it specifies that a certain numbered version 153 + of the GNU Lesser General Public License "or any later version" 154 + applies to it, you have the option of following the terms and 155 + conditions either of that published version or of any later version 156 + published by the Free Software Foundation. If the Library as you 157 + received it does not specify a version number of the GNU Lesser 158 + General Public License, you may choose any version of the GNU Lesser 159 + General Public License ever published by the Free Software Foundation. 160 + 161 + If the Library as you received it specifies that a proxy can decide 162 + whether future versions of the GNU Lesser General Public License shall 163 + apply, that proxy's public statement of acceptance of any version is 164 + permanent authorization for you to choose that version for the 165 + Library.
+221
src/libinfo/darling-resolver/resolver.c
··· 1 + /* 2 + * Darling - DNS resolver module 3 + * Copyright (c) 2015 Lubos Dolezel, All rights reserved. 4 + * 5 + * This library is free software; you can redistribute it and/or 6 + * modify it under the terms of the GNU Lesser General Public 7 + * License as published by the Free Software Foundation; either 8 + * version 3.0 of the License, or (at your option) any later version. 9 + * 10 + * This library is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 + * Lesser General Public License for more details. 14 + * 15 + * You should have received a copy of the GNU Lesser General Public 16 + * License along with this library. 17 + */ 18 + 19 + #include "../lookup.subproj/si_module.h" 20 + #include <dispatch/dispatch.h> 21 + #include <resolv.h> 22 + #include <stdio.h> 23 + 24 + static int 25 + dr_is_valid(si_mod_t *si, si_item_t *item) 26 + { 27 + return 0; 28 + } 29 + 30 + static void 31 + dr_close(si_mod_t *si) 32 + { 33 + } 34 + 35 + static si_item_t * 36 + dr_hostbyname(si_mod_t *si, const char *name, int af, const char *interface, uint32_t *err) 37 + { 38 + int type, l, i, elem_length; 39 + unsigned char buf[4096]; 40 + ns_msg msg; 41 + ns_rr rr; 42 + char* addr_buf; 43 + void** addr_ptrs; 44 + uint64_t ttl_end; 45 + 46 + if (af == AF_INET) 47 + { 48 + elem_length = 4; 49 + type = ns_t_a; 50 + } 51 + else if (af == AF_INET6) 52 + { 53 + elem_length = 16; 54 + type = ns_t_aaaa; 55 + } 56 + else 57 + return NULL; 58 + 59 + l = res_query(name, ns_c_any, type, buf, sizeof(buf)); 60 + if (l < 0) 61 + return NULL; 62 + 63 + ns_initparse(buf, l, &msg); 64 + l = ns_msg_count(msg, ns_s_an); 65 + 66 + addr_buf = (char*) __builtin_alloca(l * elem_length); 67 + addr_ptrs = (void**) __builtin_alloca((l+1) * sizeof(void*)); 68 + addr_ptrs[l] = NULL; 69 + 70 + for (i = 0; i < l; i++) 71 + { 72 + const unsigned char* data; 73 + int type; 74 + 75 + ns_parserr(&msg, ns_s_an, i, &rr); 76 + data = ns_rr_rdata(rr); 77 + type = ns_rr_type(rr); 78 + 79 + if ((af == AF_INET && type == ns_t_a) 80 + || (af == AF_INET6 && type == ns_t_aaaa)) 81 + { 82 + memcpy(addr_buf + (i*elem_length), data, elem_length); 83 + addr_ptrs[i] = addr_buf + (i*elem_length); 84 + } 85 + } 86 + 87 + ttl_end = time(NULL) + rr.ttl; 88 + if (af == AF_INET) 89 + { 90 + return (si_item_t *)LI_ils_create("L4488s*44a", (unsigned long)si, CATEGORY_HOST_IPV4, 1, ttl_end, 91 + 0LL, name, NULL, af, elem_length, addr_ptrs); 92 + } 93 + else if (af == AF_INET6) 94 + { 95 + return (si_item_t *)LI_ils_create("L4488s*44c", (unsigned long)si, CATEGORY_HOST_IPV6, 1, ttl_end, 96 + 0LL, name, NULL, af, elem_length, addr_ptrs); 97 + } 98 + return NULL; 99 + } 100 + 101 + static si_item_t * 102 + dr_hostbyaddr(si_mod_t *si, const void *addr, int af, const char *interface, uint32_t *err) 103 + { 104 + char ptr[100]; 105 + unsigned char buf[4096]; 106 + int l, i; 107 + ns_msg msg; 108 + ns_rr rr; 109 + char** name_ptrs; 110 + 111 + if (af == AF_INET) 112 + { 113 + const unsigned char* ip = (const unsigned char*) addr; 114 + sprintf(ptr, "%d.%d.%d.%d.in-addr.arpa", ip[3], ip[2], ip[1], ip[0]); 115 + } 116 + else if (af == AF_INET6) 117 + { 118 + if (memcmp(addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12) == 0) 119 + { 120 + // This is a mapped IPv4 address 121 + const unsigned char* ip = ((const unsigned char*) addr) + 12; 122 + sprintf(ptr, "%d.%d.%d.%d.in-addr.arpa", ip[3], ip[2], ip[1], ip[0]); 123 + } 124 + else 125 + { 126 + const unsigned char* ip = (const unsigned char*) addr; 127 + const char* dig = "0123456789abcdef"; 128 + int i; 129 + 130 + for (i = 0; i < 16; i++) 131 + { 132 + ptr[i*4] = dig[ip[i] & 0xf]; 133 + ptr[i*4+1] = '.'; 134 + ptr[i*4+2] = dig[ip[i] >> 4]; 135 + ptr[i*4+3] = '.'; 136 + } 137 + strcpy(&ptr[64], "ip6.arpa"); 138 + } 139 + } 140 + else 141 + return NULL; 142 + 143 + l = res_query(ptr, ns_c_any, ns_t_ptr, buf, sizeof(buf)); 144 + if (l < 0) 145 + return NULL; 146 + 147 + ns_initparse(buf, l, &msg); 148 + l = ns_msg_count(msg, ns_s_an); 149 + 150 + name_ptrs = (char**) __builtin_alloca((l+1) * sizeof(char*)); 151 + name_ptrs[l] = NULL; 152 + 153 + for (i = 0; i < l; i++) 154 + { 155 + const unsigned char* data; 156 + int type; 157 + 158 + ns_parserr(&msg, ns_s_an, i, &rr); 159 + data = ns_rr_rdata(rr); 160 + type = ns_rr_type(rr); 161 + 162 + if (type == ns_t_ptr) 163 + { 164 + // TODO 165 + } 166 + } 167 + 168 + return NULL; 169 + } 170 + 171 + static si_list_t * 172 + 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) 173 + { 174 + return NULL; 175 + } 176 + 177 + static si_item_t * 178 + 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) 179 + { 180 + return NULL; 181 + } 182 + 183 + static si_list_t * 184 + dr_srv_byname(si_mod_t* si, const char *qname, const char *interface, uint32_t *err) 185 + { 186 + return NULL; 187 + } 188 + 189 + si_mod_t *si_module_static_darling(void) 190 + { 191 + static const struct si_mod_vtable_s dr_vtable = 192 + { 193 + .sim_close = &dr_close, 194 + .sim_is_valid = &dr_is_valid, 195 + .sim_host_byname = &dr_hostbyname, 196 + .sim_host_byaddr = &dr_hostbyaddr, 197 + .sim_item_call = &dr_item_call, 198 + .sim_addrinfo = &dr_addrinfo, 199 + .sim_srv_byname = &dr_srv_byname, 200 + }; 201 + 202 + static si_mod_t si = 203 + { 204 + .vers = 1, 205 + .refcount = 1, 206 + .flags = SI_MOD_FLAG_STATIC, 207 + 208 + .private = NULL, 209 + .vtable = &dr_vtable, 210 + }; 211 + 212 + static dispatch_once_t once; 213 + 214 + dispatch_once(&once, ^{ 215 + si.name = strdup("darling-resolver"); 216 + }); 217 + 218 + return (si_mod_t*)&si; 219 + 220 + } 221 +
+3
src/libinfo/dns.subproj/res_query.c
··· 1 + // Modified by Lubos Dolezel for Darling 1 2 /* 2 3 * Copyright (c) 1999, 2012 Apple Inc. All rights reserved. 3 4 * ··· 44 45 #endif 45 46 char _res[RES_9_STATE_SIZE] = {0}; 46 47 48 + #ifndef DARLING 47 49 int 48 50 res_init(void) 49 51 { ··· 128 130 { 129 131 return _mdns_query(SI_CALL_DNS_SEARCH, name, class, type, answer, anslen); 130 132 } 133 + #endif
+2 -1
src/libinfo/lookup.subproj/search_module.c
··· 955 955 #ifdef DS_AVAILABLE 956 956 "ds", 957 957 #endif 958 - "mdns", 958 + // "mdns", 959 + "darling-resolver", 959 960 "file", 960 961 }; 961 962
+3 -1
src/libinfo/lookup.subproj/si_module.c
··· 83 83 si_mod_t *si_module_static_ds(void); 84 84 #endif 85 85 si_mod_t *si_module_static_mdns(void); 86 + si_mod_t *si_module_static_darling(void); 86 87 87 88 static void * 88 89 si_mod_dlsym(void *so, const char *name, const char *sym) ··· 182 183 #ifdef DS_AVAILABLE 183 184 { "ds", si_module_static_ds, NULL }, 184 185 #endif 185 - { "mdns", si_module_static_mdns, NULL }, 186 + // { "mdns", si_module_static_mdns, NULL }, 187 + { "darling-resolver", si_module_static_darling, NULL }, 186 188 { NULL, NULL }, 187 189 }; 188 190
+1
src/libinfo/lookup.subproj/si_module.h
··· 1 + // Modified by Lubos Dolezel for Darling 1 2 /* 2 3 * Copyright (c) 2008-2011 Apple Inc. All rights reserved. 3 4 *