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