1 /* 2 * Copyright (c) 2015-2020 Apple Inc. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _DNS_SD_PRIVATE_H 18 #define _DNS_SD_PRIVATE_H 19 20 #include <dns_sd.h> 21 22 #if !defined(DNS_SD_EXCLUDE_PRIVATE_API) 23 #if defined(__APPLE__) 24 #define DNS_SD_EXCLUDE_PRIVATE_API 0 25 #else 26 #define DNS_SD_EXCLUDE_PRIVATE_API 1 27 #endif 28 #endif 29 30 // Private flags (kDNSServiceFlagsPrivateOne, kDNSServiceFlagsPrivateTwo, kDNSServiceFlagsPrivateThree, kDNSServiceFlagsPrivateFour, kDNSServiceFlagsPrivateFive) from dns_sd.h 31 enum 32 { 33 kDNSServiceFlagsDenyConstrained = 0x2000, 34 /* 35 * This flag is meaningful only for Unicast DNS queries. When set, the daemon will restrict 36 * DNS resolutions on interfaces defined as constrained for that request. 37 */ 38 39 kDNSServiceFlagsDenyCellular = 0x8000000, 40 /* 41 * This flag is meaningful only for Unicast DNS queries. When set, the daemon will restrict 42 * DNS resolutions on the cellular interface for that request. 43 */ 44 kDNSServiceFlagsServiceIndex = 0x10000000, 45 /* 46 * This flag is meaningful only for DNSServiceGetAddrInfo() for Unicast DNS queries. 47 * When set, DNSServiceGetAddrInfo() will interpret the "interfaceIndex" argument of the call 48 * as the "serviceIndex". 49 */ 50 51 kDNSServiceFlagsDenyExpensive = 0x20000000, 52 /* 53 * This flag is meaningful only for Unicast DNS queries. When set, the daemon will restrict 54 * DNS resolutions on interfaces defined as expensive for that request. 55 */ 56 57 kDNSServiceFlagsPathEvaluationDone = 0x40000000 58 /* 59 * This flag is meaningful for only Unicast DNS queries. 60 * When set, it indicates that Network PathEvaluation has already been performed. 61 */ 62 }; 63 64 #if !DNS_SD_EXCLUDE_PRIVATE_API 65 /* DNSServiceCreateDelegateConnection() 66 * 67 * Parameters: 68 * 69 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating 70 * the reference (via DNSServiceRefDeallocate()) severs the 71 * connection and deregisters all records registered on this connection. 72 * 73 * pid : Process ID of the delegate 74 * 75 * uuid: UUID of the delegate 76 * 77 * Note that only one of the two arguments (pid or uuid) can be specified. If pid 78 * is zero, uuid will be assumed to be a valid value; otherwise pid will be used. 79 * 80 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns 81 * an error code indicating the specific failure that occurred (in which 82 * case the DNSServiceRef is not initialized). kDNSServiceErr_NotAuth is 83 * returned to indicate that the calling process does not have entitlements 84 * to use this API. 85 */ 86 DNSSD_EXPORT 87 DNSServiceErrorType DNSSD_API DNSServiceCreateDelegateConnection(DNSServiceRef *sdRef, int32_t pid, uuid_t uuid); 88 89 // Map the source port of the local UDP socket that was opened for sending the DNS query 90 // to the process ID of the application that triggered the DNS resolution. 91 // 92 /* DNSServiceGetPID() Parameters: 93 * 94 * srcport: Source port (in network byte order) of the UDP socket that was created by 95 * the daemon to send the DNS query on the wire. 96 * 97 * pid: Process ID of the application that started the name resolution which triggered 98 * the daemon to send the query on the wire. The value can be -1 if the srcport 99 * cannot be mapped. 100 * 101 * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning 102 * if the daemon is not running. The value of the pid is undefined if the return 103 * value has error. 104 */ 105 DNSSD_EXPORT 106 DNSServiceErrorType DNSSD_API DNSServiceGetPID 107 ( 108 uint16_t srcport, 109 int32_t *pid 110 ); 111 112 DNSSD_EXPORT 113 DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser(DNSServiceFlags flags, const char *domain); 114 115 SPI_AVAILABLE(macos(10.15.4), ios(13.2.2), watchos(6.2), tvos(13.2)) 116 DNSServiceErrorType DNSSD_API DNSServiceSleepKeepalive_sockaddr 117 ( 118 DNSServiceRef * sdRef, 119 DNSServiceFlags flags, 120 const struct sockaddr * localAddr, 121 const struct sockaddr * remoteAddr, 122 unsigned int timeout, 123 DNSServiceSleepKeepaliveReply callBack, 124 void * context 125 ); 126 127 /*! 128 * @brief 129 * Sets the default DNS resolver settings for the caller's process. 130 * 131 * @param plist_data_ptr 132 * Pointer to an nw_resolver_config's binary property list data. 133 * 134 * @param plist_data_len 135 * Byte-length of the binary property list data. Ignored if plist_data_ptr is NULL. 136 * 137 * @param require_encryption 138 * Pass true if the process requires that DNS queries use an encrypted DNS service, such as DNS over HTTPS. 139 * 140 * @result 141 * This function returns kDNSServiceErr_NoError on success, kDNSServiceErr_Invalid if plist_data_len 142 * exceeds 32,768, and kDNSServiceErr_NoMemory if it fails to allocate memory. 143 * 144 * @discussion 145 * These settings only apply to the calling process's DNSServiceGetAddrInfo and DNSServiceQueryRecord 146 * requests. This function exists for code that may still use the legacy DNS-SD API for resolving 147 * hostnames, i.e., it implements the functionality of dnssd_getaddrinfo_set_need_encrypted_query(), but at 148 * a process-wide level of granularity. 149 * 150 * Due to underlying IPC limitations, there's currently a 32 KB limit on the size of the binary property 151 * list data. 152 */ 153 SPI_AVAILABLE(macos(10.16), ios(14.0), watchos(7.0), tvos(14.0)) 154 DNSServiceErrorType DNSSD_API DNSServiceSetResolverDefaults(const void *plist_data_ptr, size_t plist_data_len, 155 bool require_encryption); 156 #endif // !DNS_SD_EXCLUDE_PRIVATE_API 157 158 #define kDNSServiceCompPrivateDNS "PrivateDNS" 159 #define kDNSServiceCompMulticastDNS "MulticastDNS" 160 161 #endif // _DNS_SD_PRIVATE_H 162