peachsim 0.1.1738 → 0.1.1744

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.
Files changed (327) hide show
  1. package/README.md +4 -0
  2. package/cli/app-catalog.ts +47 -23
  3. package/cli/app-fonts.ts +19 -1
  4. package/cli/command-registry.ts +3 -0
  5. package/cli/commands/control.ts +67 -16
  6. package/cli/commands/device.ts +3 -1
  7. package/cli/commands/doctor.ts +1 -4
  8. package/cli/commands/inspect/settling.ts +6 -1
  9. package/cli/commands/inspect/wait-ready.ts +22 -2
  10. package/cli/commands/package.ts +22 -20
  11. package/cli/commands/push.ts +56 -0
  12. package/cli/commands/serve.ts +9 -0
  13. package/cli/commands/shell-url.ts +37 -9
  14. package/cli/commands/swift.ts +1 -1
  15. package/cli/current-sim.ts +27 -0
  16. package/cli/drivers/linux-browser-libs.lock.json +323 -1
  17. package/cli/drivers/linux-browser-libs.ts +8 -6
  18. package/cli/drivers/playwright.ts +5 -1
  19. package/cli/internal-child.ts +11 -1
  20. package/cli/main.ts +6 -0
  21. package/cli/native-input.ts +1 -7
  22. package/cli/outbound-endpoints.ts +9 -1
  23. package/cli/packaged-app-launcher.ts +3 -1
  24. package/cli/scene-video.ts +4 -0
  25. package/cli/ws-bridge.ts +3 -1
  26. package/detox/index.ts +9 -4
  27. package/dist-lib/agent-daemon-client.cjs +1 -1
  28. package/dist-lib/agent-events.cjs +1 -1
  29. package/dist-lib/attached-projects.cjs +1 -1
  30. package/dist-lib/auth/shared-session.cjs +1 -1
  31. package/dist-lib/backend-origin.cjs +1 -1
  32. package/dist-lib/beta.cjs +1 -1
  33. package/dist-lib/beta.mjs +1 -1
  34. package/dist-lib/bridge-constants.cjs +1 -1
  35. package/dist-lib/bridge-contract-input.cjs +1 -1
  36. package/dist-lib/bridge-contract-input.mjs +1 -1
  37. package/dist-lib/bridge-contract.cjs +1 -1
  38. package/dist-lib/bridge-contract.mjs +1 -1
  39. package/dist-lib/bundle-channel.cjs +7372 -3675
  40. package/dist-lib/capture-contract.cjs +1 -1
  41. package/dist-lib/capture-contract.mjs +1 -1
  42. package/dist-lib/cloud-contract.cjs +1 -1
  43. package/dist-lib/cloud-contract.mjs +1 -1
  44. package/dist-lib/cloud-test-args.cjs +1 -1
  45. package/dist-lib/cloud-test-args.mjs +1 -1
  46. package/dist-lib/cloud.cjs +1 -1
  47. package/dist-lib/cloud.mjs +1 -1
  48. package/dist-lib/config.cjs +1 -1
  49. package/dist-lib/config.mjs +1 -1
  50. package/dist-lib/detox/index.cjs +22 -8
  51. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  52. package/dist-lib/expo-swift-bundle.cjs +6340 -3064
  53. package/dist-lib/expo-swift-metadata.cjs +14 -2
  54. package/dist-lib/expo-swift-metadata.mjs +14 -2
  55. package/dist-lib/home-paths.cjs +1 -1
  56. package/dist-lib/host/bridge-host.cjs +6524 -2720
  57. package/dist-lib/host/fetch-proxy-handler.cjs +8 -7
  58. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  59. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  60. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  61. package/dist-lib/host/websocket-proxy.cjs +6 -3
  62. package/dist-lib/index.cjs +97 -31
  63. package/dist-lib/jump-to-source-babel.cjs +1 -1
  64. package/dist-lib/jump-to-source-native.cjs +1 -1
  65. package/dist-lib/kotlin-host.cjs +1 -1
  66. package/dist-lib/menu.cjs +1 -1
  67. package/dist-lib/menu.mjs +1 -1
  68. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  69. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  70. package/dist-lib/metro-production-bundle.cjs +1 -1
  71. package/dist-lib/metro-production-bundle.mjs +1 -1
  72. package/dist-lib/metro.cjs +71 -29
  73. package/dist-lib/native-app-identity-project.cjs +53 -22
  74. package/dist-lib/native-app-identity-project.mjs +53 -22
  75. package/dist-lib/native-app-identity.cjs +10 -3
  76. package/dist-lib/native-app-identity.mjs +10 -3
  77. package/dist-lib/native-firebase-metadata.cjs +1 -1
  78. package/dist-lib/native-firebase-metadata.mjs +1 -1
  79. package/dist-lib/plist.cjs +1 -1
  80. package/dist-lib/plist.mjs +1 -1
  81. package/dist-lib/profiles.cjs +1 -1
  82. package/dist-lib/public-brand.cjs +1 -1
  83. package/dist-lib/public-origins-lib-esm.json +25 -23
  84. package/dist-lib/public-origins-lib.json +111 -79
  85. package/dist-lib/react-native-host-modules.cjs +1 -1
  86. package/dist-lib/react-native-host-modules.mjs +1 -1
  87. package/dist-lib/reap-browser.cjs +1 -1
  88. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  89. package/dist-lib/sdk.cjs +4 -1
  90. package/dist-lib/sdk.mjs +4 -1
  91. package/dist-lib/skills.cjs +40549 -37613
  92. package/dist-lib/swift-compile.cjs +2054 -388
  93. package/dist-lib/swift-compile.mjs +1976 -312
  94. package/dist-lib/swift-package.cjs +1 -1
  95. package/dist-lib/swift-package.mjs +1 -1
  96. package/dist-lib/swift-submit.cjs +2 -2
  97. package/dist-lib/swift-submit.mjs +2 -2
  98. package/dist-lib/swift-toolchain.cjs +68 -8
  99. package/dist-lib/swift.cjs +1 -1
  100. package/dist-lib/vite-swift.cjs +5867 -2646
  101. package/dist-lib/vite.cjs +18 -8
  102. package/dist-lib/worklet-executable.cjs +1 -1
  103. package/dist-lib/worklet-executable.mjs +1 -1
  104. package/dist-types/packages/peach-compat/src/stubs/screen-transition-math.d.ts +1 -0
  105. package/dist-types/packages/peach-engine/src/cli-companion.d.ts +1 -0
  106. package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +2 -0
  107. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +0 -3
  108. package/dist-types/packages/peach-engine/src/engine/node.d.ts +6 -0
  109. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +1 -0
  110. package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +25 -3
  111. package/dist-types/packages/peach-engine/src/engine/scroll-platform.d.ts +1 -15
  112. package/dist-types/packages/peach-engine/src/engine/scroll.d.ts +1 -3
  113. package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +1 -0
  114. package/dist-types/packages/peach-engine/src/engine/types.d.ts +23 -0
  115. package/dist-types/packages/peach-engine/src/ios/chrome-metrics.d.ts +6 -0
  116. package/dist-types/packages/peach-engine/src/metro-identity-contract.d.ts +33 -0
  117. package/dist-types/packages/peach-engine/src/preview/bundle-layout.d.ts +1 -1
  118. package/dist-types/packages/peach-engine/src/remote-stream/scene-recording.d.ts +2 -0
  119. package/dist-types/packages/peach-engine/src/render-worker/compositor-gpu.d.ts +1 -1
  120. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +2 -0
  121. package/dist-types/packages/peach-engine/src/render-worker/metro-bundle-metadata.d.ts +28 -0
  122. package/dist-types/packages/peach-engine/src/render-worker/native-ui-protocol.d.ts +21 -1
  123. package/dist-types/packages/peach-engine/src/render-worker/prepared-boot-bundle.d.ts +7 -0
  124. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +8 -0
  125. package/dist-types/packages/peach-engine/src/render-worker/scroll-mirror.d.ts +1 -0
  126. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +5 -0
  127. package/dist-types/packages/peach-engine/src/render-worker/test-bridge-protocol.d.ts +3 -3
  128. package/dist-types/packages/peach-engine/src/render-worker/webgpu-frame-transaction.d.ts +1 -0
  129. package/dist-types/packages/peach-engine/src/render-worker/webgpu-readback-scheduler.d.ts +1 -1
  130. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +1 -0
  131. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +8 -1
  132. package/dist-types/packages/peach-engine/src/rolldown-production-fingerprint.d.ts +1 -4
  133. package/dist-types/packages/peach-engine/src/rolldown-production-module.d.ts +12 -0
  134. package/dist-types/packages/peach-engine/src/rolldown-production-roles.d.ts +6 -0
  135. package/dist-types/packages/peach-engine/src/settings/devices.d.ts +6 -1
  136. package/dist-types/packages/peach-engine/src/settings/duo-fold-bus.d.ts +1 -0
  137. package/dist-types/packages/peach-engine/src/shell-events.d.ts +4 -0
  138. package/dist-types/packages/peach-kit/src/capabilities.d.ts +7 -0
  139. package/package.json +2 -1
  140. package/runtime-companion.json +1 -1
  141. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +1 -0
  142. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkErrors.h +257 -0
  143. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFByteOrder.h +305 -0
  144. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +2 -0
  145. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGAffineTransform.h +204 -0
  146. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h +260 -0
  147. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGColor.h +164 -0
  148. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGColorConversionInfo.h +101 -0
  149. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGColorSpace.h +510 -0
  150. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGContext.h +1132 -0
  151. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGConvertColorDataWithFormat.h +34 -0
  152. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDataConsumer.h +83 -0
  153. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDataProvider.h +197 -0
  154. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGEXRToneMappingGamma.h +36 -0
  155. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGError.h +38 -0
  156. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGFont.h +312 -0
  157. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGFunction.h +106 -0
  158. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGGradient.h +123 -0
  159. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGITUToneMapping.h +31 -0
  160. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGImage.h +409 -0
  161. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGLayer.h +78 -0
  162. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFArray.h +120 -0
  163. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFContentStream.h +55 -0
  164. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFContext.h +535 -0
  165. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFDictionary.h +133 -0
  166. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFDocument.h +252 -0
  167. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFMarkedContentItem.h +37 -0
  168. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFObject.h +67 -0
  169. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFOperatorTable.h +51 -0
  170. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFPage.h +101 -0
  171. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFScanner.h +123 -0
  172. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFStream.h +44 -0
  173. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFString.h +52 -0
  174. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFStructureElement.h +87 -0
  175. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPath.h +441 -0
  176. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPattern.h +89 -0
  177. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGRenderingBufferProvider.h +49 -0
  178. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGShading.h +124 -0
  179. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGToneMapping.h +85 -0
  180. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +44 -252
  181. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Modules/module.modulemap +1 -0
  182. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/CFNetworkErrors.h +257 -0
  183. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +0 -6
  184. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +356 -61
  185. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/NSURLSession+Network.h +32 -0
  186. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/Network.h +51 -0
  187. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/advertise_descriptor.h +193 -0
  188. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/browse_descriptor.h +163 -0
  189. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/browse_result.h +207 -0
  190. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/browser.h +285 -0
  191. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/connection.h +714 -0
  192. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/connection_group.h +629 -0
  193. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/connection_report.h +932 -0
  194. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/content_context.h +229 -0
  195. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/endpoint.h +390 -0
  196. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/error.h +135 -0
  197. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/ethernet_channel.h +349 -0
  198. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/framer_options.h +1187 -0
  199. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/group_descriptor.h +184 -0
  200. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/interface.h +150 -0
  201. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/ip_options.h +351 -0
  202. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/listener.h +438 -0
  203. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/nw_object.h +200 -0
  204. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/parameters.h +1205 -0
  205. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/path.h +392 -0
  206. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/path_monitor.h +216 -0
  207. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/privacy_context.h +188 -0
  208. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/protocol_options.h +126 -0
  209. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/proxy_config.h +357 -0
  210. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/quic_options.h +889 -0
  211. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/resolver_config.h +94 -0
  212. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/tcp_options.h +459 -0
  213. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/tls_options.h +115 -0
  214. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/txt_record.h +432 -0
  215. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/udp_options.h +112 -0
  216. package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/ws_options.h +743 -0
  217. package/sdk/ios/System/Library/Frameworks/Network.framework/Modules/module.modulemap +9 -0
  218. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAAnimation.h +395 -0
  219. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CABase.h +132 -0
  220. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CADisplayLink.h +107 -0
  221. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAEmitterCell.h +153 -0
  222. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAEmitterLayer.h +151 -0
  223. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAFrameRateRange.h +40 -0
  224. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAGradientLayer.h +78 -0
  225. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CALayer.h +1078 -0
  226. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAMediaTiming.h +97 -0
  227. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAMediaTimingFunction.h +67 -0
  228. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAReplicatorLayer.h +65 -0
  229. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAScrollLayer.h +64 -0
  230. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAShapeLayer.h +135 -0
  231. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATextLayer.h +99 -0
  232. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATiledLayer.h +67 -0
  233. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATransaction.h +124 -0
  234. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATransform3D.h +138 -0
  235. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATransformLayer.h +40 -0
  236. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAValueFunction.h +78 -0
  237. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.h +19 -38
  238. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecureTransport.h +1757 -0
  239. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/NSAttributedString.h +19 -0
  240. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/NSParagraphStyle.h +28 -0
  241. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAccessibilityConstants.h +114 -0
  242. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +16 -0
  243. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBarAppearance.h +47 -0
  244. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDataDetectors.h +20 -0
  245. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDatePicker.h +13 -0
  246. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDevice.h +16 -0
  247. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIEvent.h +84 -0
  248. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIGestureRecognizer.h +119 -0
  249. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIGestureRecognizerSubclass.h +66 -0
  250. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIHoverGestureRecognizer.h +45 -0
  251. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +161 -37
  252. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIPickerView.h +76 -0
  253. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITabBar.h +8 -0
  254. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITabBarAppearance.h +78 -0
  255. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITextInputTraits.h +29 -0
  256. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITouch.h +104 -0
  257. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITraitCollection.h +19 -0
  258. package/sdk/ios/usr/include/dns_sd.h +3616 -0
  259. package/sdk/ios/usr/include/dnssd.modulemap +4 -0
  260. package/sdk/ios/usr/include/module.modulemap +1 -0
  261. package/sdk/ios/usr/include/sys/socketvar.h +191 -0
  262. package/sdk/ios/usr/include/sys/vsock.h +84 -0
  263. package/sdk/native-hashes.json +1 -1
  264. package/skills/contrast/SKILL.md +6 -5
  265. package/skills/peach-debug/SKILL.md +68 -264
  266. package/skills/peach-debug/references/accessibility.md +37 -73
  267. package/skills/peach-debug/references/commands.md +2 -2
  268. package/skills/peach-debug/references/events.md +74 -0
  269. package/skills/peach-perf/SKILL.md +64 -401
  270. package/skills/peach-perf/references/presentation.md +46 -0
  271. package/skills/peach-perf/references/profiling.md +93 -0
  272. package/skills/peach-perf/references/render-counters.md +57 -0
  273. package/skills/peach-setup/SKILL.md +66 -216
  274. package/skills/peach-setup/references/native-config.md +35 -0
  275. package/skills/peach-setup/references/reporting.md +28 -0
  276. package/skills/peach-test/SKILL.md +68 -284
  277. package/skills/peach-test/references/detox.md +69 -0
  278. package/skills/peach-test/references/maestro.md +95 -0
  279. package/skills/peach-visual/SKILL.md +53 -105
  280. package/src/appPackageContract.ts +12 -1
  281. package/src/assetCatalogContract.ts +8 -1
  282. package/src/bridge-contract.ts +6 -0
  283. package/src/bundle-channel.mjs +133 -59
  284. package/src/cli-runtime.ts +8 -9
  285. package/src/configured-bundle-producer.ts +10 -0
  286. package/src/device-catalog.ts +68 -4
  287. package/src/expo-discovery-cache.ts +3 -0
  288. package/src/expo-native-workspace.ts +81 -17
  289. package/src/expo-swift-host.ts +57 -104
  290. package/src/expo-widget-assets.ts +76 -0
  291. package/src/expoSwiftContract.ts +13 -1
  292. package/src/host/websocket-proxy.ts +7 -2
  293. package/src/native-prebuilt.ts +3 -3
  294. package/src/nitro-adapter.lock.json +263 -263
  295. package/src/nitro-adapter.ts +69 -7
  296. package/src/nitro-bundle.ts +52 -24
  297. package/src/nitro-compile.ts +6 -1
  298. package/src/nitro-source.ts +82 -4
  299. package/src/nitro-superset.lock.json +103 -0
  300. package/src/nitro-superset.ts +137 -0
  301. package/src/nitroContract.ts +5 -1
  302. package/src/react-bridge-importers.ts +1 -0
  303. package/src/settingsContract.ts +26 -1
  304. package/src/swift-compile.ts +267 -68
  305. package/src/swift-compiler-digest.ts +2 -0
  306. package/src/swift-coverage/xcode-packages.ts +61 -1
  307. package/src/swift-coverage/xcode.ts +10 -12
  308. package/src/swift-cxx-reachable.ts +1 -1
  309. package/src/swift-distribution.lock.json +15 -13
  310. package/src/swift-distribution.ts +57 -26
  311. package/src/swift-host.ts +48 -35
  312. package/src/swift-link-roots.ts +45 -18
  313. package/src/swift-objc-compile.ts +78 -2
  314. package/src/swift-objc-standin.ts +3 -0
  315. package/src/swift-shared-sdk.ts +85 -1
  316. package/src/swift-standins.ts +233 -11
  317. package/src/swift-submit.ts +13 -1
  318. package/src/swift-toolchain.ts +82 -7
  319. package/src/swift-wasm-prune.ts +1629 -0
  320. package/src/turbo-bundle.ts +11 -10
  321. package/src/turbo-runtime.lock.json +16 -16
  322. package/src/vite-plugin-one.ts +12 -1
  323. package/src/vite-plugin.ts +82 -23
  324. package/src/wasm-optimize.ts +34 -0
  325. package/src/worker-system-chunks.ts +3 -3
  326. package/src/xcode-project.ts +52 -0
  327. package/src/xcode-target-members.ts +12 -1
@@ -0,0 +1,3616 @@
1
+ /* -*- Mode: C; tab-width: 4 -*-
2
+ *
3
+ * Copyright (c) 2003-2025 Apple Inc. All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice,
9
+ * this list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the documentation
12
+ * and/or other materials provided with the distribution.
13
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of its
14
+ * contributors may be used to endorse or promote products derived from this
15
+ * software without specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+
30
+ /*! @header DNS Service Discovery
31
+ *
32
+ * @discussion This section describes the functions, callbacks, and data structures
33
+ * that make up the DNS Service Discovery API.
34
+ *
35
+ * The DNS Service Discovery API is part of Bonjour, Apple's implementation
36
+ * of zero-configuration networking (ZEROCONF).
37
+ *
38
+ * Bonjour allows you to register a network service, such as a
39
+ * printer or file server, so that it can be found by name or browsed
40
+ * for by service type and domain. Using Bonjour, applications can
41
+ * discover what services are available on the network, along with
42
+ * all the information -- such as name, IP address, and port --
43
+ * necessary to access a particular service.
44
+ *
45
+ * In effect, Bonjour combines the functions of a local DNS server and
46
+ * AppleTalk. Bonjour allows applications to provide user-friendly printer
47
+ * and server browsing, among other things, over standard IP networks.
48
+ * This behavior is a result of combining protocols such as multicast and
49
+ * DNS to add new functionality to the network (such as multicast DNS).
50
+ *
51
+ * Bonjour gives applications easy access to services over local IP
52
+ * networks without requiring the service or the application to support
53
+ * an AppleTalk or a Netbeui stack, and without requiring a DNS server
54
+ * for the local network.
55
+ */
56
+
57
+ /* _DNS_SD_H contains the API version number for this header file
58
+ * The API version defined in this header file symbol allows for compile-time
59
+ * checking, so that C code building with earlier versions of the header file
60
+ * can avoid compile errors trying to use functions that aren't even defined
61
+ * in those earlier versions. Similar checks may also be performed at run-time:
62
+ * => weak linking -- to avoid link failures if run with an earlier
63
+ * version of the library that's missing some desired symbol, or
64
+ * => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon
65
+ * ("system service" on Windows) meets some required minimum functionality level.
66
+ */
67
+
68
+ #ifndef _DNS_SD_H
69
+ #define _DNS_SD_H 3111000005
70
+
71
+ /* DNS-SD API version strings are of the form x[.y[.z]].
72
+ * Version strings less than or equal to 1661 are encoded as (x * 10000) + (y * 100) + z, where 0 ≤ y,z ≤ 99.
73
+ * Version strings greater than 1661 are encoded as (x * 1000000) + (y * 1000) + z, where 0 ≤ y,z ≤ 999.
74
+ * Therefore, the greatest version number for the original encoding is 16610000.
75
+ */
76
+ #define DNS_SD_ORIGINAL_ENCODING_VERSION_NUMBER_MAX 16610000
77
+
78
+ #if !defined(__BEGIN_DECLS)
79
+ #if defined(__cplusplus)
80
+ #define __BEGIN_DECLS extern "C" {
81
+ #define __END_DECLS }
82
+ #else
83
+ #define __BEGIN_DECLS
84
+ #define __END_DECLS
85
+ #endif
86
+ #endif
87
+
88
+ /* Set to 1 if libdispatch is supported
89
+ * Note: May also be set by project and/or Makefile
90
+ */
91
+ #if defined(__APPLE__)
92
+ #define _DNS_SD_LIBDISPATCH 1
93
+ #else
94
+ #define _DNS_SD_LIBDISPATCH 0
95
+ #endif
96
+
97
+ /* standard calling convention under Win32 is __stdcall */
98
+ /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */
99
+ /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */
100
+ #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)
101
+ #define DNSSD_API __stdcall
102
+ #else
103
+ #define DNSSD_API
104
+ #endif
105
+
106
+ #if (defined(__GNUC__) && (__GNUC__ >= 4))
107
+ #define DNSSD_EXPORT __attribute__((visibility("default")))
108
+ #else
109
+ #define DNSSD_EXPORT
110
+ #endif
111
+
112
+ #if defined(_WIN32)
113
+ #include <winsock2.h>
114
+ typedef SOCKET dnssd_sock_t;
115
+ #else
116
+ typedef int dnssd_sock_t;
117
+ #endif
118
+
119
+ /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */
120
+ #if defined(__FreeBSD__) && (__FreeBSD__ < 5)
121
+ #include <sys/types.h>
122
+
123
+ /* Likewise, on Sun, standard integer types are in sys/types.h */
124
+ #elif defined(__sun__)
125
+ #include <sys/types.h>
126
+
127
+ /* EFI does not have stdint.h, or anything else equivalent */
128
+ #elif defined(EFI32) || defined(EFI64) || defined(EFIX64)
129
+ #include "Tiano.h"
130
+ #if !defined(_STDINT_H_)
131
+ typedef UINT8 uint8_t;
132
+ typedef INT8 int8_t;
133
+ typedef UINT16 uint16_t;
134
+ typedef INT16 int16_t;
135
+ typedef UINT32 uint32_t;
136
+ typedef INT32 int32_t;
137
+ #endif
138
+ /* Windows has its own differences */
139
+ #elif defined(_WIN32)
140
+ #include <windows.h>
141
+ #define _UNUSED
142
+ #ifndef _MSL_STDINT_H
143
+ typedef UINT8 uint8_t;
144
+ typedef INT8 int8_t;
145
+ typedef UINT16 uint16_t;
146
+ typedef INT16 int16_t;
147
+ typedef UINT32 uint32_t;
148
+ typedef INT32 int32_t;
149
+ #endif
150
+
151
+ /* All other Posix platforms use stdint.h */
152
+ #else
153
+ #include <stdint.h>
154
+ #endif
155
+
156
+ #if !defined(__has_extension)
157
+ #define __has_extension(X) 0
158
+ #endif
159
+
160
+ #if !defined(__has_feature)
161
+ #define __has_feature(X) 0
162
+ #endif
163
+
164
+ #if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || __has_extension(cxx_strong_enums)
165
+ #define DNS_SERVICE_FLAGS_ENUM enum : uint32_t
166
+ #else
167
+ #define DNS_SERVICE_FLAGS_ENUM enum
168
+ #endif
169
+
170
+ #if _DNS_SD_LIBDISPATCH
171
+ #include <dispatch/dispatch.h>
172
+ #endif
173
+
174
+ #ifndef DNS_SD_NULLABLE
175
+ #if __has_feature(nullability)
176
+ #define DNS_SD_NULLABLE _Nullable
177
+ #define DNS_SD_NONNULL _Nonnull
178
+ #else
179
+ #define DNS_SD_NULLABLE
180
+ #define DNS_SD_NONNULL
181
+ #endif
182
+ #endif
183
+
184
+ __BEGIN_DECLS
185
+
186
+ /* DNSServiceRef, DNSRecordRef
187
+ *
188
+ * Opaque internal data types.
189
+ * Note: client is responsible for serializing access to these structures if
190
+ * they are shared between concurrent threads.
191
+ */
192
+
193
+ typedef struct _DNSServiceRef_t *DNSServiceRef;
194
+ typedef struct _DNSRecordRef_t *DNSRecordRef;
195
+ typedef struct DNSServiceAttribute_s DNSServiceAttribute;
196
+ typedef DNSServiceAttribute *DNSServiceAttributeRef;
197
+
198
+ #if defined(__APPLE__)
199
+ #define DNS_SD_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__)
200
+ #else
201
+ #define DNS_SD_API_AVAILABLE(...) DNSSD_EXPORT
202
+ #endif
203
+ typedef enum
204
+ {
205
+ kDNSServiceAAAAPolicyNone = 0,
206
+ kDNSServiceAAAAPolicyFallback = 1 // If AAAA record doesn't exist, query for A.
207
+ } DNS_SD_API_AVAILABLE(macos(12.0), ios(15.0), tvos(15.0), watchos(8.0)) DNSServiceAAAAPolicy;
208
+
209
+ #ifndef __OPEN_SOURCE__
210
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
211
+ #else
212
+ DNSSD_EXPORT
213
+ #endif
214
+ extern const DNSServiceAttribute kDNSServiceAttributeAAAAFallback;
215
+
216
+ struct sockaddr;
217
+
218
+ /*! @enum General flags
219
+ * Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter.
220
+ * As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning,
221
+ * regardless of the function or callback being used. For any given function or callback,
222
+ * typically only a subset of the possible flags are meaningful, and all others should be zero.
223
+ * The discussion section for each API call describes which flags are valid for that call
224
+ * and callback. In some cases, for a particular call, it may be that no flags are currently
225
+ * defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion.
226
+ * In all cases, developers should expect that in future releases, it is possible that new flag
227
+ * values will be defined, and write code with this in mind. For example, code that tests
228
+ * if (flags == kDNSServiceFlagsAdd) ...
229
+ * will fail if, in a future release, another bit in the 32-bit flags field is also set.
230
+ * The reliable way to test whether a particular bit is set is not with an equality test,
231
+ * but with a bitwise mask:
232
+ * if (flags & kDNSServiceFlagsAdd) ...
233
+ * With the exception of kDNSServiceFlagsValidate, each flag can be valid(be set)
234
+ * EITHER only as an input to one of the DNSService*() APIs OR only as an output
235
+ * (provide status) through any of the callbacks used. For example, kDNSServiceFlagsAdd
236
+ * can be set only as an output in the callback, whereas the kDNSServiceFlagsIncludeP2P
237
+ * can be set only as an input to the DNSService*() APIs. See comments on kDNSServiceFlagsValidate
238
+ * defined in enum below.
239
+ */
240
+
241
+ DNS_SERVICE_FLAGS_ENUM
242
+ {
243
+ kDNSServiceFlagsMoreComing = 0x1,
244
+ /* MoreComing indicates to a callback that at least one more result is
245
+ * queued and will be delivered following immediately after this one.
246
+ * When the MoreComing flag is set, applications should not immediately
247
+ * update their UI, because this can result in a great deal of ugly flickering
248
+ * on the screen, and can waste a great deal of CPU time repeatedly updating
249
+ * the screen with content that is then immediately erased, over and over.
250
+ * Applications should wait until MoreComing is not set, and then
251
+ * update their UI when no more changes are imminent.
252
+ * When MoreComing is not set, that doesn't mean there will be no more
253
+ * answers EVER, just that there are no more answers immediately
254
+ * available right now at this instant. If more answers become available
255
+ * in the future they will be delivered as usual.
256
+ */
257
+
258
+ kDNSServiceFlagsQueueRequest = 0x1,
259
+ /* kDNSServiceFlagsQueueRequest indicates that the request will be queued;
260
+ * otherwise the request is sent immediately.
261
+ * All the queued requests will be sent to server in scatter/gather IO when function
262
+ * DNSServiceSendQueuedRequests is called.
263
+ * This flag is an input value to functions generate requests to server such as
264
+ * DNSServiceRegisterRecord(), which is why we can use the same value as
265
+ * kDNSServiceFlagsMoreComing, which is an output flag for various client callbacks.
266
+ */
267
+
268
+ kDNSServiceFlagsAutoTrigger = 0x1,
269
+ /* Valid for browses using kDNSServiceInterfaceIndexAny.
270
+ * Will auto trigger the browse over AWDL as well once the service is discovered
271
+ * over BLE.
272
+ * This flag is an input value to DNSServiceBrowse(), which is why we can
273
+ * use the same value as kDNSServiceFlagsMoreComing, which is an output flag
274
+ * for various client callbacks.
275
+ */
276
+
277
+ kDNSServiceFlagsAdd = 0x2,
278
+ kDNSServiceFlagsDefault = 0x4,
279
+ /* Flags for domain enumeration and browse/query reply callbacks.
280
+ * "Default" applies only to enumeration and is only valid in
281
+ * conjunction with "Add". An enumeration callback with the "Add"
282
+ * flag NOT set indicates a "Remove", i.e. the domain is no longer
283
+ * valid.
284
+ */
285
+
286
+ kDNSServiceFlagsNoAutoRename = 0x8,
287
+ /* Flag for specifying renaming behavior on name conflict when registering
288
+ * non-shared records. By default, name conflicts are automatically handled
289
+ * by renaming the service. NoAutoRename overrides this behavior - with this
290
+ * flag set, name conflicts will result in a callback. The NoAutorename flag
291
+ * is only valid if a name is explicitly specified when registering a service
292
+ * (i.e. the default name is not used.)
293
+ */
294
+
295
+ kDNSServiceFlagsShared = 0x10,
296
+ kDNSServiceFlagsUnique = 0x20,
297
+ /* Flag for registering individual records on a connected
298
+ * DNSServiceRef. Shared indicates that there may be multiple records
299
+ * with this name on the network (e.g. PTR records). Unique indicates that the
300
+ * record's name is to be unique on the network (e.g. SRV records).
301
+ */
302
+
303
+ kDNSServiceFlagsBrowseDomains = 0x40,
304
+ kDNSServiceFlagsRegistrationDomains = 0x80,
305
+ /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
306
+ * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
307
+ * enumerates domains recommended for registration.
308
+ */
309
+
310
+ kDNSServiceFlagsLongLivedQuery = 0x100,
311
+ /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
312
+
313
+ kDNSServiceFlagsAllowRemoteQuery = 0x200,
314
+ /* Flag for creating a record for which we will answer remote queries
315
+ * (queries from hosts more than one hop away; hosts not directly connected to the local link).
316
+ */
317
+
318
+ kDNSServiceFlagsForceMulticast = 0x400,
319
+ /* Flag for signifying that a query or registration should be performed exclusively via multicast
320
+ * DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
321
+ */
322
+
323
+ kDNSServiceFlagsForce = 0x800, // This flag is deprecated.
324
+
325
+ kDNSServiceFlagsKnownUnique = 0x800,
326
+ /*
327
+ * Client guarantees that record names are unique, so we can skip sending out initial
328
+ * probe messages. Standard name conflict resolution is still done if a conflict is discovered.
329
+ */
330
+
331
+ kDNSServiceFlagsReturnIntermediates = 0x1000,
332
+ /* Flag for returning intermediate results.
333
+ * For example, if a query results in an authoritative NXDomain (name does not exist)
334
+ * then that result is returned to the client. However the query is not implicitly
335
+ * cancelled -- it remains active and if the answer subsequently changes
336
+ * (e.g. because a VPN tunnel is subsequently established) then that positive
337
+ * result will still be returned to the client.
338
+ * Similarly, if a query results in a CNAME record, then in addition to following
339
+ * the CNAME referral, the intermediate CNAME result is also returned to the client.
340
+ * When this flag is not set, NXDomain errors are not returned, and CNAME records
341
+ * are followed silently without informing the client of the intermediate steps.
342
+ * (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME)
343
+ */
344
+
345
+ kDNSServiceFlagsShareConnection = 0x4000,
346
+ /* For efficiency, clients that perform many concurrent operations may want to use a
347
+ * single Unix Domain Socket connection with the background daemon, instead of having a
348
+ * separate connection for each independent operation. To use this mode, clients first
349
+ * call DNSServiceCreateConnection(&SharedRef) to initialize the main DNSServiceRef.
350
+ * For each subsequent operation that is to share that same connection, the client copies
351
+ * the SharedRef, and then passes the address of that copy, setting the ShareConnection flag
352
+ * to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef;
353
+ * it's a copy of an existing DNSServiceRef whose connection information should be reused.
354
+ *
355
+ * For example:
356
+ *
357
+ * DNSServiceErrorType error;
358
+ * DNSServiceRef SharedRef;
359
+ * error = DNSServiceCreateConnection(&SharedRef);
360
+ * if (error) ...
361
+ * DNSServiceRef BrowseRef = SharedRef; // Important: COPY the primary DNSServiceRef first...
362
+ * error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy
363
+ * if (error) ...
364
+ * ...
365
+ * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation
366
+ * DNSServiceRefDeallocate(SharedRef); // Terminate the shared connection
367
+ *
368
+ * Notes:
369
+ *
370
+ * 1. Collective kDNSServiceFlagsMoreComing flag
371
+ * When callbacks are invoked using a shared DNSServiceRef, the
372
+ * kDNSServiceFlagsMoreComing flag applies collectively to *all* active
373
+ * operations sharing the same parent DNSServiceRef. If the MoreComing flag is
374
+ * set it means that there are more results queued on this parent DNSServiceRef,
375
+ * but not necessarily more results for this particular callback function.
376
+ * The implication of this for client programmers is that when a callback
377
+ * is invoked with the MoreComing flag set, the code should update its
378
+ * internal data structures with the new result, and set a variable indicating
379
+ * that its UI needs to be updated. Then, later when a callback is eventually
380
+ * invoked with the MoreComing flag not set, the code should update *all*
381
+ * stale UI elements related to that shared parent DNSServiceRef that need
382
+ * updating, not just the UI elements related to the particular callback
383
+ * that happened to be the last one to be invoked.
384
+ *
385
+ * 2. Canceling operations and kDNSServiceFlagsMoreComing
386
+ * Whenever you cancel any operation for which you had deferred UI updates
387
+ * waiting because of a kDNSServiceFlagsMoreComing flag, you should perform
388
+ * those deferred UI updates. This is because, after cancelling the operation,
389
+ * you can no longer wait for a callback *without* MoreComing set, to tell
390
+ * you do perform your deferred UI updates (the operation has been canceled,
391
+ * so there will be no more callbacks). An implication of the collective
392
+ * kDNSServiceFlagsMoreComing flag for shared connections is that this
393
+ * guideline applies more broadly -- any time you cancel an operation on
394
+ * a shared connection, you should perform all deferred UI updates for all
395
+ * operations sharing that connection. This is because the MoreComing flag
396
+ * might have been referring to events coming for the operation you canceled,
397
+ * which will now not be coming because the operation has been canceled.
398
+ *
399
+ * 3. Only share DNSServiceRef's created with DNSServiceCreateConnection
400
+ * Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef.
401
+ * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve()
402
+ * cannot be shared by copying them and using kDNSServiceFlagsShareConnection.
403
+ *
404
+ * 4. Don't Double-Deallocate
405
+ * Calling DNSServiceRefDeallocate(OpRef) for a particular operation's DNSServiceRef terminates
406
+ * just that operation. Calling DNSServiceRefDeallocate(SharedRef) for the main shared DNSServiceRef
407
+ * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&SharedRef))
408
+ * automatically terminates the shared connection *and* all operations that were still using it.
409
+ * After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's.
410
+ * The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt
411
+ * to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses
412
+ * to freed memory, leading to crashes or other equally undesirable results.
413
+ * You can deallocate individual operations first and then deallocate the parent DNSServiceRef last,
414
+ * but if you deallocate the parent DNSServiceRef first, then all of the subordinate DNSServiceRef's
415
+ * are implicitly deallocated, and explicitly deallocating them a second time will lead to crashes.
416
+ *
417
+ * 5. Thread Safety
418
+ * The dns_sd.h API does not presuppose any particular threading model, and consequently
419
+ * does no locking internally (which would require linking with a specific threading library).
420
+ * If the client concurrently, from multiple threads (or contexts), calls API routines using
421
+ * the same DNSServiceRef, it is the client's responsibility to provide mutual exclusion for
422
+ * that DNSServiceRef.
423
+ *
424
+ * For example, use of DNSServiceRefDeallocate requires caution. A common mistake is as follows:
425
+ * Thread B calls DNSServiceRefDeallocate to deallocate sdRef while Thread A is processing events
426
+ * using sdRef. Doing this will lead to intermittent crashes on thread A if the sdRef is used after
427
+ * it was deallocated.
428
+ *
429
+ * A telltale sign of this crash type is to see DNSServiceProcessResult on the stack preceding the
430
+ * actual crash location.
431
+ *
432
+ * To state this more explicitly, mDNSResponder does not queue DNSServiceRefDeallocate so
433
+ * that it occurs discretely before or after an event is handled.
434
+ */
435
+
436
+ kDNSServiceFlagsSuppressUnusable = 0x8000,
437
+ /*
438
+ * This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the
439
+ * wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
440
+ * but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses
441
+ * for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly,
442
+ * if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for
443
+ * "hostname".
444
+ */
445
+
446
+ kDNSServiceFlagsTimeout = 0x10000,
447
+ /*
448
+ * When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is
449
+ * stopped after a certain number of seconds have elapsed. The time at which the query will be stopped
450
+ * is determined by the system and cannot be configured by the user. The query will be stopped irrespective
451
+ * of whether a response was given earlier or not. When the query is stopped, the callback will be called
452
+ * with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo
453
+ * and zero length rdata will be returned for DNSServiceQueryRecord.
454
+ */
455
+
456
+ kDNSServiceFlagsIncludeP2P = 0x20000,
457
+ /*
458
+ * Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified.
459
+ * By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces.
460
+ */
461
+
462
+ kDNSServiceFlagsWakeOnResolve = 0x40000,
463
+ /*
464
+ * This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet
465
+ * to wake up the client.
466
+ */
467
+
468
+ kDNSServiceFlagsBackgroundTrafficClass = 0x80000,
469
+ /*
470
+ * This flag is meaningful for Unicast DNS queries. When set, it uses the background traffic
471
+ * class for packets that service the request.
472
+ */
473
+
474
+ kDNSServiceFlagsIncludeAWDL = 0x100000,
475
+ /*
476
+ * Include AWDL interface when kDNSServiceInterfaceIndexAny is specified.
477
+ */
478
+
479
+ kDNSServiceFlagsEnableDNSSEC = 0x200000,
480
+ /*
481
+ * Perform DNSSEC validation on the client request when kDNSServiceFlagsEnableDNSSEC is specified
482
+ * Since the client API has not been finalized, we will use it as a temporary flag to turn on the DNSSEC validation.
483
+ */
484
+
485
+ kDNSServiceFlagsValidate = 0x200000,
486
+ /*
487
+ * This flag is meaningful in DNSServiceGetAddrInfo and DNSServiceQueryRecord. This is the ONLY flag to be valid
488
+ * as an input to the APIs and also an output through the callbacks in the APIs.
489
+ *
490
+ * When this flag is passed to DNSServiceQueryRecord and DNSServiceGetAddrInfo to resolve unicast names,
491
+ * the response will be validated using DNSSEC. The validation results are delivered using the flags field in
492
+ * the callback and kDNSServiceFlagsValidate is marked in the flags to indicate that DNSSEC status is also available.
493
+ * When the callback is called to deliver the query results, the validation results may or may not be available.
494
+ * If it is not delivered along with the results, the validation status is delivered when the validation completes.
495
+ *
496
+ * When the validation results are delivered in the callback, it is indicated by marking the flags with
497
+ * kDNSServiceFlagsValidate and kDNSServiceFlagsAdd along with the DNSSEC status flags (described below) and a NULL
498
+ * sockaddr will be returned for DNSServiceGetAddrInfo and zero length rdata will be returned for DNSServiceQueryRecord.
499
+ * DNSSEC validation results are for the whole RRSet and not just individual records delivered in the callback. When
500
+ * kDNSServiceFlagsAdd is not set in the flags, applications should implicitly assume that the DNSSEC status of the
501
+ * RRSet that has been delivered up until that point is not valid anymore, till another callback is called with
502
+ * kDNSServiceFlagsAdd and kDNSServiceFlagsValidate.
503
+ *
504
+ * The following four flags indicate the status of the DNSSEC validation and marked in the flags field of the callback.
505
+ * When any of the four flags is set, kDNSServiceFlagsValidate will also be set. To check the validation status, the
506
+ * other applicable output flags should be masked.
507
+ */
508
+
509
+ kDNSServiceFlagsSecure = 0x200010,
510
+ /*
511
+ * The response has been validated by verifying all the signatures in the response and was able to
512
+ * build a successful authentication chain starting from a known trust anchor.
513
+ */
514
+
515
+ kDNSServiceFlagsInsecure = 0x200020,
516
+ /*
517
+ * A chain of trust cannot be built starting from a known trust anchor to the response.
518
+ */
519
+
520
+ kDNSServiceFlagsBogus = 0x200040,
521
+ /*
522
+ * If the response cannot be verified to be secure due to expired signatures, missing signatures etc.,
523
+ * then the results are considered to be bogus.
524
+ */
525
+
526
+ kDNSServiceFlagsIndeterminate = 0x200080,
527
+ /*
528
+ * There is no valid trust anchor that can be used to determine whether a response is secure or not.
529
+ */
530
+
531
+ kDNSServiceFlagsUnicastResponse = 0x400000,
532
+ /*
533
+ * Request unicast response to query.
534
+ */
535
+ kDNSServiceFlagsValidateOptional = 0x800000,
536
+
537
+ /*
538
+ * This flag is identical to kDNSServiceFlagsValidate except for the case where the response
539
+ * cannot be validated. If this flag is set in DNSServiceQueryRecord or DNSServiceGetAddrInfo,
540
+ * the DNSSEC records will be requested for validation. If they cannot be received for some reason
541
+ * during the validation (e.g., zone is not signed, zone is signed but cannot be traced back to
542
+ * root, recursive server does not understand DNSSEC etc.), then this will fallback to the default
543
+ * behavior where the validation will not be performed and no DNSSEC results will be provided.
544
+ *
545
+ * If the zone is signed and there is a valid path to a known trust anchor configured in the system
546
+ * and the application requires DNSSEC validation irrespective of the DNSSEC awareness in the current
547
+ * network, then this option MUST not be used. This is only intended to be used during the transition
548
+ * period where the different nodes participating in the DNS resolution may not understand DNSSEC or
549
+ * managed properly (e.g. missing DS record) but still want to be able to resolve DNS successfully.
550
+ */
551
+
552
+ kDNSServiceFlagsWakeOnlyService = 0x1000000,
553
+ /*
554
+ * This flag is meaningful only in DNSServiceRegister. When set, the service will not be registered
555
+ * with sleep proxy server during sleep.
556
+ */
557
+
558
+ kDNSServiceFlagsThresholdOne = 0x2000000,
559
+ kDNSServiceFlagsThresholdFinder = 0x4000000,
560
+ kDNSServiceFlagsThresholdReached = kDNSServiceFlagsThresholdOne,
561
+ /*
562
+ * kDNSServiceFlagsThresholdOne is used only with DNSServiceBrowse, and is not meaningful
563
+ * with any other API call. This flag limits the number of retries that are performed when
564
+ * doing mDNS service discovery. As soon as a single answer is received, retransmission
565
+ * is discontinued. This allows the caller to determine whether or not a particular service
566
+ * is present on the network in as efficient a way as possible. As answers expire from the
567
+ * cache or are explicitly removed as a consequence of the service being discontinued, if
568
+ * the number of still-valid answers reaches zero, mDNSResponder will resume periodic querying
569
+ * on the network until at least one valid answer is present. Because this flag only controls
570
+ * retransmission, when more than one service of the type being browsed is present on the
571
+ * network, it is quite likely that more than one answer will be delivered to the callback.
572
+ *
573
+ * kDNSServiceFlagsThresholdFinder is used only in DNSServiceBrowse, and is not meaningful
574
+ * in other API calls. When set, this flag limits the number of retries that are performed
575
+ * when doing mDNS service discovery, similar to kDNSServiceFlagsThresholdOne. The difference
576
+ * is that the threshold here is higher: retransmissions will continue until some system-
577
+ * dependent number of answers are present, or the retransmission process is complete.
578
+ * Because the number of answers that ends retransmission varies, developers should not
579
+ * depend on there being some specific threshold; rather, this flag can be used in cases
580
+ * where it is preferred to give the user a choice, but where once a small number of
581
+ * such services are discovered, retransmission is discontinued.
582
+ *
583
+ * When kDNSServiceFlagsThresholdReached is set in the client callback add or remove event,
584
+ * it indicates that the browse answer threshold has been reached and no
585
+ * browse requests will be generated on the network until the number of answers falls
586
+ * below the threshold value. Add and remove events can still occur based
587
+ * on incoming Bonjour traffic observed by the system.
588
+ * The set of services return to the client is not guaranteed to represent the
589
+ * entire set of services present on the network once the threshold has been reached.
590
+ *
591
+ * Note, while kDNSServiceFlagsThresholdReached and kDNSServiceFlagsThresholdOne
592
+ * have the same value, there isn't a conflict because kDNSServiceFlagsThresholdReached
593
+ * is only set in the callbacks and kDNSServiceFlagsThresholdOne is only set on
594
+ * input to a DNSServiceBrowse call.
595
+ */
596
+
597
+ kDNSServiceFlagsPrivateOne = 0x2000,
598
+ /*
599
+ * This flag is private and should not be used.
600
+ */
601
+
602
+ kDNSServiceFlagsPrivateTwo = 0x8000000,
603
+ /*
604
+ * This flag is private and should not be used.
605
+ */
606
+
607
+ kDNSServiceFlagsPrivateThree = 0x10000000,
608
+ /*
609
+ * This flag is private and should not be used.
610
+ */
611
+
612
+ kDNSServiceFlagsPrivateFour = 0x20000000,
613
+ /*
614
+ * This flag is private and should not be used.
615
+ */
616
+
617
+ kDNSServiceFlagsPrivateFive = 0x40000000,
618
+ /*
619
+ * This flag is private and should not be used.
620
+ */
621
+
622
+
623
+ kDNSServiceFlagAnsweredFromCache = 0x40000000,
624
+ /*
625
+ * When kDNSServiceFlagAnsweredFromCache is passed back in the flags parameter of DNSServiceQueryRecordReply or DNSServiceGetAddrInfoReply,
626
+ * an answer will have this flag set if it was answered from the cache.
627
+ */
628
+
629
+ kDNSServiceFlagsAllowExpiredAnswers = 0x80000000,
630
+ /*
631
+ * When kDNSServiceFlagsAllowExpiredAnswers is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo,
632
+ * if there are matching expired records still in the cache, then they are immediately returned to the
633
+ * client, and in parallel a network query for that name is issued. All returned records from the query will
634
+ * remain in the cache after expiration.
635
+ */
636
+
637
+ kDNSServiceFlagsExpiredAnswer = 0x80000000
638
+ /*
639
+ * When kDNSServiceFlagsAllowExpiredAnswers is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo,
640
+ * an expired answer will have this flag set.
641
+ */
642
+
643
+ };
644
+
645
+ /* Possible protocol values */
646
+ enum
647
+ {
648
+ /* for DNSServiceGetAddrInfo() */
649
+ kDNSServiceProtocol_IPv4 = 0x01,
650
+ kDNSServiceProtocol_IPv6 = 0x02,
651
+ /* 0x04 and 0x08 reserved for future internetwork protocols */
652
+
653
+ /* for DNSServiceNATPortMappingCreate() */
654
+ kDNSServiceProtocol_UDP = 0x10,
655
+ kDNSServiceProtocol_TCP = 0x20
656
+ /* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960]
657
+ * or DCCP [RFC 4340]. If future NAT gateways are created that support port
658
+ * mappings for these protocols, new constants will be defined here.
659
+ */
660
+ };
661
+
662
+ /*
663
+ * The values for DNS Classes and Types are listed in RFC 1035, and are available
664
+ * on every OS in its DNS header file. Unfortunately every OS does not have the
665
+ * same header file containing DNS Class and Type constants, and the names of
666
+ * the constants are not consistent. For example, BIND 8 uses "T_A",
667
+ * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
668
+ * For this reason, these constants are also listed here, so that code using
669
+ * the DNS-SD programming APIs can use these constants, so that the same code
670
+ * can compile on all our supported platforms.
671
+ */
672
+
673
+ enum
674
+ {
675
+ kDNSServiceClass_IN = 1 /* Internet */
676
+ };
677
+
678
+ enum
679
+ {
680
+ kDNSServiceType_A = 1, /* Host address. */
681
+ kDNSServiceType_NS = 2, /* Authoritative server. */
682
+ kDNSServiceType_MD = 3, /* Mail destination. */
683
+ kDNSServiceType_MF = 4, /* Mail forwarder. */
684
+ kDNSServiceType_CNAME = 5, /* Canonical name. */
685
+ kDNSServiceType_SOA = 6, /* Start of authority zone. */
686
+ kDNSServiceType_MB = 7, /* Mailbox domain name. */
687
+ kDNSServiceType_MG = 8, /* Mail group member. */
688
+ kDNSServiceType_MR = 9, /* Mail rename name. */
689
+ kDNSServiceType_NULL = 10, /* Null resource record. */
690
+ kDNSServiceType_WKS = 11, /* Well known service. */
691
+ kDNSServiceType_PTR = 12, /* Domain name pointer. */
692
+ kDNSServiceType_HINFO = 13, /* Host information. */
693
+ kDNSServiceType_MINFO = 14, /* Mailbox information. */
694
+ kDNSServiceType_MX = 15, /* Mail routing information. */
695
+ kDNSServiceType_TXT = 16, /* One or more text strings (NOT "zero or more..."). */
696
+ kDNSServiceType_RP = 17, /* Responsible person. */
697
+ kDNSServiceType_AFSDB = 18, /* AFS cell database. */
698
+ kDNSServiceType_X25 = 19, /* X_25 calling address. */
699
+ kDNSServiceType_ISDN = 20, /* ISDN calling address. */
700
+ kDNSServiceType_RT = 21, /* Router. */
701
+ kDNSServiceType_NSAP = 22, /* NSAP address. */
702
+ kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */
703
+ kDNSServiceType_SIG = 24, /* Security signature. */
704
+ kDNSServiceType_KEY = 25, /* Security key. */
705
+ kDNSServiceType_PX = 26, /* X.400 mail mapping. */
706
+ kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */
707
+ kDNSServiceType_AAAA = 28, /* IPv6 Address. */
708
+ kDNSServiceType_LOC = 29, /* Location Information. */
709
+ kDNSServiceType_NXT = 30, /* Next domain (security). */
710
+ kDNSServiceType_EID = 31, /* Endpoint identifier. */
711
+ kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */
712
+ kDNSServiceType_SRV = 33, /* Server Selection. */
713
+ kDNSServiceType_ATMA = 34, /* ATM Address */
714
+ kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */
715
+ kDNSServiceType_KX = 36, /* Key Exchange */
716
+ kDNSServiceType_CERT = 37, /* Certification record */
717
+ kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */
718
+ kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */
719
+ kDNSServiceType_SINK = 40, /* Kitchen sink (experimental) */
720
+ kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */
721
+ kDNSServiceType_APL = 42, /* Address Prefix List */
722
+ kDNSServiceType_DS = 43, /* Delegation Signer */
723
+ kDNSServiceType_SSHFP = 44, /* SSH Key Fingerprint */
724
+ kDNSServiceType_IPSECKEY = 45, /* IPSECKEY */
725
+ kDNSServiceType_RRSIG = 46, /* RRSIG */
726
+ kDNSServiceType_NSEC = 47, /* Denial of Existence */
727
+ kDNSServiceType_DNSKEY = 48, /* DNSKEY */
728
+ kDNSServiceType_DHCID = 49, /* DHCP Client Identifier */
729
+ kDNSServiceType_NSEC3 = 50, /* Hashed Authenticated Denial of Existence */
730
+ kDNSServiceType_NSEC3PARAM = 51, /* Hashed Authenticated Denial of Existence */
731
+
732
+ kDNSServiceType_HIP = 55, /* Host Identity Protocol */
733
+
734
+ kDNSServiceType_SVCB = 64, /* Service Binding. */
735
+ kDNSServiceType_HTTPS = 65, /* HTTPS Service Binding. */
736
+
737
+ kDNSServiceType_SPF = 99, /* Sender Policy Framework for E-Mail */
738
+ kDNSServiceType_UINFO = 100, /* IANA-Reserved */
739
+ kDNSServiceType_UID = 101, /* IANA-Reserved */
740
+ kDNSServiceType_GID = 102, /* IANA-Reserved */
741
+ kDNSServiceType_UNSPEC = 103, /* IANA-Reserved */
742
+
743
+ kDNSServiceType_TKEY = 249, /* Transaction key */
744
+ kDNSServiceType_TSIG = 250, /* Transaction signature. */
745
+ kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */
746
+ kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */
747
+ kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */
748
+ kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */
749
+ kDNSServiceType_ANY = 255 /* Wildcard match. */
750
+ };
751
+
752
+ /* possible error code values */
753
+ enum
754
+ {
755
+ kDNSServiceErr_NoError = 0,
756
+
757
+ /* IMPORTANT: Values in the negative errno range are reserved and should not
758
+ * be used when defining new DNSService error codes. These values are used
759
+ * internally to map system errno codes directly to DNS Service error codes
760
+ * for improved error handling.
761
+ *
762
+ * Clients can check if an error code is greater than
763
+ * kDNSServiceErr_Unknown. If so, they can negate it to get an
764
+ * errno-compatible error code that can be used with any function that reads
765
+ * errno, providing improved error handling and more detailed error
766
+ * descriptions.
767
+ */
768
+
769
+ kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */
770
+ kDNSServiceErr_NoSuchName = -65538,
771
+ kDNSServiceErr_NoMemory = -65539,
772
+ kDNSServiceErr_BadParam = -65540,
773
+ kDNSServiceErr_BadReference = -65541,
774
+ kDNSServiceErr_BadState = -65542,
775
+ kDNSServiceErr_BadFlags = -65543,
776
+ kDNSServiceErr_Unsupported = -65544,
777
+ kDNSServiceErr_NotInitialized = -65545,
778
+ kDNSServiceErr_AlreadyRegistered = -65547,
779
+ kDNSServiceErr_NameConflict = -65548,
780
+ kDNSServiceErr_Invalid = -65549,
781
+ kDNSServiceErr_Firewall = -65550,
782
+ kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */
783
+ kDNSServiceErr_BadInterfaceIndex = -65552,
784
+ kDNSServiceErr_Refused = -65553,
785
+ kDNSServiceErr_NoSuchRecord = -65554,
786
+ kDNSServiceErr_NoAuth = -65555,
787
+ kDNSServiceErr_NoSuchKey = -65556,
788
+ kDNSServiceErr_NATTraversal = -65557,
789
+ kDNSServiceErr_DoubleNAT = -65558,
790
+ kDNSServiceErr_BadTime = -65559, /* Codes up to here existed in Tiger */
791
+ kDNSServiceErr_BadSig = -65560,
792
+ kDNSServiceErr_BadKey = -65561,
793
+ kDNSServiceErr_Transient = -65562,
794
+ kDNSServiceErr_ServiceNotRunning = -65563, /* Background daemon not running */
795
+ kDNSServiceErr_NATPortMappingUnsupported = -65564, /* NAT doesn't support PCP, NAT-PMP or UPnP */
796
+ kDNSServiceErr_NATPortMappingDisabled = -65565, /* NAT supports PCP, NAT-PMP or UPnP, but it's disabled by the administrator */
797
+ kDNSServiceErr_NoRouter = -65566, /* No router currently configured (probably no network connectivity) */
798
+ kDNSServiceErr_PollingMode = -65567,
799
+ kDNSServiceErr_Timeout = -65568,
800
+ kDNSServiceErr_DefunctConnection = -65569, /* Connection to daemon returned a SO_ISDEFUNCT error result */
801
+ kDNSServiceErr_PolicyDenied = -65570,
802
+ kDNSServiceErr_NotPermitted = -65571,
803
+ kDNSServiceErr_StaleData = -65572,
804
+ kDNSServiceErr_AWDLTimeout = -65573, /* AWDL global timeout. No futher AWDL results will be provided. */
805
+
806
+ /* mDNS Error codes are in the range
807
+ * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
808
+ };
809
+
810
+ /* Maximum length, in bytes, of a service name represented as a */
811
+ /* literal C-String, including the terminating NULL at the end. */
812
+
813
+ #define kDNSServiceMaxServiceName 64
814
+
815
+ /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
816
+ /* including the final trailing dot, and the C-String terminating NULL at the end. */
817
+
818
+ #define kDNSServiceMaxDomainName 1009
819
+
820
+ /*
821
+ * Notes on DNS Name Escaping
822
+ * -- or --
823
+ * "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?"
824
+ *
825
+ * All strings used in the DNS-SD APIs are UTF-8 strings.
826
+ * Apart from the exceptions noted below, the APIs expect the strings to be properly escaped, using the
827
+ * conventional DNS escaping rules, as used by the traditional DNS res_query() API, as described below:
828
+ *
829
+ * Generally all UTF-8 characters (which includes all US ASCII characters) represent themselves,
830
+ * with three exceptions:
831
+ * the dot ('.') character, which is the DNS label separator,
832
+ * the backslash ('\') character, which is the DNS escape character, and
833
+ * the ASCII NUL (0) byte value, which is the C-string terminator character.
834
+ * The escape character ('\') is interpreted as described below:
835
+ *
836
+ * '\ddd', where ddd is a three-digit decimal value from 000 to 255,
837
+ * represents a single literal byte with that value. Any byte value may be
838
+ * represented in '\ddd' format, even characters that don't strictly need to be escaped.
839
+ * For example, the ASCII code for 'w' is 119, and therefore '\119' is equivalent to 'w'.
840
+ * Thus the command "ping '\119\119\119.apple.com'" is the equivalent to the command "ping 'www.apple.com'".
841
+ * Nonprinting ASCII characters in the range 0-31 are often represented this way.
842
+ * In particular, the ASCII NUL character (0) cannot appear in a C-string because C uses it as the
843
+ * string terminator character, so ASCII NUL in a domain name has to be represented in a C-string as '\000'.
844
+ * Other characters like space (ASCII code 32) are sometimes represented as '\032'
845
+ * in contexts where having an actual space character in a C-string would be inconvenient.
846
+ *
847
+ * Otherwise, for all cases where a '\' is followed by anything other than a three-digit decimal value
848
+ * from 000 to 255, the character sequence '\x' represents a single literal occurrence of character 'x'.
849
+ * This is legal for any character, so, for example, '\w' is equivalent to 'w'.
850
+ * Thus the command "ping '\w\w\w.apple.com'" is the equivalent to the command "ping 'www.apple.com'".
851
+ * However, this encoding is most useful when representing the characters '.' and '\',
852
+ * which otherwise would have special meaning in DNS name strings.
853
+ * This means that the following encodings are particularly common:
854
+ * '\\' represents a single literal '\' in the name
855
+ * '\.' represents a single literal '.' in the name
856
+ *
857
+ * A lone escape character ('\') appearing at the end of a string is not allowed, since it is
858
+ * followed by neither a three-digit decimal value from 000 to 255 nor a single character.
859
+ * If a lone escape character ('\') does appear as the last character of a string, it is silently ignored.
860
+ *
861
+ * The worse-case length for an escaped domain name is calculated as follows:
862
+ * The longest legal domain name is 256 bytes in wire format (see RFC 6762, Appendix C, DNS Name Length).
863
+ * For our calculation of the longest *escaped* domain name, we use
864
+ * the longest legal domain name, with the most characters escaped.
865
+ *
866
+ * We consider a domain name of the form: "label63.label63.label63.label62."
867
+ * where "label63" is a 63-byte label and "label62" is a 62-byte label.
868
+ * Counting four label-length bytes, 251 bytes of label data, and the terminating zero,
869
+ * this makes a total of 256 bytes in wire format, the longest legal domain name.
870
+ *
871
+ * If each one of the 251 bytes of label data is represented using '\ddd',
872
+ * then it takes 251 * 4 = 1004 bytes to represent these in a C-string.
873
+ * Adding four '.' characters as shown above, plus the C-string terminating
874
+ * zero at the end, results in a maximum storage requirement of 1009 bytes.
875
+ *
876
+ * The exceptions, that do not use escaping, are the routines where the full
877
+ * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
878
+ * In these routines, the "servicename" is NOT escaped. It does not need to be, since
879
+ * it is, by definition, just a single literal string. Any characters in that string
880
+ * represent exactly what they are. The "regtype" portion is, technically speaking,
881
+ * escaped, but since legal regtypes are only allowed to contain US ASCII letters,
882
+ * digits, and hyphens, there is nothing to escape, so the issue is moot.
883
+ * The "domain" portion is also escaped, though most domains in use on the public
884
+ * Internet today, like regtypes, don't contain any characters that need to be escaped.
885
+ * As DNS-SD becomes more popular, rich-text domains for service discovery will
886
+ * become common, so software should be written to cope with domains with escaping.
887
+ *
888
+ * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
889
+ * terminating NULL at the end). The regtype is of the form _service._tcp or
890
+ * _service._udp, where the "service" part is 1-15 characters, which may be
891
+ * letters, digits, or hyphens. The domain part of the three-part name may be
892
+ * any legal domain, providing that the resulting servicename+regtype+domain
893
+ * name does not exceed 256 bytes.
894
+ *
895
+ * For most software, these issues are transparent. When browsing, the discovered
896
+ * servicenames should simply be displayed as-is. When resolving, the discovered
897
+ * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
898
+ * When a DNSServiceResolve() succeeds, the returned fullname is already in
899
+ * the correct format to pass to standard system DNS APIs such as res_query().
900
+ * For converting from servicename/regtype/domain to a single properly-escaped
901
+ * full DNS name, the helper function DNSServiceConstructFullName() is provided.
902
+ *
903
+ * The following (highly contrived) example illustrates the escaping process.
904
+ * Suppose you have a service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
905
+ * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
906
+ * The full (escaped) DNS name of this service's SRV record would be:
907
+ * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
908
+ */
909
+
910
+
911
+ /*
912
+ * Constants for specifying an interface index
913
+ *
914
+ * Specific interface indexes are identified via a 32-bit unsigned integer returned
915
+ * by the if_nametoindex() family of calls.
916
+ *
917
+ * If the client passes 0 for interface index, that means "do the right thing",
918
+ * which (at present) means, "if the name is in an mDNS local multicast domain
919
+ * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
920
+ * on all applicable interfaces, otherwise send via unicast to the appropriate
921
+ * DNS server." Normally, most clients will use 0 for interface index to
922
+ * automatically get the default sensible behaviour.
923
+ *
924
+ * If the client passes a positive interface index, then that indicates to do the
925
+ * operation only on that one specified interface.
926
+ *
927
+ * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
928
+ * a service, then that service will be found *only* by other local clients
929
+ * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
930
+ * or kDNSServiceInterfaceIndexAny.
931
+ * If a client has a 'private' service, accessible only to other processes
932
+ * running on the same machine, this allows the client to advertise that service
933
+ * in a way such that it does not inadvertently appear in service lists on
934
+ * all the other machines on the network.
935
+ *
936
+ * If the client passes kDNSServiceInterfaceIndexLocalOnly when querying or
937
+ * browsing, then the LocalOnly authoritative records and /etc/hosts caches
938
+ * are searched and will find *all* records registered or configured on that
939
+ * same local machine.
940
+ *
941
+ * If interested in getting negative answers to local questions while querying
942
+ * or browsing, then set both the kDNSServiceInterfaceIndexLocalOnly and the
943
+ * kDNSServiceFlagsReturnIntermediates flags. If no local answers exist at this
944
+ * moment in time, then the reply will return an immediate negative answer. If
945
+ * local records are subsequently created that answer the question, then those
946
+ * answers will be delivered, for as long as the question is still active.
947
+ *
948
+ * If the kDNSServiceFlagsTimeout and kDNSServiceInterfaceIndexLocalOnly flags
949
+ * are set simultaneously when either DNSServiceQueryRecord or DNSServiceGetAddrInfo
950
+ * is called then both flags take effect. However, if DNSServiceQueryRecord is called
951
+ * with both the kDNSServiceFlagsSuppressUnusable and kDNSServiceInterfaceIndexLocalOnly
952
+ * flags set, then the kDNSServiceFlagsSuppressUnusable flag is ignored.
953
+ *
954
+ * Clients explicitly wishing to discover *only* LocalOnly services during a
955
+ * browse may do this, without flags, by inspecting the interfaceIndex of each
956
+ * service reported to a DNSServiceBrowseReply() callback function, and
957
+ * discarding those answers where the interface index is not set to
958
+ * kDNSServiceInterfaceIndexLocalOnly.
959
+ *
960
+ * kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord, Register,
961
+ * and Resolve operations. It should not be used in other DNSService APIs.
962
+ *
963
+ * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or
964
+ * DNSServiceQueryRecord, it restricts the operation to P2P.
965
+ *
966
+ * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceRegister, it is
967
+ * mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P
968
+ * set.
969
+ *
970
+ * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is
971
+ * mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P
972
+ * set, because resolving a P2P service may create and/or enable an interface whose
973
+ * index is not known a priori. The resolve callback will indicate the index of the
974
+ * interface via which the service can be accessed.
975
+ *
976
+ * If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse
977
+ * or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag
978
+ * to include P2P. In this case, if a service instance or the record being queried
979
+ * is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P
980
+ * as the interface index.
981
+ */
982
+
983
+ #define kDNSServiceInterfaceIndexAny 0
984
+ #define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)0xffffffffU)
985
+ #define kDNSServiceInterfaceIndexUnicast ((uint32_t)0xfffffffeU)
986
+ #define kDNSServiceInterfaceIndexP2P ((uint32_t)0xfffffffdU)
987
+ #define kDNSServiceInterfaceIndexBLE ((uint32_t)0xfffffffcU)
988
+ #define kDNSServiceInterfaceIndexInfra ((uint32_t)0xfffffffbU) // Reserved, not used by DNSService API
989
+
990
+ typedef uint32_t DNSServiceFlags;
991
+ typedef uint32_t DNSServiceProtocol;
992
+ typedef int32_t DNSServiceErrorType;
993
+
994
+ #if (defined(__clang__) && __clang__)
995
+ #pragma clang diagnostic push
996
+ #pragma clang diagnostic ignored "-Wnullability-completeness"
997
+ #endif
998
+ /*********************************************************************************************
999
+ *
1000
+ * Version checking
1001
+ *
1002
+ *********************************************************************************************/
1003
+
1004
+ /*!
1005
+ * @brief
1006
+ * Get value of service property.
1007
+ *
1008
+ * @param property
1009
+ * The requested property.
1010
+ * Currently the only property defined is kDNSServiceProperty_DaemonVersion.
1011
+ *
1012
+ * @param result
1013
+ * Place to store result.
1014
+ * For retrieving DaemonVersion, this should be the address of a uint32_t.
1015
+ *
1016
+ * @param size
1017
+ * Pointer to uint32_t containing size of the result location.
1018
+ * For retrieving DaemonVersion, this should be sizeof(uint32_t).
1019
+ * On return the uint32_t is updated to the size of the data returned.
1020
+ * For DaemonVersion, the returned size is always sizeof(uint32_t), but
1021
+ * future properties could be defined which return variable-sized results.
1022
+ *
1023
+ * @result
1024
+ * Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning
1025
+ * if the daemon (or "system service" on Windows) is not running.
1026
+ */
1027
+ DNSSD_EXPORT
1028
+ DNSServiceErrorType DNSSD_API DNSServiceGetProperty
1029
+ (
1030
+ const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
1031
+ void *result, /* Pointer to place to store result */
1032
+ uint32_t *size /* size of result location */
1033
+ );
1034
+
1035
+ /*
1036
+ * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point
1037
+ * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t).
1038
+ *
1039
+ * On return, the 32-bit unsigned integer contains the API version number
1040
+ *
1041
+ * For example, Mac OS X 10.4.9 has API version 1080400.
1042
+ * This allows applications to do simple greater-than and less-than comparisons:
1043
+ * e.g. an application that requires at least API version 1080400 can check:
1044
+ * if (version >= 1080400) ...
1045
+ *
1046
+ * Example usage:
1047
+ * uint32_t version;
1048
+ * uint32_t size = sizeof(version);
1049
+ * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size);
1050
+ * if (!err)
1051
+ * {
1052
+ * if (version > DNS_SD_ORIGINAL_ENCODING_VERSION_NUMBER_MAX)
1053
+ * {
1054
+ * printf("DNS_SD API version is %u.%u.%u\n", version / 1000000, (version / 1000) % 1000, version % 1000);
1055
+ * }
1056
+ * else
1057
+ * {
1058
+ * printf("DNS_SD API version is %u.%u.%u\n", version / 10000, (version / 100) % 100, version % 100);
1059
+ * }
1060
+ * }
1061
+ */
1062
+
1063
+ #define kDNSServiceProperty_DaemonVersion "DaemonVersion"
1064
+
1065
+ /*********************************************************************************************
1066
+ *
1067
+ * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
1068
+ *
1069
+ *********************************************************************************************/
1070
+
1071
+ /*!
1072
+ * @brief
1073
+ * Access underlying Unix domain socket for an initialized DNSServiceRef.
1074
+ *
1075
+ * @param sdRef
1076
+ * A DNSServiceRef initialized by any of the DNSService calls.
1077
+ *
1078
+ * @result
1079
+ * The DNSServiceRef's underlying socket descriptor, or -1 on error.
1080
+ *
1081
+ * @discussion
1082
+ * The DNS Service Discovery implementation uses this socket to communicate between the client and
1083
+ * the daemon. The application MUST NOT directly read from or write to this socket.
1084
+ * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop
1085
+ * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/
1086
+ * select/CFRunLoop etc.) indicates to the client that data is available for reading on the
1087
+ * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's
1088
+ * reply from the socket, and pass it to the appropriate application callback. By using a run
1089
+ * loop or select(), results from the daemon can be processed asynchronously. Alternatively,
1090
+ * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);"
1091
+ * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it
1092
+ * will block until data does become available, and then process the data and return to the caller.
1093
+ * The application is responsible for checking the return value of DNSServiceProcessResult()
1094
+ * to determine if the socket is valid and if it should continue to process data on the socket.
1095
+ * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref)
1096
+ * in a timely fashion -- if the client allows a large backlog of data to build up the daemon
1097
+ * may terminate the connection.
1098
+ */
1099
+ DNSSD_EXPORT
1100
+ dnssd_sock_t DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);
1101
+
1102
+ /*!
1103
+ * @brief
1104
+ * Read a reply from the daemon, calling the appropriate application callback.
1105
+ *
1106
+ * @param sdRef
1107
+ * A DNSServiceRef initialized by any of the DNSService calls
1108
+ * that take a callback parameter.
1109
+ *
1110
+ * @result
1111
+ * Returns kDNSServiceErr_NoError on success, otherwise returns
1112
+ * an error code indicating the specific failure that occurred.
1113
+ *
1114
+ * @discussion
1115
+ * This call will block until the daemon's response is received. Use DNSServiceRefSockFD() in
1116
+ * conjunction with a run loop or select() to determine the presence of a response from the
1117
+ * server before calling this function to process the reply without blocking. Call this function
1118
+ * at any point if it is acceptable to block until the daemon's response arrives. Note that the
1119
+ * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
1120
+ * a reply from the daemon - the daemon may terminate its connection with a client that does not
1121
+ * process the daemon's responses.
1122
+ */
1123
+ DNSSD_EXPORT
1124
+ DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);
1125
+
1126
+ /*!
1127
+ * @brief
1128
+ * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
1129
+ *
1130
+ * @param sdRef
1131
+ * A DNSServiceRef initialized by any of the DNSService calls.
1132
+ *
1133
+ * @discussion
1134
+ * Any services or records registered with this DNSServiceRef will be deregistered. Any
1135
+ * Browse, Resolve, or Query operations called with this reference will be terminated.
1136
+ *
1137
+ * Note: If the reference's underlying socket is used in a run loop or select() call, it should
1138
+ * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
1139
+ * socket.
1140
+ *
1141
+ * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
1142
+ * created via this reference will be invalidated by this call - the resource records are
1143
+ * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
1144
+ * if the reference was initialized with DNSServiceRegister, and an extra resource record was
1145
+ * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
1146
+ * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
1147
+ * functions.
1148
+ *
1149
+ * If the reference was passed to DNSServiceSetDispatchQueue(), DNSServiceRefDeallocate() must
1150
+ * be called on the same queue originally passed as an argument to DNSServiceSetDispatchQueue().
1151
+ *
1152
+ * Note: This call is to be used only with the DNSServiceRef defined by this API.
1153
+ */
1154
+ DNSSD_EXPORT
1155
+ void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);
1156
+
1157
+ /*********************************************************************************************
1158
+ *
1159
+ * Domain Enumeration
1160
+ *
1161
+ *********************************************************************************************/
1162
+
1163
+ /*!
1164
+ * @brief
1165
+ * The definition of the DNSServiceEnumerateDomains callback function.
1166
+ *
1167
+ * @param sdRef
1168
+ * The DNSServiceRef initialized by DNSServiceEnumerateDomains().
1169
+ *
1170
+ * @param flags
1171
+ * Possible values are:
1172
+ * kDNSServiceFlagsMoreComing
1173
+ * kDNSServiceFlagsAdd
1174
+ * kDNSServiceFlagsDefault
1175
+ *
1176
+ * @param interfaceIndex
1177
+ * Specifies the interface on which the domain exists. (The index for a given
1178
+ * interface is determined via the if_nametoindex() family of calls.)
1179
+ *
1180
+ * @param errorCode
1181
+ * Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
1182
+ * the failure that occurred (other parameters are undefined if errorCode is nonzero).
1183
+ *
1184
+ * @param replyDomain
1185
+ * The name of the domain.
1186
+ *
1187
+ * @param context
1188
+ * The context pointer passed to DNSServiceEnumerateDomains.
1189
+ */
1190
+ typedef void (DNSSD_API *DNSServiceDomainEnumReply)
1191
+ (
1192
+ DNSServiceRef sdRef,
1193
+ DNSServiceFlags flags,
1194
+ uint32_t interfaceIndex,
1195
+ DNSServiceErrorType errorCode,
1196
+ const char *replyDomain,
1197
+ void *context
1198
+ );
1199
+
1200
+ /*!
1201
+ * @brief
1202
+ * Asynchronously enumerate domains available for browsing and registration.
1203
+ *
1204
+ * @param sdRef
1205
+ * A pointer to an uninitialized DNSServiceRef
1206
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
1207
+ * a copy of the shared connection reference that is to be used).
1208
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
1209
+ * returns kDNSServiceErr_NoError, and the enumeration operation
1210
+ * will remain active indefinitely until the client terminates it
1211
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
1212
+ * (or by closing the underlying shared connection, if used).
1213
+ *
1214
+ * @param flags
1215
+ * Possible values are:
1216
+ * kDNSServiceFlagsShareConnection to use a shared connection.
1217
+ * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
1218
+ * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
1219
+ * for registration.
1220
+ *
1221
+ * @param interfaceIndex
1222
+ * If non-zero, specifies the interface on which to look for domains.
1223
+ * (the index for a given interface is determined via the if_nametoindex()
1224
+ * family of calls.) Most applications will pass 0 to enumerate domains on
1225
+ * all interfaces. See "Constants for specifying an interface index" for more details.
1226
+ *
1227
+ * @param callBack
1228
+ * The function to be called when a domain is found or the call asynchronously
1229
+ * fails.
1230
+ *
1231
+ * @param context
1232
+ * An application context pointer which is passed to the callback function
1233
+ * (may be NULL).
1234
+ *
1235
+ * @result
1236
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1237
+ * errors are delivered to the callback), otherwise returns an error code indicating
1238
+ * the error that occurred (the callback is not invoked and the DNSServiceRef
1239
+ * is not initialized).
1240
+ * @discussion
1241
+ * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
1242
+ * are to be found.
1243
+ *
1244
+ * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
1245
+ * and are escaped using standard DNS escaping rules.
1246
+ * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
1247
+ * A graphical browser displaying a hierarchical tree-structured view should cut
1248
+ * the names at the bare dots to yield individual labels, then de-escape each
1249
+ * label according to the escaping rules, and then display the resulting UTF-8 text.
1250
+ */
1251
+ DNSSD_EXPORT
1252
+ DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
1253
+ (
1254
+ DNSServiceRef *sdRef,
1255
+ DNSServiceFlags flags,
1256
+ uint32_t interfaceIndex,
1257
+ DNSServiceDomainEnumReply callBack,
1258
+ void *context
1259
+ );
1260
+
1261
+
1262
+ /*********************************************************************************************
1263
+ *
1264
+ * Service Registration
1265
+ *
1266
+ *********************************************************************************************/
1267
+
1268
+ /*!
1269
+ * @brief
1270
+ * The definition of the DNSServiceRegister callback function.
1271
+ *
1272
+ * @param sdRef
1273
+ * The DNSServiceRef initialized by DNSServiceRegister().
1274
+ *
1275
+ * @param flags
1276
+ * When a name is successfully registered, the callback will be
1277
+ * invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area
1278
+ * DNS-SD is in use, it is possible for a single service to get
1279
+ * more than one success callback (e.g. one in the "local" multicast
1280
+ * DNS domain, and another in a wide-area unicast DNS domain).
1281
+ * If a successfully-registered name later suffers a name conflict
1282
+ * or similar problem and has to be deregistered, the callback will
1283
+ * be invoked with the kDNSServiceFlagsAdd flag not set. The callback
1284
+ * is *not* invoked in the case where the caller explicitly terminates
1285
+ * the service registration by calling DNSServiceRefDeallocate(ref);
1286
+ *
1287
+ * @param errorCode
1288
+ * Will be kDNSServiceErr_NoError on success, otherwise will
1289
+ * indicate the failure that occurred (including name conflicts,
1290
+ * if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
1291
+ * Other parameters are undefined if errorCode is nonzero.
1292
+ *
1293
+ * @param name
1294
+ * The service name registered (if the application did not specify a name in
1295
+ * DNSServiceRegister(), this indicates what name was automatically chosen).
1296
+ *
1297
+ * @param regtype
1298
+ * The type of service registered, as it was passed to the callout.
1299
+ *
1300
+ * @param domain
1301
+ * The domain on which the service was registered (if the application did not
1302
+ * specify a domain in DNSServiceRegister(), this indicates the default domain
1303
+ * on which the service was registered).
1304
+ *
1305
+ * @param context
1306
+ * The context pointer that was passed to the callout.
1307
+ */
1308
+ typedef void (DNSSD_API *DNSServiceRegisterReply)
1309
+ (
1310
+ DNSServiceRef sdRef,
1311
+ DNSServiceFlags flags,
1312
+ DNSServiceErrorType errorCode,
1313
+ const char *name,
1314
+ const char *regtype,
1315
+ const char *domain,
1316
+ void *context
1317
+ );
1318
+
1319
+ /*!
1320
+ * @brief
1321
+ * Register a service that is discovered via Browse() and Resolve() calls.
1322
+ *
1323
+ * @param sdRef
1324
+ * A pointer to an uninitialized DNSServiceRef
1325
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
1326
+ * a copy of the shared connection reference that is to be used).
1327
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
1328
+ * returns kDNSServiceErr_NoError, and the service registration
1329
+ * will remain active indefinitely until the client terminates it
1330
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
1331
+ * (or by closing the underlying shared connection, if used).
1332
+ *
1333
+ * @param flags
1334
+ * Possible values are:
1335
+ * kDNSServiceFlagsShareConnection to use a shared connection.
1336
+ * Other flags indicate the renaming behavior on name conflict
1337
+ * (not required for most applications).
1338
+ * See flag definitions above for details.
1339
+ *
1340
+ * @param interfaceIndex
1341
+ * If non-zero, specifies the interface on which to register the service
1342
+ * (the index for a given interface is determined via the if_nametoindex()
1343
+ * family of calls.) Most applications will pass 0 to register on all
1344
+ * available interfaces. See "Constants for specifying an interface index" for more details.
1345
+ *
1346
+ * @param name
1347
+ * If non-NULL, specifies the service name to be registered.
1348
+ * Most applications will not specify a name, in which case the computer
1349
+ * name is used (this name is communicated to the client via the callback).
1350
+ * If a name is specified, it must be 1-63 bytes of UTF-8 text.
1351
+ * If the name is longer than 63 bytes it will be automatically truncated
1352
+ * to a legal length, unless the NoAutoRename flag is set,
1353
+ * in which case kDNSServiceErr_BadParam will be returned.
1354
+ *
1355
+ * @param regtype
1356
+ * The service type followed by the protocol, separated by a dot
1357
+ * (e.g. "_ftp._tcp"). The service type must be an underscore, followed
1358
+ * by 1-15 characters, which may be letters, digits, or hyphens.
1359
+ * The transport protocol must be "_tcp" or "_udp". New service types
1360
+ * should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
1361
+ *
1362
+ * Additional subtypes of the primary service type (where a service
1363
+ * type has defined subtypes) follow the primary service type in a
1364
+ * comma-separated list, with no additional spaces, e.g.
1365
+ * "_primarytype._tcp,_subtype1,_subtype2,_subtype3"
1366
+ * Subtypes provide a mechanism for filtered browsing: A client browsing
1367
+ * for "_primarytype._tcp" will discover all instances of this type;
1368
+ * a client browsing for "_primarytype._tcp,_subtype2" will discover only
1369
+ * those instances that were registered with "_subtype2" in their list of
1370
+ * registered subtypes.
1371
+ *
1372
+ * The subtype mechanism can be illustrated with some examples using the
1373
+ * dns-sd command-line tool:
1374
+ *
1375
+ * % dns-sd -R Simple _test._tcp "" 1001 &
1376
+ * % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 &
1377
+ * % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 &
1378
+ *
1379
+ * Now:
1380
+ * % dns-sd -B _test._tcp # will find all three services
1381
+ * % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best"
1382
+ * % dns-sd -B _test._tcp,HasFeatureB # finds only "Best"
1383
+ *
1384
+ * Subtype labels may be up to 63 bytes long, and may contain any eight-
1385
+ * bit byte values, including zero bytes. However, due to the nature of
1386
+ * using a C-string-based API, conventional DNS escaping must be used for
1387
+ * dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below:
1388
+ *
1389
+ * % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123
1390
+ *
1391
+ * @param domain
1392
+ * If non-NULL, specifies the domain on which to advertise the service.
1393
+ * Most applications will not specify a domain, instead automatically
1394
+ * registering in the default domain(s).
1395
+ *
1396
+ * @param host
1397
+ * If non-NULL, specifies the SRV target host name. Most applications
1398
+ * will not specify a host, instead automatically using the machine's
1399
+ * default host name(s). Note that specifying a non-NULL host does NOT
1400
+ * create an address record for that host - the application is responsible
1401
+ * for ensuring that the appropriate address record exists, or creating it
1402
+ * via DNSServiceRegisterRecord().
1403
+ *
1404
+ * @param port
1405
+ * The port, in network byte order, on which the service accepts connections.
1406
+ * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
1407
+ * by browsing, but will cause a name conflict if another client tries to
1408
+ * register that same name). Most clients will not use placeholder services.
1409
+ *
1410
+ * @param txtLen
1411
+ * The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
1412
+ *
1413
+ * @param txtRecord
1414
+ * The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
1415
+ * TXT record, i.e. <length byte> <data> <length byte> <data> ...
1416
+ * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
1417
+ * i.e. it creates a TXT record of length one containing a single empty string.
1418
+ * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
1419
+ * string is the smallest legal DNS TXT record.
1420
+ * As with the other parameters, the DNSServiceRegister call copies the txtRecord
1421
+ * data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
1422
+ * then you can safely free that memory right after the DNSServiceRegister call returns.
1423
+ *
1424
+ * @param callBack
1425
+ * The function to be called when the registration completes or asynchronously
1426
+ * fails. The client MAY pass NULL for the callback - The client will NOT be notified
1427
+ * of the default values picked on its behalf, and the client will NOT be notified of any
1428
+ * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
1429
+ * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
1430
+ * The client may still deregister the service at any time via DNSServiceRefDeallocate().
1431
+ *
1432
+ * @param context
1433
+ * An application context pointer which is passed to the callback function
1434
+ * (may be NULL).
1435
+ *
1436
+ * @result
1437
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1438
+ * errors are delivered to the callback), otherwise returns an error code indicating
1439
+ * the error that occurred (the callback is never invoked and the DNSServiceRef
1440
+ * is not initialized).
1441
+ */
1442
+ DNSSD_EXPORT
1443
+ DNSServiceErrorType DNSSD_API DNSServiceRegister
1444
+ (
1445
+ DNSServiceRef *sdRef,
1446
+ DNSServiceFlags flags,
1447
+ uint32_t interfaceIndex,
1448
+ const char *name, /* may be NULL */
1449
+ const char *regtype,
1450
+ const char *domain, /* may be NULL */
1451
+ const char *host, /* may be NULL */
1452
+ uint16_t port, /* In network byte order */
1453
+ uint16_t txtLen,
1454
+ const void *txtRecord, /* may be NULL */
1455
+ DNSServiceRegisterReply callBack, /* may be NULL */
1456
+ void *context
1457
+ );
1458
+
1459
+ /*!
1460
+ * @brief
1461
+ * Add a record to a registered service.
1462
+ *
1463
+ * @param sdRef
1464
+ * A DNSServiceRef initialized by DNSServiceRegister().
1465
+ *
1466
+ * @param RecordRef
1467
+ * A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
1468
+ * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1469
+ * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
1470
+ * invalidated and may not be used further.
1471
+ *
1472
+ * @param flags
1473
+ * Currently ignored, reserved for future use.
1474
+ *
1475
+ * @param rrtype
1476
+ * The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
1477
+ *
1478
+ * @param rdlen
1479
+ * The length, in bytes, of the rdata.
1480
+ *
1481
+ * @param rdata
1482
+ * The raw rdata to be contained in the added resource record.
1483
+ *
1484
+ * @param ttl
1485
+ * The time to live of the resource record, in seconds.
1486
+ * Most clients should pass 0 to indicate that the system should
1487
+ * select a sensible default value.
1488
+ *
1489
+ * @result
1490
+ * Returns kDNSServiceErr_NoError on success, otherwise returns an
1491
+ * error code indicating the error that occurred (the RecordRef is not initialized).
1492
+ *
1493
+ * @discussion
1494
+ * The name of the record will be the same as the
1495
+ * registered service's name.
1496
+ * The record can later be updated or deregistered by passing the RecordRef initialized
1497
+ * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1498
+ *
1499
+ * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe
1500
+ * with respect to a single DNSServiceRef. If you plan to have multiple threads
1501
+ * in your program simultaneously add, update, or remove records from the same
1502
+ * DNSServiceRef, then it's the caller's responsibility to use a mutex lock
1503
+ * or take similar appropriate precautions to serialize those calls.
1504
+ */
1505
+ DNSSD_EXPORT
1506
+ DNSServiceErrorType DNSSD_API DNSServiceAddRecord
1507
+ (
1508
+ DNSServiceRef sdRef,
1509
+ DNSRecordRef *RecordRef,
1510
+ DNSServiceFlags flags,
1511
+ uint16_t rrtype,
1512
+ uint16_t rdlen,
1513
+ const void *rdata,
1514
+ uint32_t ttl
1515
+ );
1516
+
1517
+ /*!
1518
+ * @brief
1519
+ * Update a registered resource record. This function can update three types of records:
1520
+ * 1. The primary txt record for a service that was previously registered.
1521
+ * 2. Some other record that was added to the service using DNSServiceAddRecord().
1522
+ * 3. A record registered using DNSServiceRegisterRecord().
1523
+ *
1524
+ * @param sdRef
1525
+ * For updates of records associated with a registered service (cases 1 and 2), this is the
1526
+ * DNSServiceRef returned by DNSServiceRegister(). For updates of records registered with
1527
+ * DNSServiceRegisterRecord() (case 3), this is the DNSServiceRef that was passed to
1528
+ * DNSServiceRegisterRecord().
1529
+ *
1530
+ * @param recordRef
1531
+ * For case 1, this is NULL. For case 2, it's a DNSRecordRef returned by DNSServiceAddRecord(). For
1532
+ * case 3, it's a DNSRecordRef returned by DNSServiceRegisterRecord().
1533
+ *
1534
+ * @param flags
1535
+ * Currently ignored, reserved for future use.
1536
+ *
1537
+ * @param rdlen
1538
+ * The length, in bytes, of the new rdata.
1539
+ *
1540
+ * @param rdata
1541
+ * The new rdata to be contained in the updated resource record.
1542
+ *
1543
+ * @param ttl
1544
+ * The time to live of the updated resource record, in seconds.
1545
+ * Most clients should pass 0 to indicate that the system should
1546
+ * select a sensible default value.
1547
+ *
1548
+ * @result
1549
+ * Returns kDNSServiceErr_NoError on success, otherwise returns an
1550
+ * error code indicating the error that occurred.
1551
+ */
1552
+ DNSSD_EXPORT
1553
+ DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
1554
+ (
1555
+ DNSServiceRef sdRef,
1556
+ DNSRecordRef recordRef, /* may be NULL */
1557
+ DNSServiceFlags flags,
1558
+ uint16_t rdlen,
1559
+ const void *rdata,
1560
+ uint32_t ttl
1561
+ );
1562
+
1563
+ #if (defined(__clang__) && __clang__)
1564
+ #pragma clang diagnostic pop
1565
+ #endif
1566
+
1567
+ /*!
1568
+ * @brief
1569
+ * Update a registered resource record with attribute.
1570
+ *
1571
+ * @param sdRef
1572
+ * A DNSServiceRef that was initialized by DNSServiceRegister()
1573
+ * or DNSServiceCreateConnection().
1574
+ *
1575
+ * @param recordRef
1576
+ * A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
1577
+ * service's primary txt record.
1578
+ *
1579
+ * @param flags
1580
+ * Currently ignored, reserved for future use.
1581
+ *
1582
+ * @param rdlen
1583
+ * The length, in bytes, of the new rdata.
1584
+ *
1585
+ * @param rdata
1586
+ * The new rdata to be contained in the updated resource record.
1587
+ *
1588
+ * @param ttl
1589
+ * The time to live of the updated resource record, in seconds.
1590
+ * Most clients should pass 0 to indicate that the system should
1591
+ * select a sensible default value.
1592
+ *
1593
+ * @param attr
1594
+ * An DNSServiceAttribute pointer which is used to specify the attribute
1595
+ * (may be NULL).
1596
+ *
1597
+ * @result
1598
+ * Returns kDNSServiceErr_NoError on success, otherwise returns an
1599
+ * error code indicating the error that occurred.
1600
+ *
1601
+ * @discussion
1602
+ * When atrr is NULL, the functionality of the this function will be the same as
1603
+ * DNSServiceUpdateRecord().
1604
+ */
1605
+ #ifndef __OPEN_SOURCE__
1606
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
1607
+ #else
1608
+ DNSSD_EXPORT
1609
+ #endif
1610
+ DNSServiceErrorType DNSSD_API DNSServiceUpdateRecordWithAttribute
1611
+ (
1612
+ DNSServiceRef DNS_SD_NULLABLE sdRef,
1613
+ DNSRecordRef DNS_SD_NULLABLE recordRef,
1614
+ DNSServiceFlags flags,
1615
+ uint16_t rdlen,
1616
+ const void * DNS_SD_NULLABLE rdata,
1617
+ uint32_t ttl,
1618
+ const DNSServiceAttributeRef DNS_SD_NULLABLE attr
1619
+ );
1620
+
1621
+ #if (defined(__clang__) && __clang__)
1622
+ #pragma clang diagnostic push
1623
+ #pragma clang diagnostic ignored "-Wnullability-completeness"
1624
+ #endif
1625
+
1626
+ /*!
1627
+ * @brief
1628
+ * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
1629
+ * a record registered individually via DNSServiceRegisterRecord().
1630
+ *
1631
+ * @param sdRef
1632
+ * A DNSServiceRef initialized by DNSServiceRegister() (if the
1633
+ * record being removed was registered via DNSServiceAddRecord()) or by
1634
+ * DNSServiceCreateConnection() (if the record being removed was registered via
1635
+ * DNSServiceRegisterRecord()).
1636
+ *
1637
+ * @param RecordRef
1638
+ * A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
1639
+ * or DNSServiceRegisterRecord().
1640
+ *
1641
+ * @param flags
1642
+ * Currently ignored, reserved for future use.
1643
+ *
1644
+ * @result
1645
+ * Returns kDNSServiceErr_NoError on success, otherwise returns an
1646
+ * error code indicating the error that occurred.
1647
+ */
1648
+ DNSSD_EXPORT
1649
+ DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
1650
+ (
1651
+ DNSServiceRef sdRef,
1652
+ DNSRecordRef RecordRef,
1653
+ DNSServiceFlags flags
1654
+ );
1655
+
1656
+ /*********************************************************************************************
1657
+ *
1658
+ * Service Discovery
1659
+ *
1660
+ *********************************************************************************************/
1661
+
1662
+ /*!
1663
+ * @brief
1664
+ * The definition of the DNSServiceBrowse callback function
1665
+ *
1666
+ * @param sdRef
1667
+ * The DNSServiceRef initialized by DNSServiceBrowse().
1668
+ *
1669
+ * @param flags
1670
+ * Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
1671
+ * See flag definitions for details.
1672
+ *
1673
+ * @param interfaceIndex
1674
+ * The interface on which the service is advertised. This index should
1675
+ * be passed to DNSServiceResolve() when resolving the service.
1676
+ *
1677
+ * @param errorCode
1678
+ * Will be kDNSServiceErr_NoError (0) on success, otherwise will
1679
+ * indicate the failure that occurred. Other parameters are undefined if
1680
+ * the errorCode is nonzero.
1681
+ *
1682
+ * @param serviceName
1683
+ * The discovered service name. This name should be displayed to the user,
1684
+ * and stored for subsequent use in the DNSServiceResolve() call.
1685
+ *
1686
+ * @param regtype
1687
+ * The service type, which is usually (but not always) the same as was passed
1688
+ * to DNSServiceBrowse(). One case where the discovered service type may
1689
+ * not be the same as the requested service type is when using subtypes:
1690
+ * The client may want to browse for only those ftp servers that allow
1691
+ * anonymous connections. The client will pass the string "_ftp._tcp,_anon"
1692
+ * to DNSServiceBrowse(), but the type of the service that's discovered
1693
+ * is simply "_ftp._tcp". The regtype for each discovered service instance
1694
+ * should be stored along with the name, so that it can be passed to
1695
+ * DNSServiceResolve() when the service is later resolved.
1696
+ *
1697
+ * @param replyDomain
1698
+ * The domain of the discovered service instance. This may or may not be the
1699
+ * same as the domain that was passed to DNSServiceBrowse(). The domain for each
1700
+ * discovered service instance should be stored along with the name, so that
1701
+ * it can be passed to DNSServiceResolve() when the service is later resolved.
1702
+ *
1703
+ * @param context
1704
+ * The context pointer that was passed to the callout.
1705
+ */
1706
+ typedef void (DNSSD_API *DNSServiceBrowseReply)
1707
+ (
1708
+ DNSServiceRef sdRef,
1709
+ DNSServiceFlags flags,
1710
+ uint32_t interfaceIndex,
1711
+ DNSServiceErrorType errorCode,
1712
+ const char *serviceName,
1713
+ const char *regtype,
1714
+ const char *replyDomain,
1715
+ void *context
1716
+ );
1717
+
1718
+ /*!
1719
+ * @brief
1720
+ * Browse for instances of a service.
1721
+ *
1722
+ * @param sdRef
1723
+ * A pointer to an uninitialized DNSServiceRef
1724
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
1725
+ * a copy of the shared connection reference that is to be used).
1726
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
1727
+ * returns kDNSServiceErr_NoError, and the browse operation
1728
+ * will remain active indefinitely until the client terminates it
1729
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
1730
+ * (or by closing the underlying shared connection, if used).
1731
+ *
1732
+ * @param flags
1733
+ * Possible values are:
1734
+ * kDNSServiceFlagsShareConnection to use a shared connection.
1735
+ *
1736
+ * @param interfaceIndex
1737
+ * If non-zero, specifies the interface on which to browse for services
1738
+ * (the index for a given interface is determined via the if_nametoindex()
1739
+ * family of calls.) Most applications will pass 0 to browse on all available
1740
+ * interfaces. See "Constants for specifying an interface index" for more details.
1741
+ *
1742
+ * @param regtype
1743
+ * The service type being browsed for followed by the protocol, separated by a
1744
+ * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
1745
+ * A client may optionally specify a single subtype to perform filtered browsing:
1746
+ * e.g. browsing for "_primarytype._tcp,_subtype" will discover only those
1747
+ * instances of "_primarytype._tcp" that were registered specifying "_subtype"
1748
+ * in their list of registered subtypes.
1749
+ *
1750
+ * @param domain
1751
+ * If non-NULL, specifies the domain on which to browse for services.
1752
+ * Most applications will not specify a domain, instead browsing on the
1753
+ * default domain(s).
1754
+ *
1755
+ * @param callBack
1756
+ * The function to be called when an instance of the service being browsed for
1757
+ * is found, or if the call asynchronously fails.
1758
+ *
1759
+ * @param context
1760
+ * An application context pointer which is passed to the callback function
1761
+ * (may be NULL).
1762
+ *
1763
+ * @result
1764
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1765
+ * errors are delivered to the callback), otherwise returns an error code indicating
1766
+ * the error that occurred (the callback is not invoked and the DNSServiceRef
1767
+ * is not initialized).
1768
+ */
1769
+ DNSSD_EXPORT
1770
+ DNSServiceErrorType DNSSD_API DNSServiceBrowse
1771
+ (
1772
+ DNSServiceRef *sdRef,
1773
+ DNSServiceFlags flags,
1774
+ uint32_t interfaceIndex,
1775
+ const char *regtype,
1776
+ const char *domain, /* may be NULL */
1777
+ DNSServiceBrowseReply callBack,
1778
+ void *context
1779
+ );
1780
+
1781
+ /*!
1782
+ * @brief
1783
+ * The definition of the DNSServiceResolve callback function.
1784
+ *
1785
+ * @param sdRef
1786
+ * The DNSServiceRef initialized by DNSServiceResolve().
1787
+ *
1788
+ * @param flags
1789
+ * Possible values: kDNSServiceFlagsMoreComing
1790
+ *
1791
+ * @param interfaceIndex
1792
+ * The interface on which the service was resolved.
1793
+ *
1794
+ * @param errorCode
1795
+ * Will be kDNSServiceErr_NoError (0) on success, otherwise will
1796
+ * indicate the failure that occurred. Other parameters are undefined if
1797
+ * the errorCode is nonzero.
1798
+ *
1799
+ * @param fullname
1800
+ * The full service domain name, in the form <servicename>.<protocol>.<domain>.
1801
+ * (This name is escaped following standard DNS rules, making it suitable for
1802
+ * passing to standard system DNS APIs such as res_query(), or to the
1803
+ * special-purpose functions included in this API that take fullname parameters.
1804
+ * See "Notes on DNS Name Escaping" earlier in this file for more details.)
1805
+ *
1806
+ * @param hosttarget
1807
+ * The target hostname of the machine providing the service. This name can
1808
+ * be passed to functions like gethostbyname() to identify the host's IP address.
1809
+ *
1810
+ * @param port
1811
+ * The port, in network byte order, on which connections are accepted for this service.
1812
+ *
1813
+ * @param txtLen
1814
+ * The length of the txt record, in bytes.
1815
+ *
1816
+ * @param txtRecord
1817
+ * The service's primary txt record, in standard txt record format.
1818
+ *
1819
+ * @param context
1820
+ * The context pointer that was passed to the callout.
1821
+ */
1822
+ typedef void (DNSSD_API *DNSServiceResolveReply)
1823
+ (
1824
+ DNSServiceRef sdRef,
1825
+ DNSServiceFlags flags,
1826
+ uint32_t interfaceIndex,
1827
+ DNSServiceErrorType errorCode,
1828
+ const char *fullname,
1829
+ const char *hosttarget,
1830
+ uint16_t port, /* In network byte order */
1831
+ uint16_t txtLen,
1832
+ const unsigned char *txtRecord,
1833
+ void *context
1834
+ );
1835
+
1836
+ /*!
1837
+ * @brief
1838
+ * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
1839
+ * txt record.
1840
+ *
1841
+ * @param sdRef
1842
+ * A pointer to an uninitialized DNSServiceRef
1843
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
1844
+ * a copy of the shared connection reference that is to be used).
1845
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
1846
+ * returns kDNSServiceErr_NoError, and the resolve operation
1847
+ * will remain active indefinitely until the client terminates it
1848
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
1849
+ * (or by closing the underlying shared connection, if used).
1850
+ *
1851
+ * @param flags
1852
+ * Possible values are:
1853
+ * kDNSServiceFlagsShareConnection to use a shared connection.
1854
+ * Specifying kDNSServiceFlagsForceMulticast will cause query to be
1855
+ * performed with a link-local mDNS query, even if the name is an
1856
+ * apparently non-local name (i.e. a name not ending in ".local.")
1857
+ *
1858
+ * @param interfaceIndex
1859
+ * The interface on which to resolve the service. If this resolve call is
1860
+ * as a result of a currently active DNSServiceBrowse() operation, then the
1861
+ * interfaceIndex should be the index reported in the DNSServiceBrowseReply
1862
+ * callback. If this resolve call is using information previously saved
1863
+ * (e.g. in a preference file) for later use, then use interfaceIndex 0, because
1864
+ * the desired service may now be reachable via a different physical interface.
1865
+ * See "Constants for specifying an interface index" for more details.
1866
+ *
1867
+ * @param name
1868
+ * The name of the service instance to be resolved, as reported to the
1869
+ * DNSServiceBrowseReply() callback.
1870
+ *
1871
+ * @param regtype
1872
+ * The type of the service instance to be resolved, as reported to the
1873
+ * DNSServiceBrowseReply() callback.
1874
+ *
1875
+ * @param domain
1876
+ * The domain of the service instance to be resolved, as reported to the
1877
+ * DNSServiceBrowseReply() callback.
1878
+ *
1879
+ * @param callBack
1880
+ * The function to be called when a result is found, or if the call
1881
+ * asynchronously fails.
1882
+ *
1883
+ * @param context
1884
+ * An application context pointer which is passed to the callback function
1885
+ * (may be NULL).
1886
+ *
1887
+ * @result
1888
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1889
+ * errors are delivered to the callback), otherwise returns an error code indicating
1890
+ * the error that occurred (the callback is never invoked and the DNSServiceRef
1891
+ * is not initialized).
1892
+ * @discussion
1893
+ * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
1894
+ * DNSServiceQueryRecord() instead, as it is more efficient for this task.
1895
+ *
1896
+ * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
1897
+ * DNSServiceRefDeallocate().
1898
+ *
1899
+ * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
1900
+ * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
1901
+ * DNSServiceQueryRecord() should be used.
1902
+ *
1903
+ * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"
1904
+ * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.
1905
+ * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.
1906
+ * These should be fixed by updating your own callback function definition to match the corrected
1907
+ * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent
1908
+ * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250
1909
+ * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.
1910
+ * If you need to maintain portable code that will compile cleanly with both the old and new versions of
1911
+ * this header file, you should update your callback function definition to use the correct unsigned value,
1912
+ * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate
1913
+ * the compiler warning, e.g.:
1914
+ * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);
1915
+ * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)
1916
+ * with both the old header and with the new corrected version.
1917
+ */
1918
+ DNSSD_EXPORT
1919
+ DNSServiceErrorType DNSSD_API DNSServiceResolve
1920
+ (
1921
+ DNSServiceRef *sdRef,
1922
+ DNSServiceFlags flags,
1923
+ uint32_t interfaceIndex,
1924
+ const char *name,
1925
+ const char *regtype,
1926
+ const char *domain,
1927
+ DNSServiceResolveReply callBack,
1928
+ void *context
1929
+ );
1930
+
1931
+ /*********************************************************************************************
1932
+ *
1933
+ * Querying Individual Specific Records
1934
+ *
1935
+ *********************************************************************************************/
1936
+
1937
+ /*!
1938
+ * @brief
1939
+ * The definition of the DNSServiceQueryRecord callback function.
1940
+ *
1941
+ * @param sdRef
1942
+ * The DNSServiceRef initialized by DNSServiceQueryRecord().
1943
+ *
1944
+ * @param flags
1945
+ * Possible values are kDNSServiceFlagsMoreComing and
1946
+ * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
1947
+ * with a ttl of 0, i.e. "Remove" events.
1948
+ *
1949
+ * @param interfaceIndex
1950
+ * The interface on which the query was resolved (the index for a given
1951
+ * interface is determined via the if_nametoindex() family of calls).
1952
+ * See "Constants for specifying an interface index" for more details.
1953
+ *
1954
+ * @param errorCode
1955
+ * Will be kDNSServiceErr_NoError on success, otherwise will
1956
+ * indicate the failure that occurred. Other parameters are undefined if
1957
+ * errorCode is nonzero.
1958
+ *
1959
+ * @param fullname
1960
+ * The resource record's full domain name.
1961
+ *
1962
+ * @param rrtype
1963
+ * The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1964
+ *
1965
+ * @param rrclass
1966
+ * The class of the resource record (usually kDNSServiceClass_IN).
1967
+ *
1968
+ * @param rdlen
1969
+ * The length, in bytes, of the resource record rdata.
1970
+ *
1971
+ * @param rdata
1972
+ * The raw rdata of the resource record.
1973
+ *
1974
+ * @param ttl
1975
+ * If the client wishes to cache the result for performance reasons,
1976
+ * the TTL indicates how long the client may legitimately hold onto
1977
+ * this result, in seconds. After the TTL expires, the client should
1978
+ * consider the result no longer valid, and if it requires this data
1979
+ * again, it should be re-fetched with a new query. Of course, this
1980
+ * only applies to clients that cancel the asynchronous operation when
1981
+ * they get a result. Clients that leave the asynchronous operation
1982
+ * running can safely assume that the data remains valid until they
1983
+ * get another callback telling them otherwise. The ttl value is not
1984
+ * updated when the daemon answers from the cache, hence relying on
1985
+ * the accuracy of the ttl value is not recommended.
1986
+ *
1987
+ * @param context
1988
+ * The context pointer that was passed to the callout.
1989
+ */
1990
+ typedef void (DNSSD_API *DNSServiceQueryRecordReply)
1991
+ (
1992
+ DNSServiceRef sdRef,
1993
+ DNSServiceFlags flags,
1994
+ uint32_t interfaceIndex,
1995
+ DNSServiceErrorType errorCode,
1996
+ const char *fullname,
1997
+ uint16_t rrtype,
1998
+ uint16_t rrclass,
1999
+ uint16_t rdlen,
2000
+ const void *rdata,
2001
+ uint32_t ttl,
2002
+ void *context
2003
+ );
2004
+
2005
+ /*!
2006
+ * @brief
2007
+ * Query for an arbitrary DNS record.
2008
+ *
2009
+ * @param sdRef
2010
+ * A pointer to an uninitialized DNSServiceRef
2011
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
2012
+ * a copy of the shared connection reference that is to be used).
2013
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
2014
+ * returns kDNSServiceErr_NoError, and the query operation
2015
+ * will remain active indefinitely until the client terminates it
2016
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
2017
+ * (or by closing the underlying shared connection, if used).
2018
+ *
2019
+ * @param flags
2020
+ * Possible values are:
2021
+ * kDNSServiceFlagsShareConnection to use a shared connection.
2022
+ * kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
2023
+ * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
2024
+ * query to a unicast DNS server that implements the protocol. This flag
2025
+ * has no effect on link-local multicast queries.
2026
+ *
2027
+ * @param interfaceIndex
2028
+ * If non-zero, specifies the interface on which to issue the query
2029
+ * (the index for a given interface is determined via the if_nametoindex()
2030
+ * family of calls.) Passing 0 causes the name to be queried for on all
2031
+ * interfaces. See "Constants for specifying an interface index" for more details.
2032
+ *
2033
+ * @param fullname
2034
+ * The full domain name of the resource record to be queried for.
2035
+ *
2036
+ * @param rrtype
2037
+ * The numerical type of the resource record to be queried for
2038
+ * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
2039
+ *
2040
+ * @param rrclass
2041
+ * The class of the resource record (usually kDNSServiceClass_IN).
2042
+ *
2043
+ * @param callBack
2044
+ * The function to be called when a result is found, or if the call
2045
+ * asynchronously fails.
2046
+ *
2047
+ * @param context
2048
+ * An application context pointer which is passed to the callback function
2049
+ * (may be NULL).
2050
+ *
2051
+ * @result:
2052
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
2053
+ * errors are delivered to the callback), otherwise returns an error code indicating
2054
+ * the error that occurred (the callback is never invoked and the DNSServiceRef
2055
+ * is not initialized).
2056
+ */
2057
+ DNSSD_EXPORT
2058
+ DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
2059
+ (
2060
+ DNSServiceRef *sdRef,
2061
+ DNSServiceFlags flags,
2062
+ uint32_t interfaceIndex,
2063
+ const char *fullname,
2064
+ uint16_t rrtype,
2065
+ uint16_t rrclass,
2066
+ DNSServiceQueryRecordReply callBack,
2067
+ void *context
2068
+ );
2069
+
2070
+ /*********************************************************************************************
2071
+ *
2072
+ * Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname
2073
+ *
2074
+ *********************************************************************************************/
2075
+
2076
+ /*!
2077
+ * @brief
2078
+ * The definition of the DNSServiceGetAddrInfo callback function.
2079
+ *
2080
+ * @param sdRef
2081
+ * The DNSServiceRef initialized by DNSServiceGetAddrInfo().
2082
+ *
2083
+ * @param flags
2084
+ * Possible values are kDNSServiceFlagsMoreComing and
2085
+ * kDNSServiceFlagsAdd.
2086
+ *
2087
+ * @param interfaceIndex
2088
+ * The interface to which the answers pertain.
2089
+ *
2090
+ * @param errorCode
2091
+ * Will be kDNSServiceErr_NoError on success, otherwise will
2092
+ * indicate the failure that occurred. Other parameters are
2093
+ * undefined if errorCode is nonzero.
2094
+ *
2095
+ * @param hostname
2096
+ * The fully qualified domain name of the host to be queried for.
2097
+ *
2098
+ * @param address
2099
+ * IPv4 or IPv6 address.
2100
+ *
2101
+ * @param ttl
2102
+ * If the client wishes to cache the result for performance reasons,
2103
+ * the TTL indicates how long the client may legitimately hold onto
2104
+ * this result, in seconds. After the TTL expires, the client should
2105
+ * consider the result no longer valid, and if it requires this data
2106
+ * again, it should be re-fetched with a new query. Of course, this
2107
+ * only applies to clients that cancel the asynchronous operation when
2108
+ * they get a result. Clients that leave the asynchronous operation
2109
+ * running can safely assume that the data remains valid until they
2110
+ * get another callback telling them otherwise. The ttl value is not
2111
+ * updated when the daemon answers from the cache, hence relying on
2112
+ * the accuracy of the ttl value is not recommended.
2113
+ *
2114
+ * @param context
2115
+ * The context pointer that was passed to the callout.
2116
+ */
2117
+ typedef void (DNSSD_API *DNSServiceGetAddrInfoReply)
2118
+ (
2119
+ DNSServiceRef sdRef,
2120
+ DNSServiceFlags flags,
2121
+ uint32_t interfaceIndex,
2122
+ DNSServiceErrorType errorCode,
2123
+ const char *hostname,
2124
+ const struct sockaddr *address,
2125
+ uint32_t ttl,
2126
+ void *context
2127
+ );
2128
+
2129
+ /*!
2130
+ * @brief
2131
+ * Queries for the IP address of a hostname by using either Multicast or Unicast DNS.
2132
+ *
2133
+ * @param sdRef
2134
+ * A pointer to an uninitialized DNSServiceRef
2135
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
2136
+ * a copy of the shared connection reference that is to be used).
2137
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
2138
+ * returns kDNSServiceErr_NoError, and the address query operation
2139
+ * will remain active indefinitely until the client terminates it
2140
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
2141
+ * (or by closing the underlying shared connection, if used).
2142
+ *
2143
+ * @param flags
2144
+ * Possible values are:
2145
+ * kDNSServiceFlagsShareConnection to use a shared connection.
2146
+ * kDNSServiceFlagsForceMulticast
2147
+ *
2148
+ * @param interfaceIndex
2149
+ * The interface on which to issue the query. Passing 0 causes the query to be
2150
+ * sent on all active interfaces via Multicast or the primary interface via Unicast.
2151
+ *
2152
+ * @param protocol
2153
+ * Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6
2154
+ * to look up IPv6 addresses, or both to look up both kinds. If neither flag is
2155
+ * set, the system will apply an intelligent heuristic, which is (currently)
2156
+ * that it will attempt to look up both, except:
2157
+ *
2158
+ * * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
2159
+ * but this host has no routable IPv6 address, then the call will not try to
2160
+ * look up IPv6 addresses for "hostname", since any addresses it found would be
2161
+ * unlikely to be of any use anyway. Similarly, if this host has no routable
2162
+ * IPv4 address, the call will not try to look up IPv4 addresses for "hostname".
2163
+ *
2164
+ * @param hostname
2165
+ * The fully qualified domain name of the host to be queried for.
2166
+ *
2167
+ * @param callBack
2168
+ * The function to be called when the query succeeds or fails asynchronously.
2169
+ *
2170
+ * @param context
2171
+ * An application context pointer which is passed to the callback function
2172
+ * (may be NULL).
2173
+ *
2174
+ * @result
2175
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
2176
+ * errors are delivered to the callback), otherwise returns an error code indicating
2177
+ * the error that occurred.
2178
+ */
2179
+ DNSSD_EXPORT
2180
+ DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo
2181
+ (
2182
+ DNSServiceRef *sdRef,
2183
+ DNSServiceFlags flags,
2184
+ uint32_t interfaceIndex,
2185
+ DNSServiceProtocol protocol,
2186
+ const char *hostname,
2187
+ DNSServiceGetAddrInfoReply callBack,
2188
+ void *context
2189
+ );
2190
+
2191
+ /*********************************************************************************************
2192
+ *
2193
+ * Special Purpose Calls:
2194
+ * DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord()
2195
+ * (most applications will not use these)
2196
+ *
2197
+ *********************************************************************************************/
2198
+
2199
+ /*!
2200
+ * @brief
2201
+ * Create a connection to the daemon allowing efficient registration of
2202
+ * multiple individual records.
2203
+ *
2204
+ * @param sdRef
2205
+ * A pointer to an uninitialized DNSServiceRef.
2206
+ * Deallocating the reference (via DNSServiceRefDeallocate())
2207
+ * severs the connection and cancels all operations and
2208
+ * deregisters all records registered on this connection.
2209
+ *
2210
+ * @result
2211
+ * Returns kDNSServiceErr_NoError on success, otherwise returns
2212
+ * an error code indicating the specific failure that occurred
2213
+ * (in which case the DNSServiceRef is not initialized).
2214
+ */
2215
+ DNSSD_EXPORT
2216
+ DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);
2217
+
2218
+ /*!
2219
+ * @brief
2220
+ * The definition of the DNSServiceRegisterRecord callback function.
2221
+ *
2222
+ * @param sdRef
2223
+ * The connected DNSServiceRef initialized by
2224
+ * DNSServiceCreateConnection().
2225
+ *
2226
+ * @param RecordRef
2227
+ * The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
2228
+ * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
2229
+ * invalidated, and may not be used further.
2230
+ *
2231
+ * @param flags
2232
+ * Currently unused, reserved for future use.
2233
+ *
2234
+ * @param errorCode
2235
+ * Will be kDNSServiceErr_NoError on success, otherwise will
2236
+ * indicate the failure that occurred (including name conflicts.)
2237
+ * Other parameters are undefined if errorCode is nonzero.
2238
+ *
2239
+ * @param context
2240
+ * The context pointer that was passed to the callout.
2241
+ */
2242
+ typedef void (DNSSD_API *DNSServiceRegisterRecordReply)
2243
+ (
2244
+ DNSServiceRef sdRef,
2245
+ DNSRecordRef RecordRef,
2246
+ DNSServiceFlags flags,
2247
+ DNSServiceErrorType errorCode,
2248
+ void *context
2249
+ );
2250
+
2251
+ /*!
2252
+ * @brief
2253
+ * Register an individual resource record on a connected DNSServiceRef.
2254
+ *
2255
+ * @param sdRef
2256
+ * A DNSServiceRef initialized by DNSServiceCreateConnection().
2257
+ *
2258
+ * @param RecordRef
2259
+ * A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
2260
+ * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
2261
+ * (To deregister ALL records registered on a single connected DNSServiceRef
2262
+ * and deallocate each of their corresponding DNSServiceRecordRefs, call
2263
+ * DNSServiceRefDeallocate()).
2264
+ *
2265
+ * @param flags
2266
+ * Required values are:
2267
+ * One of kDNSServiceFlagsShared, kDNSServiceFlagsUnique or kDNSServiceFlagsKnownUnique flags.
2268
+ *
2269
+ * Possible values are:
2270
+ * kDNSServiceFlagsForceMulticast: If it is specified, the registration will be performed just like
2271
+ * a link-local mDNS registration even if the name is an apparently non-local name (i.e. a name not
2272
+ * ending in ".local.")
2273
+ *
2274
+ * @param interfaceIndex
2275
+ * If non-zero, specifies the interface on which to register the record
2276
+ * (the index for a given interface is determined via the if_nametoindex()
2277
+ * family of calls.) Passing 0 causes the record to be registered on all interfaces.
2278
+ * See "Constants for specifying an interface index" for more details.
2279
+ *
2280
+ * @param fullname
2281
+ * The full domain name of the resource record.
2282
+ *
2283
+ * @param rrtype
2284
+ * The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
2285
+ *
2286
+ * @param rrclass
2287
+ * The class of the resource record (usually kDNSServiceClass_IN)
2288
+ *
2289
+ * @param rdlen
2290
+ * Length, in bytes, of the rdata.
2291
+ *
2292
+ * @param rdata
2293
+ * A pointer to the raw rdata, as it is to appear in the DNS record.
2294
+ *
2295
+ * @param ttl
2296
+ * The time to live of the resource record, in seconds.
2297
+ * Most clients should pass 0 to indicate that the system should
2298
+ * select a sensible default value.
2299
+ *
2300
+ * @param callBack
2301
+ * The function to be called when a result is found, or if the call
2302
+ * asynchronously fails (e.g. because of a name conflict.)
2303
+ *
2304
+ * @param context
2305
+ * An application context pointer which is passed to the callback function
2306
+ * (may be NULL).
2307
+ *
2308
+ * @result
2309
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
2310
+ * errors are delivered to the callback), otherwise returns an error code indicating
2311
+ * the error that occurred (the callback is never invoked and the DNSRecordRef is
2312
+ * not initialized).
2313
+ *
2314
+ * @discussion
2315
+ * Note that name conflicts occurring for records registered via this call must be handled
2316
+ * by the client in the callback. The RecordRef object returned by the DNSServiceRegisterRecord
2317
+ * call in this case is not disposed of as a result of the error. The caller is responsible
2318
+ * for disposing of it either calling DNSServiceRemoveRecord on the value returned in RecordRef,
2319
+ * or by calling DNSServiceRefDeallocate on the DNSServiceRef value passed in sdRef.
2320
+ */
2321
+ DNSSD_EXPORT
2322
+ DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
2323
+ (
2324
+ DNSServiceRef sdRef,
2325
+ DNSRecordRef *RecordRef,
2326
+ DNSServiceFlags flags,
2327
+ uint32_t interfaceIndex,
2328
+ const char *fullname,
2329
+ uint16_t rrtype,
2330
+ uint16_t rrclass,
2331
+ uint16_t rdlen,
2332
+ const void *rdata,
2333
+ uint32_t ttl,
2334
+ DNSServiceRegisterRecordReply callBack,
2335
+ void *context
2336
+ );
2337
+
2338
+ /*!
2339
+ * @brief
2340
+ * Instruct the daemon to verify the validity of a resource record that appears
2341
+ * to be out of date (e.g. because TCP connection to a service's target failed.)
2342
+ * Causes the record to be flushed from the daemon's cache (as well as all other
2343
+ * daemons' caches on the network) if the record is determined to be invalid.
2344
+ * Use this routine conservatively. Reconfirming a record necessarily consumes
2345
+ * network bandwidth, so this should not be done indiscriminately.
2346
+ *
2347
+ * @param flags
2348
+ * Not currently used.
2349
+ *
2350
+ * @param interfaceIndex
2351
+ * Specifies the interface of the record in question.
2352
+ * The caller must specify the interface.
2353
+ * This API (by design) causes increased network traffic, so it requires
2354
+ * the caller to be precise about which record should be reconfirmed.
2355
+ * It is not possible to pass zero for the interface index to perform
2356
+ * a "wildcard" reconfirmation, where *all* matching records are reconfirmed.
2357
+ *
2358
+ * @param fullname
2359
+ * The resource record's full domain name.
2360
+ *
2361
+ * @param rrtype
2362
+ * The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
2363
+ *
2364
+ * @param rrclass
2365
+ * The class of the resource record (usually kDNSServiceClass_IN).
2366
+ *
2367
+ * @param rdlen
2368
+ * The length, in bytes, of the resource record rdata.
2369
+ *
2370
+ * @param rdata
2371
+ * The raw rdata of the resource record.
2372
+ */
2373
+ DNSSD_EXPORT
2374
+ DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
2375
+ (
2376
+ DNSServiceFlags flags,
2377
+ uint32_t interfaceIndex,
2378
+ const char *fullname,
2379
+ uint16_t rrtype,
2380
+ uint16_t rrclass,
2381
+ uint16_t rdlen,
2382
+ const void *rdata
2383
+ );
2384
+
2385
+ #ifndef __OPEN_SOURCE__
2386
+
2387
+ /*!
2388
+ * @brief
2389
+ * Release P2P connection resources associated with the service instance.
2390
+ *
2391
+ * @param flags
2392
+ * Not currently used.
2393
+ *
2394
+ * @param name
2395
+ * The name of the service instance to be resolved, as reported to the
2396
+ * DNSServiceBrowseReply() callback.
2397
+ *
2398
+ * @param regtype
2399
+ * The type of the service instance to be resolved, as reported to the
2400
+ * DNSServiceBrowseReply() callback.
2401
+ *
2402
+ * @param domain
2403
+ * The domain of the service instance to be resolved, as reported to the
2404
+ * DNSServiceBrowseReply() callback.
2405
+ *
2406
+ * @result
2407
+ * Returns kDNSServiceErr_NoError on success or the error that occurred.
2408
+ *
2409
+ * @discussion
2410
+ * When a service is resolved over a P2P interface, a connection is brought up to the
2411
+ * peer advertising the service instance. This call will free the resources associated
2412
+ * with that connection. Note that the reference to the service instance will only
2413
+ * be maintained by the daemon while the browse for the service type is still
2414
+ * running. Thus the sequence of calls to discover, resolve, and then terminate the connection
2415
+ * associated with a given P2P service instance would be:
2416
+ *
2417
+ * DNSServiceRef BrowseRef, ResolveRef;
2418
+ * DNSServiceBrowse(&BrowseRef, ...) // browse for all instances of the service
2419
+ * DNSServiceResolve(&ResolveRef, ...) // resolving a service instance creates a
2420
+ * // connection to the peer device advertising that service
2421
+ * DNSServiceRefDeallocate(ResolveRef) // Stop the resolve, which does not close the peer connection
2422
+ *
2423
+ * // Communicate with the peer application.
2424
+ *
2425
+ * PeerConnectionRelease() // release the connection to the peer device for the specified service instance
2426
+ *
2427
+ * DNSServiceRefDeallocate(BrowseRef) // stop the browse
2428
+ * // Any further calls to PeerConnectionRelease() will have no affect since the
2429
+ * // service instance to peer connection relationship is only maintained by the
2430
+ * // daemon while the browse is running.
2431
+ */
2432
+ DNSSD_EXPORT
2433
+ DNSServiceErrorType DNSSD_API PeerConnectionRelease
2434
+ (
2435
+ DNSServiceFlags flags,
2436
+ const char *name,
2437
+ const char *regtype,
2438
+ const char *domain
2439
+ );
2440
+
2441
+ #endif // __OPEN_SOURCE__
2442
+
2443
+ /*********************************************************************************************
2444
+ *
2445
+ * NAT Port Mapping
2446
+ *
2447
+ *********************************************************************************************/
2448
+
2449
+ /*!
2450
+ * @brief
2451
+ * The definition of the DNSServiceNATPortMappingCreate callback function.
2452
+ *
2453
+ * @param sdRef
2454
+ * The DNSServiceRef initialized by DNSServiceNATPortMappingCreate().
2455
+ *
2456
+ * @param flags
2457
+ * Currently unused, reserved for future use.
2458
+ *
2459
+ * @param interfaceIndex
2460
+ * The interface through which the NAT gateway is reached.
2461
+ *
2462
+ * @param errorCode
2463
+ * Will be kDNSServiceErr_NoError on success.
2464
+ * Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or
2465
+ * more layers of NAT, in which case the other parameters have the defined values.
2466
+ * For other failures, will indicate the failure that occurred, and the other
2467
+ * parameters are undefined.
2468
+ *
2469
+ * @param externalAddress
2470
+ * Four byte IPv4 address in network byte order.
2471
+ *
2472
+ * @param protocol
2473
+ * Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both.
2474
+ *
2475
+ * @param internalPort
2476
+ * The port on the local machine that was mapped.
2477
+ *
2478
+ * @param externalPort
2479
+ * The actual external port in the NAT gateway that was mapped.
2480
+ * This is likely to be different than the requested external port.
2481
+ *
2482
+ * @param ttl
2483
+ * The lifetime of the NAT port mapping created on the gateway.
2484
+ * This controls how quickly stale mappings will be garbage-collected
2485
+ * if the client machine crashes, suffers a power failure, is disconnected
2486
+ * from the network, or suffers some other unfortunate demise which
2487
+ * causes it to vanish without explicitly removing its NAT port mapping.
2488
+ * It's possible that the ttl value will differ from the requested ttl value.
2489
+ *
2490
+ * @param context
2491
+ * The context pointer that was passed to the callout.
2492
+ */
2493
+ typedef void (DNSSD_API *DNSServiceNATPortMappingReply)
2494
+ (
2495
+ DNSServiceRef sdRef,
2496
+ DNSServiceFlags flags,
2497
+ uint32_t interfaceIndex,
2498
+ DNSServiceErrorType errorCode,
2499
+ uint32_t externalAddress, /* four byte IPv4 address in network byte order */
2500
+ DNSServiceProtocol protocol,
2501
+ uint16_t internalPort, /* In network byte order */
2502
+ uint16_t externalPort, /* In network byte order and may be different than the requested port */
2503
+ uint32_t ttl, /* may be different than the requested ttl */
2504
+ void *context
2505
+ );
2506
+
2507
+ /*!
2508
+ * @brief
2509
+ * Request a port mapping in the NAT gateway, which maps a port on the local machine
2510
+ * to an external port on the NAT.
2511
+ *
2512
+ * @param sdRef
2513
+ * A pointer to an uninitialized DNSServiceRef
2514
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
2515
+ * a copy of the shared connection reference that is to be used).
2516
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
2517
+ * returns kDNSServiceErr_NoError, and the NAT port mapping
2518
+ * will remain active indefinitely until the client terminates it
2519
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
2520
+ * (or by closing the underlying shared connection, if used).
2521
+ *
2522
+ * @param flags
2523
+ * Possible values are:
2524
+ * kDNSServiceFlagsShareConnection to use a shared connection.
2525
+ *
2526
+ * @param interfaceIndex
2527
+ * The interface on which to create port mappings in a NAT gateway.
2528
+ * Passing 0 causes the port mapping request to be sent on the primary interface.
2529
+ *
2530
+ * @param protocol
2531
+ * To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP,
2532
+ * or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both.
2533
+ * The local listening port number must also be specified in the internalPort parameter.
2534
+ * To just discover the NAT gateway's external IP address, pass zero for protocol,
2535
+ * internalPort, externalPort and ttl.
2536
+ *
2537
+ * @param internalPort
2538
+ * The port number in network byte order on the local machine which is listening for packets.
2539
+ *
2540
+ * @param externalPort
2541
+ * The requested external port in network byte order in the NAT gateway that you would
2542
+ * like to map to the internal port. Pass 0 if you don't care which external port is chosen for you.
2543
+ *
2544
+ * @param ttl
2545
+ * The requested renewal period of the NAT port mapping, in seconds.
2546
+ * If the client machine crashes, suffers a power failure, is disconnected from
2547
+ * the network, or suffers some other unfortunate demise which causes it to vanish
2548
+ * unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway
2549
+ * will garbage-collect old stale NAT port mappings when their lifetime expires.
2550
+ * Requesting a short TTL causes such orphaned mappings to be garbage-collected
2551
+ * more promptly, but consumes system resources and network bandwidth with
2552
+ * frequent renewal packets to keep the mapping from expiring.
2553
+ * Requesting a long TTL is more efficient on the network, but in the event of the
2554
+ * client vanishing, stale NAT port mappings will not be garbage-collected as quickly.
2555
+ * Most clients should pass 0 to use a system-wide default value.
2556
+ *
2557
+ * @param callBack
2558
+ * The function to be called when the port mapping request succeeds or fails asynchronously.
2559
+ *
2560
+ * @param context
2561
+ * An application context pointer which is passed to the callback function
2562
+ * (may be NULL).
2563
+ *
2564
+ * @result
2565
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
2566
+ * errors are delivered to the callback), otherwise returns an error code indicating
2567
+ * the error that occurred.
2568
+ *
2569
+ * If you don't actually want a port mapped, and are just calling the API
2570
+ * because you want to find out the NAT's external IP address (e.g. for UI
2571
+ * display) then pass zero for protocol, internalPort, externalPort and ttl.
2572
+ *
2573
+ * @discussion
2574
+ * The NAT should support either PCP, NAT-PMP or the
2575
+ * UPnP/IGD protocol for this API to create a successful mapping. Note that this API
2576
+ * currently supports IPv4 addresses/mappings only. If the NAT gateway supports PCP and
2577
+ * returns an IPv6 address (incorrectly, since this API specifically requests IPv4
2578
+ * addresses), the DNSServiceNATPortMappingReply callback will be invoked with errorCode
2579
+ * kDNSServiceErr_NATPortMappingUnsupported.
2580
+ *
2581
+ * The port mapping will be renewed indefinitely until the client process exits, or
2582
+ * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate().
2583
+ * The client callback will be invoked, informing the client of the NAT gateway's
2584
+ * external IP address and the external port that has been allocated for this client.
2585
+ * The client should then record this external IP address and port using whatever
2586
+ * directory service mechanism it is using to enable peers to connect to it.
2587
+ * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API
2588
+ * -- when a client calls DNSServiceRegister() NAT mappings are automatically created
2589
+ * and the external IP address and port for the service are recorded in the global DNS.
2590
+ * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use
2591
+ * this API to explicitly map their own ports.)
2592
+ *
2593
+ * It's possible that the client callback could be called multiple times, for example
2594
+ * if the NAT gateway's IP address changes, or if a configuration change results in a
2595
+ * different external port being mapped for this client. Over the lifetime of any long-lived
2596
+ * port mapping, the client should be prepared to handle these notifications of changes
2597
+ * in the environment, and should update its recorded address and/or port as appropriate.
2598
+ *
2599
+ * NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works,
2600
+ * which were intentionally designed to help simplify client code:
2601
+ *
2602
+ * 1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway.
2603
+ * In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT
2604
+ * gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no
2605
+ * NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out
2606
+ * whether or not you need a NAT mapping can be tricky and non-obvious, particularly on
2607
+ * a machine with multiple active network interfaces. Rather than make every client recreate
2608
+ * this logic for deciding whether a NAT mapping is required, the PortMapping API does that
2609
+ * work for you. If the client calls the PortMapping API when the machine already has a
2610
+ * routable public IP address, then instead of complaining about it and giving an error,
2611
+ * the PortMapping API just invokes your callback, giving the machine's public address
2612
+ * and your own port number. This means you don't need to write code to work out whether
2613
+ * your client needs to call the PortMapping API -- just call it anyway, and if it wasn't
2614
+ * necessary, no harm is done:
2615
+ *
2616
+ * - If the machine already has a routable public IP address, then your callback
2617
+ * will just be invoked giving your own address and port.
2618
+ * - If a NAT mapping is required and obtained, then your callback will be invoked
2619
+ * giving you the external address and port.
2620
+ * - If a NAT mapping is required but not obtained from the local NAT gateway,
2621
+ * or the machine has no network connectivity, then your callback will be
2622
+ * invoked giving zero address and port.
2623
+ *
2624
+ * 2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new
2625
+ * network, it's the client's job to notice this, and work out whether a NAT mapping
2626
+ * is required on the new network, and make a new NAT mapping request if necessary.
2627
+ * The DNSServiceNATPortMappingCreate API does this for you, automatically.
2628
+ * The client just needs to make one call to the PortMapping API, and its callback will
2629
+ * be invoked any time the mapping state changes. This property complements point (1) above.
2630
+ * If the client didn't make a NAT mapping request just because it determined that one was
2631
+ * not required at that particular moment in time, the client would then have to monitor
2632
+ * for network state changes to determine if a NAT port mapping later became necessary.
2633
+ * By unconditionally making a NAT mapping request, even when a NAT mapping not to be
2634
+ * necessary, the PortMapping API will then begin monitoring network state changes on behalf of
2635
+ * the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT
2636
+ * mapping and inform the client with a new callback giving the new address and port information.
2637
+ */
2638
+ DNSSD_EXPORT
2639
+ DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate
2640
+ (
2641
+ DNSServiceRef *sdRef,
2642
+ DNSServiceFlags flags,
2643
+ uint32_t interfaceIndex,
2644
+ DNSServiceProtocol protocol, /* TCP and/or UDP */
2645
+ uint16_t internalPort, /* network byte order */
2646
+ uint16_t externalPort, /* network byte order */
2647
+ uint32_t ttl, /* time to live in seconds */
2648
+ DNSServiceNATPortMappingReply callBack,
2649
+ void *context
2650
+ );
2651
+
2652
+ /*********************************************************************************************
2653
+ *
2654
+ * General Utility Functions
2655
+ *
2656
+ *********************************************************************************************/
2657
+
2658
+ /*!
2659
+ * @brief
2660
+ * Concatenate a three-part domain name (as returned by the above callbacks) into a
2661
+ * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
2662
+ * strings where necessary.
2663
+ *
2664
+ * @param fullName
2665
+ * A pointer to a buffer that where the resulting full domain name is to be written.
2666
+ * The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to
2667
+ * accommodate the longest legal domain name without buffer overrun.
2668
+ *
2669
+ * @param service
2670
+ * The service name - any dots or backslashes must NOT be escaped.
2671
+ * May be NULL (to construct a PTR record name, e.g.
2672
+ * "_ftp._tcp.apple.com.").
2673
+ *
2674
+ * @param regtype
2675
+ * The service type followed by the protocol, separated by a dot
2676
+ * (e.g. "_ftp._tcp").
2677
+ *
2678
+ * @param domain
2679
+ * The domain name, e.g. "apple.com.". Literal dots or backslashes,
2680
+ * if any, must be escaped, e.g. "1st\. Floor.apple.com."
2681
+ *
2682
+ * @result:
2683
+ * Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error.
2684
+ */
2685
+ DNSSD_EXPORT
2686
+ DNSServiceErrorType DNSSD_API DNSServiceConstructFullName
2687
+ (
2688
+ char * const fullName,
2689
+ const char * const service, /* may be NULL */
2690
+ const char * const regtype,
2691
+ const char * const domain
2692
+ );
2693
+
2694
+ /*********************************************************************************************
2695
+ *
2696
+ * TXT Record Construction Functions
2697
+ *
2698
+ *********************************************************************************************/
2699
+
2700
+ /*
2701
+ * A typical calling sequence for TXT record construction is something like:
2702
+ *
2703
+ * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
2704
+ * TXTRecordCreate();
2705
+ * TXTRecordSetValue();
2706
+ * TXTRecordSetValue();
2707
+ * TXTRecordSetValue();
2708
+ * ...
2709
+ * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
2710
+ * TXTRecordDeallocate();
2711
+ * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
2712
+ */
2713
+
2714
+
2715
+ /* TXTRecordRef
2716
+ *
2717
+ * Opaque internal data type.
2718
+ * Note: Represents a DNS-SD TXT record.
2719
+ */
2720
+
2721
+ typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef;
2722
+
2723
+
2724
+ /*!
2725
+ * @brief
2726
+ * Creates a new empty TXTRecordRef referencing the specified storage.
2727
+ *
2728
+ * @param txtRecord
2729
+ * A pointer to an uninitialized TXTRecordRef.
2730
+ *
2731
+ * @param bufferLen
2732
+ * The size of the storage provided in the "buffer" parameter.
2733
+ *
2734
+ * @param buffer
2735
+ * Optional caller-supplied storage used to hold the TXTRecord data.
2736
+ * This storage must remain valid for as long as
2737
+ * the TXTRecordRef.
2738
+ * @discussion
2739
+ * If the buffer parameter is NULL, or the specified storage size is not
2740
+ * large enough to hold a key subsequently added using TXTRecordSetValue(),
2741
+ * then additional memory will be added as needed using malloc(). Note that
2742
+ * an existing TXT record buffer should not be passed to TXTRecordCreate
2743
+ * to create a copy of another TXT Record. The correct way to copy TXTRecordRef
2744
+ * is creating an empty TXTRecordRef with TXTRecordCreate() first, and using
2745
+ * TXTRecordSetValue to set the same value.
2746
+ *
2747
+ * On some platforms, when memory is low, malloc() may fail. In this
2748
+ * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
2749
+ * error condition will need to be handled as appropriate by the caller.
2750
+ *
2751
+ * You can avoid the need to handle this error condition if you ensure
2752
+ * that the storage you initially provide is large enough to hold all
2753
+ * the key/value pairs that are to be added to the record.
2754
+ * The caller can precompute the exact length required for all of the
2755
+ * key/value pairs to be added, or simply provide a fixed-sized buffer
2756
+ * known in advance to be large enough.
2757
+ * A no-value (key-only) key requires (1 + key length) bytes.
2758
+ * A key with empty value requires (1 + key length + 1) bytes.
2759
+ * A key with non-empty value requires (1 + key length + 1 + value length).
2760
+ * For most applications, DNS-SD TXT records are generally
2761
+ * less than 100 bytes, so in most cases a simple fixed-sized
2762
+ * 256-byte buffer will be more than sufficient.
2763
+ * Recommended size limits for DNS-SD TXT Records are discussed in RFC 6763
2764
+ * <https://tools.ietf.org/html/rfc6763#section-6.2>
2765
+ *
2766
+ * Note: When passing parameters to and from these TXT record APIs,
2767
+ * the key name does not include the '=' character. The '=' character
2768
+ * is the separator between the key and value in the on-the-wire
2769
+ * packet format; it is not part of either the key or the value.
2770
+ */
2771
+ DNSSD_EXPORT
2772
+ void DNSSD_API TXTRecordCreate
2773
+ (
2774
+ TXTRecordRef *txtRecord,
2775
+ uint16_t bufferLen,
2776
+ void *buffer
2777
+ );
2778
+
2779
+ /*!
2780
+ * @brief
2781
+ * Releases any resources allocated in the course of preparing a TXT Record
2782
+ * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
2783
+ * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
2784
+ *
2785
+ * @param txtRecord
2786
+ * A TXTRecordRef initialized by calling TXTRecordCreate().
2787
+ */
2788
+ DNSSD_EXPORT
2789
+ void DNSSD_API TXTRecordDeallocate
2790
+ (
2791
+ TXTRecordRef *txtRecord
2792
+ );
2793
+
2794
+ /*!
2795
+ * @brief
2796
+ * Adds a key (optionally with value) to a TXTRecordRef.
2797
+ *
2798
+ * @param txtRecord
2799
+ * A TXTRecordRef initialized by calling TXTRecordCreate().
2800
+ *
2801
+ * @param key
2802
+ * A null-terminated string which only contains printable ASCII
2803
+ * values (0x20-0x7E), excluding '=' (0x3D). Keys should be
2804
+ * 9 characters or fewer (not counting the terminating null).
2805
+ *
2806
+ * @param valueSize
2807
+ * The size of the value.
2808
+ *
2809
+ * @param value
2810
+ * Any binary value. For values that represent
2811
+ * textual data, UTF-8 is STRONGLY recommended.
2812
+ * For values that represent textual data, valueSize
2813
+ * should NOT include the terminating null (if any)
2814
+ * at the end of the string.
2815
+ * If NULL, then "key" will be added with no value.
2816
+ * If non-NULL but valueSize is zero, then "key=" will be
2817
+ * added with empty value.
2818
+ *
2819
+ * @result
2820
+ * Returns kDNSServiceErr_NoError on success.
2821
+ * Returns kDNSServiceErr_Invalid if the "key" string contains
2822
+ * illegal characters.
2823
+ * Returns kDNSServiceErr_NoMemory if adding this key would
2824
+ * exceed the available storage.
2825
+ *
2826
+ * @discussion
2827
+ * If the "key" already
2828
+ * exists in the TXTRecordRef, then the current value will be replaced with
2829
+ * the new value.
2830
+ * Keys may exist in four states with respect to a given TXT record:
2831
+ * - Absent (key does not appear at all)
2832
+ * - Present with no value ("key" appears alone)
2833
+ * - Present with empty value ("key=" appears in TXT record)
2834
+ * - Present with non-empty value ("key=value" appears in TXT record)
2835
+ * For more details refer to "Data Syntax for DNS-SD TXT Records" in RFC 6763
2836
+ * <https://tools.ietf.org/html/rfc6763#section-6>
2837
+ */
2838
+ DNSSD_EXPORT
2839
+ DNSServiceErrorType DNSSD_API TXTRecordSetValue
2840
+ (
2841
+ TXTRecordRef *txtRecord,
2842
+ const char *key,
2843
+ uint8_t valueSize, /* may be zero */
2844
+ const void *value /* may be NULL */
2845
+ );
2846
+
2847
+ /*!
2848
+ * @brief
2849
+ * Removes a key from a TXTRecordRef. The "key" must be an
2850
+ * ASCII string which exists in the TXTRecordRef.
2851
+ *
2852
+ * @param txtRecord
2853
+ * A TXTRecordRef initialized by calling TXTRecordCreate().
2854
+ *
2855
+ * @param key
2856
+ * A key name which exists in the TXTRecordRef.
2857
+ *
2858
+ * @result
2859
+ * Returns kDNSServiceErr_NoError on success.
2860
+ * Returns kDNSServiceErr_NoSuchKey if the "key" does not
2861
+ * exist in the TXTRecordRef.
2862
+ */
2863
+ DNSSD_EXPORT
2864
+ DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
2865
+ (
2866
+ TXTRecordRef *txtRecord,
2867
+ const char *key
2868
+ );
2869
+
2870
+ /*!
2871
+ * @brief
2872
+ * Allows you to determine the length of the raw bytes within a TXTRecordRef.
2873
+ *
2874
+ * @param txtRecord
2875
+ * A TXTRecordRef initialized by calling TXTRecordCreate().
2876
+ *
2877
+ * @result
2878
+ * Returns the size of the raw bytes inside a TXTRecordRef
2879
+ * which you can pass directly to DNSServiceRegister() or
2880
+ * to DNSServiceUpdateRecord().
2881
+ * Returns 0 if the TXTRecordRef is empty.
2882
+ */
2883
+ DNSSD_EXPORT
2884
+ uint16_t DNSSD_API TXTRecordGetLength
2885
+ (
2886
+ const TXTRecordRef *txtRecord
2887
+ );
2888
+
2889
+ /*!
2890
+ * @brief
2891
+ * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
2892
+ *
2893
+ * @param txtRecord
2894
+ * A TXTRecordRef initialized by calling TXTRecordCreate().
2895
+ *
2896
+ * @result
2897
+ * Returns a pointer to the raw bytes inside the TXTRecordRef
2898
+ * which you can pass directly to DNSServiceRegister() or
2899
+ * to DNSServiceUpdateRecord().
2900
+ */
2901
+ DNSSD_EXPORT
2902
+ const void * DNSSD_API TXTRecordGetBytesPtr
2903
+ (
2904
+ const TXTRecordRef *txtRecord
2905
+ );
2906
+
2907
+ /*********************************************************************************************
2908
+ *
2909
+ * TXT Record Parsing Functions
2910
+ *
2911
+ *********************************************************************************************/
2912
+
2913
+ /*
2914
+ * A typical calling sequence for TXT record parsing is something like:
2915
+ *
2916
+ * Receive TXT record data in DNSServiceResolve() callback
2917
+ * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
2918
+ * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
2919
+ * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
2920
+ * ...
2921
+ * memcpy(myval1, val1ptr, len1);
2922
+ * memcpy(myval2, val2ptr, len2);
2923
+ * ...
2924
+ * return;
2925
+ *
2926
+ * If you wish to retain the values after return from the DNSServiceResolve()
2927
+ * callback, then you need to copy the data to your own storage using memcpy()
2928
+ * or similar, as shown in the example above.
2929
+ *
2930
+ * If for some reason you need to parse a TXT record you built yourself
2931
+ * using the TXT record construction functions above, then you can do
2932
+ * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
2933
+ * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
2934
+ *
2935
+ * Most applications only fetch keys they know about from a TXT record and
2936
+ * ignore the rest.
2937
+ * However, some debugging tools wish to fetch and display all keys.
2938
+ * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
2939
+ */
2940
+
2941
+ /*!
2942
+ * @brief
2943
+ * Allows you to determine if a given TXT Record contains a specified key.
2944
+ *
2945
+ * @param txtLen
2946
+ * The size of the received TXT Record.
2947
+ *
2948
+ * @param txtRecord
2949
+ * Pointer to the received TXT Record bytes.
2950
+ *
2951
+ * @param key
2952
+ * A null-terminated ASCII string containing the key name.
2953
+ *
2954
+ * @result
2955
+ * Returns 1 if the TXT Record contains the specified key.
2956
+ * Otherwise, it returns 0.
2957
+ */
2958
+ DNSSD_EXPORT
2959
+ int DNSSD_API TXTRecordContainsKey
2960
+ (
2961
+ uint16_t txtLen,
2962
+ const void *txtRecord,
2963
+ const char *key
2964
+ );
2965
+
2966
+ /*!
2967
+ * @brief
2968
+ * Allows you to retrieve the value for a given key from a TXT Record.
2969
+ *
2970
+ * @param txtLen
2971
+ * The size of the received TXT Record
2972
+ *
2973
+ * @param txtRecord
2974
+ * Pointer to the received TXT Record bytes.
2975
+ *
2976
+ * @param key
2977
+ * A null-terminated ASCII string containing the key name.
2978
+ *
2979
+ * @param valueLen
2980
+ * On output, will be set to the size of the "value" data.
2981
+ *
2982
+ * @discussion
2983
+ * Returns NULL if the key does not exist in this TXT record,
2984
+ * or exists with no value (to differentiate between
2985
+ * these two cases use TXTRecordContainsKey()).
2986
+ * Returns pointer to location within TXT Record bytes
2987
+ * if the key exists with empty or non-empty value.
2988
+ * For empty value, valueLen will be zero.
2989
+ * For non-empty value, valueLen will be length of value data.
2990
+ */
2991
+ DNSSD_EXPORT
2992
+ const void * DNSSD_API TXTRecordGetValuePtr
2993
+ (
2994
+ uint16_t txtLen,
2995
+ const void *txtRecord,
2996
+ const char *key,
2997
+ uint8_t *valueLen
2998
+ );
2999
+
3000
+ /*!
3001
+ * @brief
3002
+ * Returns the number of keys stored in the TXT Record. The count
3003
+ * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
3004
+ *
3005
+ * @param txtLen
3006
+ * The size of the received TXT Record.
3007
+ *
3008
+ * @param txtRecord
3009
+ * Pointer to the received TXT Record bytes.
3010
+ *
3011
+ * @result
3012
+ * Returns the total number of keys in the TXT Record.
3013
+ */
3014
+ DNSSD_EXPORT
3015
+ uint16_t DNSSD_API TXTRecordGetCount
3016
+ (
3017
+ uint16_t txtLen,
3018
+ const void *txtRecord
3019
+ );
3020
+
3021
+ /*!
3022
+ * @brief
3023
+ * Allows you to retrieve a key name and value pointer, given an index into
3024
+ * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
3025
+ * It's also possible to iterate through keys in a TXT record by simply
3026
+ * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
3027
+ * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
3028
+ *
3029
+ *
3030
+ * @param txtLen
3031
+ * The size of the received TXT Record.
3032
+ *
3033
+ * @param txtRecord
3034
+ * Pointer to the received TXT Record bytes.
3035
+ *
3036
+ * @param itemIndex
3037
+ * An index into the TXT Record.
3038
+ *
3039
+ * @param keyBufLen
3040
+ * The size of the string buffer being supplied.
3041
+ *
3042
+ * @param key
3043
+ * A string buffer used to store the key name.
3044
+ * On return, the buffer contains a null-terminated C-string
3045
+ * giving the key name. DNS-SD TXT keys are usually
3046
+ * 9 characters or fewer. To hold the maximum possible
3047
+ * key name, the buffer should be 256 bytes long.
3048
+ *
3049
+ * @param valueLen
3050
+ * On output, will be set to the size of the "value" data.
3051
+ *
3052
+ * @param value
3053
+ * On output, *value is set to point to location within TXT
3054
+ * Record bytes that holds the value data.
3055
+ *
3056
+ * @result
3057
+ * Returns kDNSServiceErr_NoError on success.
3058
+ * Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
3059
+ * Returns kDNSServiceErr_Invalid if index is greater than
3060
+ * TXTRecordGetCount()-1.
3061
+ * On return:
3062
+ * For keys with no value, *value is set to NULL and *valueLen is zero.
3063
+ * For keys with empty value, *value is non-NULL and *valueLen is zero.
3064
+ * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
3065
+ */
3066
+ DNSSD_EXPORT
3067
+ DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
3068
+ (
3069
+ uint16_t txtLen,
3070
+ const void *txtRecord,
3071
+ uint16_t itemIndex,
3072
+ uint16_t keyBufLen,
3073
+ char *key,
3074
+ uint8_t *valueLen,
3075
+ const void **value
3076
+ );
3077
+
3078
+ #if _DNS_SD_LIBDISPATCH
3079
+ /*!
3080
+ * @brief
3081
+ * Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous
3082
+ * callbacks. It's the clients responsibility to ensure that the provided dispatch queue is running.
3083
+ *
3084
+ * @param service
3085
+ * DNSServiceRef that was allocated and returned to the application, when the
3086
+ * application calls one of the DNSService API.
3087
+ *
3088
+ * @param queue
3089
+ * dispatch queue where the application callback will be scheduled
3090
+ *
3091
+ * @result
3092
+ * Returns kDNSServiceErr_NoError on success.
3093
+ * Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source
3094
+ * Returns kDNSServiceErr_BadParam if the service param is invalid or the
3095
+ * queue param is invalid
3096
+ *
3097
+ * @discussion
3098
+ * A typical application that uses CFRunLoopRun or dispatch_main on its main thread will
3099
+ * usually schedule DNSServiceRefs on its main queue (which is always a serial queue)
3100
+ * using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());"
3101
+ *
3102
+ * If there is any error during the processing of events, the application callback will
3103
+ * be called with an error code. For shared connections, each subordinate DNSServiceRef
3104
+ * will get its own error callback. Currently these error callbacks only happen
3105
+ * if the daemon is manually terminated or crashes, and the error
3106
+ * code in this case is kDNSServiceErr_ServiceNotRunning. The application must call
3107
+ * DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code.
3108
+ * These error callbacks are rare and should not normally happen on customer machines,
3109
+ * but application code should be written defensively to handle such error callbacks
3110
+ * gracefully if they occur.
3111
+ *
3112
+ * After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult
3113
+ * on the same DNSServiceRef will result in undefined behavior and should be avoided.
3114
+ *
3115
+ * Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using
3116
+ * DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use
3117
+ * DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch
3118
+ * queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until
3119
+ * the application no longer requires that operation and terminates it using DNSServiceRefDeallocate.
3120
+ * Note that the call to DNSServiceRefDeallocate() must be done on the same queue originally passed
3121
+ * as an argument to DNSServiceSetDispatchQueue().
3122
+ */
3123
+ DNSSD_EXPORT
3124
+ DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue
3125
+ (
3126
+ DNSServiceRef service,
3127
+ dispatch_queue_t queue
3128
+ );
3129
+ #endif //_DNS_SD_LIBDISPATCH
3130
+
3131
+ #if !defined(_WIN32)
3132
+ typedef void (DNSSD_API *DNSServiceSleepKeepaliveReply)
3133
+ (
3134
+ DNSServiceRef sdRef,
3135
+ DNSServiceErrorType errorCode,
3136
+ void *context
3137
+ );
3138
+ DNSSD_EXPORT
3139
+ DNSServiceErrorType DNSSD_API DNSServiceSleepKeepalive
3140
+ (
3141
+ DNSServiceRef *sdRef,
3142
+ DNSServiceFlags flags,
3143
+ int fd,
3144
+ unsigned int timeout,
3145
+ DNSServiceSleepKeepaliveReply callBack,
3146
+ void *context
3147
+ );
3148
+ #endif
3149
+
3150
+ /* Some C compiler cleverness. We can make the compiler check certain things for us,
3151
+ * and report errors at compile-time if anything is wrong. The usual way to do this would
3152
+ * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
3153
+ * then you don't find out what's wrong until you run the software. This way, if the assertion
3154
+ * condition is false, the array size is negative, and the complier complains immediately.
3155
+ */
3156
+
3157
+ struct CompileTimeAssertionChecks_DNS_SD
3158
+ {
3159
+ char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1];
3160
+ };
3161
+
3162
+ #if (defined(__clang__) && __clang__)
3163
+ #pragma clang diagnostic pop
3164
+ #endif
3165
+
3166
+ /*!
3167
+ * @result
3168
+ * Returns a DNSServiceAttribute pointer.
3169
+ */
3170
+ #ifndef __OPEN_SOURCE__
3171
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
3172
+ #else
3173
+ DNSSD_EXPORT
3174
+ #endif
3175
+ DNSServiceAttributeRef DNSSD_API DNS_SD_NULLABLE DNSServiceAttributeCreate(void);
3176
+
3177
+ /*!
3178
+ * @brief
3179
+ * Set the aaaa_policy value in attr.
3180
+ *
3181
+ * @param attr
3182
+ * DNSServiceAttribute pointer.
3183
+ * @param policy
3184
+ * DNSServiceAAAAPolicy enum value.
3185
+ * @result
3186
+ * Returns kDNSServiceErr_NoError.
3187
+ */
3188
+ #ifndef __OPEN_SOURCE__
3189
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
3190
+ #else
3191
+ DNSSD_EXPORT
3192
+ #endif
3193
+ DNSServiceErrorType DNSSD_API DNSServiceAttributeSetAAAAPolicy
3194
+ (
3195
+ DNSServiceAttributeRef DNS_SD_NONNULL attr,
3196
+ DNSServiceAAAAPolicy policy
3197
+ );
3198
+
3199
+ /*!
3200
+ * @brief
3201
+ * Set the timestamp value in attr.
3202
+ * The host key hash must also be set in attr.
3203
+ *
3204
+ * @param attr
3205
+ * DNSServiceAttribute pointer.
3206
+ * @param timestamp
3207
+ * Relative time in seconds. Should be zero if the timestamp is now,
3208
+ * 30 if the timestamp is 30 seconds in the past, and so on.
3209
+ * @result
3210
+ * Returns kDNSServiceErr_NoError.
3211
+ */
3212
+ #ifndef __OPEN_SOURCE__
3213
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
3214
+ #else
3215
+ DNSSD_EXPORT
3216
+ #endif
3217
+ DNSServiceErrorType DNSSD_API DNSServiceAttributeSetTimestamp
3218
+ (
3219
+ DNSServiceAttributeRef DNS_SD_NONNULL attr,
3220
+ uint32_t timestamp
3221
+ );
3222
+
3223
+ /*!
3224
+ * @brief
3225
+ * Set the host key hash value in attr.
3226
+ * The timestamp attribute must also be set in attr.
3227
+ *
3228
+ * @param attr
3229
+ * DNSServiceAttribute pointer.
3230
+ * @param hostkeyhash
3231
+ * A 32-bit host key hash value.
3232
+ * @result
3233
+ * Returns kDNSServiceErr_NoError on success.
3234
+ */
3235
+ #ifndef __OPEN_SOURCE__
3236
+ DNS_SD_API_AVAILABLE(macos(15.0), ios(18.0), tvos(18.0), watchos(11.0))
3237
+ #else
3238
+ DNSSD_EXPORT
3239
+ #endif
3240
+ DNSServiceErrorType DNSSD_API DNSServiceAttributeSetHostKeyHash
3241
+ (
3242
+ DNSServiceAttributeRef DNS_SD_NONNULL attr,
3243
+ uint32_t hostkeyhash
3244
+ );
3245
+
3246
+ /*!
3247
+ * @brief
3248
+ * Free DNSServiceAttribute pointer pointed by attr,
3249
+ *
3250
+ * @param attr
3251
+ * An DNSServiceAttribute pointer(may be NULL).
3252
+ */
3253
+ #ifndef __OPEN_SOURCE__
3254
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
3255
+ #else
3256
+ DNSSD_EXPORT
3257
+ #endif
3258
+ void DNSSD_API DNSServiceAttributeDeallocate
3259
+ (
3260
+ DNSServiceAttributeRef DNS_SD_NONNULL attr
3261
+ );
3262
+
3263
+ /*!
3264
+ * @brief
3265
+ * DNSServiceQueryRecordWithAttribute is an extention to API DNSServiceQueryRecord,
3266
+ * accepting another parameter with type DNSServiceAttributeRef to specify extra attributes.
3267
+ *
3268
+ * @param sdRef
3269
+ * A pointer to an uninitialized DNSServiceRef
3270
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
3271
+ * a copy of the shared connection reference that is to be used).
3272
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
3273
+ * returns kDNSServiceErr_NoError, and the service registration
3274
+ * will remain active indefinitely until the client terminates it
3275
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
3276
+ * (or by closing the underlying shared connection, if used).
3277
+ *
3278
+ * @param flags
3279
+ * Possible values are:
3280
+ * kDNSServiceFlagsShareConnection to use a shared connection.
3281
+ * kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
3282
+ * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
3283
+ * query to a unicast DNS server that implements the protocol. This flag
3284
+ * has no effect on link-local multicast queries.
3285
+ *
3286
+ * @param ifindex
3287
+ * If non-zero, specifies the interface on which to register the service
3288
+ * (the index for a given interface is determined via the if_nametoindex()
3289
+ * family of calls.) Most applications will pass 0 to register on all
3290
+ * available interfaces. See "Constants for specifying an interface index" for more details.
3291
+ *
3292
+ * @param name
3293
+ * The full domain name of the resource record to be queried for.
3294
+ *
3295
+ * @param rrtype
3296
+ * The numerical type of the resource record to be queried for
3297
+ * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
3298
+ *
3299
+ * @param rrclass
3300
+ * The class of the resource record (usually kDNSServiceClass_IN).
3301
+ *
3302
+ * @param attr
3303
+ * An DNSServiceAttribute pointer which is used to specify the attribute
3304
+ * (may be NULL).
3305
+ *
3306
+ * @param callback
3307
+ * The function to be called when a result is found, or if the call
3308
+ * asynchronously fails.
3309
+ *
3310
+ * @param context
3311
+ * An application context pointer which is passed to the callback function
3312
+ * (may be NULL).
3313
+ *
3314
+ * @result
3315
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
3316
+ * errors are delivered to the callback), otherwise returns an error code indicating
3317
+ * the error that occurred (the callback is never invoked and the DNSServiceRef
3318
+ * is not initialized).
3319
+ *
3320
+ * @discussion
3321
+ * When atrr is NULL, the functionality of the this function will be the same as
3322
+ * DNSServiceQueryRecord().
3323
+ */
3324
+ #ifndef __OPEN_SOURCE__
3325
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
3326
+ #else
3327
+ DNSSD_EXPORT
3328
+ #endif
3329
+ DNSServiceErrorType DNSSD_API DNSServiceQueryRecordWithAttribute
3330
+ (
3331
+ DNSServiceRef DNS_SD_NONNULL * DNS_SD_NULLABLE sdRef,
3332
+ DNSServiceFlags flags,
3333
+ uint32_t ifindex,
3334
+ const char * DNS_SD_NULLABLE name,
3335
+ uint16_t rrtype,
3336
+ uint16_t rrclass,
3337
+ const DNSServiceAttribute * DNS_SD_NULLABLE attr,
3338
+ DNSServiceQueryRecordReply DNS_SD_NULLABLE callback,
3339
+ void * DNS_SD_NULLABLE context
3340
+ );
3341
+
3342
+ /*!
3343
+ * @brief
3344
+ * DNSServiceRegisterWithAttribute is an extention to API DNSServiceRegister,
3345
+ * accepting another parameter with type DNSServiceAttributeRef to specify extra attributes.
3346
+ *
3347
+ * @param sdRef
3348
+ * A pointer to an uninitialized DNSServiceRef
3349
+ * (or, if the kDNSServiceFlagsShareConnection flag is used,
3350
+ * a copy of the shared connection reference that is to be used).
3351
+ * If the call succeeds then it initializes (or updates) the DNSServiceRef,
3352
+ * returns kDNSServiceErr_NoError, and the service registration
3353
+ * will remain active indefinitely until the client terminates it
3354
+ * by passing this DNSServiceRef to DNSServiceRefDeallocate()
3355
+ * (or by closing the underlying shared connection, if used).
3356
+ *
3357
+ * @param flags
3358
+ * Possible values are:
3359
+ * kDNSServiceFlagsShareConnection to use a shared connection.
3360
+ * Other flags indicate the renaming behavior on name conflict
3361
+ * (not required for most applications).
3362
+ * See flag definitions above for details.
3363
+ *
3364
+ * @param interfaceIndex
3365
+ * If non-zero, specifies the interface on which to register the service
3366
+ * (the index for a given interface is determined via the if_nametoindex()
3367
+ * family of calls.) Most applications will pass 0 to register on all
3368
+ * available interfaces. See "Constants for specifying an interface index" for more details.
3369
+ *
3370
+ * @param name
3371
+ * If non-NULL, specifies the service name to be registered.
3372
+ * Most applications will not specify a name, in which case the computer
3373
+ * name is used (this name is communicated to the client via the callback).
3374
+ * If a name is specified, it must be 1-63 bytes of UTF-8 text.
3375
+ * If the name is longer than 63 bytes it will be automatically truncated
3376
+ * to a legal length, unless the NoAutoRename flag is set,
3377
+ * in which case kDNSServiceErr_BadParam will be returned.
3378
+ *
3379
+ * @param regtype
3380
+ * The service type followed by the protocol, separated by a dot
3381
+ * (e.g. "_ftp._tcp"). The service type must be an underscore, followed
3382
+ * by 1-15 characters, which may be letters, digits, or hyphens.
3383
+ * The transport protocol must be "_tcp" or "_udp". New service types
3384
+ * should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
3385
+ *
3386
+ * Additional subtypes of the primary service type (where a service
3387
+ * type has defined subtypes) follow the primary service type in a
3388
+ * comma-separated list, with no additional spaces, e.g.
3389
+ * "_primarytype._tcp,_subtype1,_subtype2,_subtype3"
3390
+ * Subtypes provide a mechanism for filtered browsing: A client browsing
3391
+ * for "_primarytype._tcp" will discover all instances of this type;
3392
+ * a client browsing for "_primarytype._tcp,_subtype2" will discover only
3393
+ * those instances that were registered with "_subtype2" in their list of
3394
+ * registered subtypes.
3395
+ *
3396
+ * The subtype mechanism can be illustrated with some examples using the
3397
+ * dns-sd command-line tool:
3398
+ *
3399
+ * % dns-sd -R Simple _test._tcp "" 1001 &
3400
+ * % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 &
3401
+ * % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 &
3402
+ *
3403
+ * Now:
3404
+ * % dns-sd -B _test._tcp # will find all three services
3405
+ * % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best"
3406
+ * % dns-sd -B _test._tcp,HasFeatureB # finds only "Best"
3407
+ *
3408
+ * Subtype labels may be up to 63 bytes long, and may contain any eight-
3409
+ * bit byte values, including zero bytes. However, due to the nature of
3410
+ * using a C-string-based API, conventional DNS escaping must be used for
3411
+ * dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below:
3412
+ *
3413
+ * % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123
3414
+ *
3415
+ * @param domain
3416
+ * If non-NULL, specifies the domain on which to advertise the service.
3417
+ * Most applications will not specify a domain, instead automatically
3418
+ * registering in the default domain(s).
3419
+ *
3420
+ * @param host
3421
+ * If non-NULL, specifies the SRV target host name. Most applications
3422
+ * will not specify a host, instead automatically using the machine's
3423
+ * default host name(s). Note that specifying a non-NULL host does NOT
3424
+ * create an address record for that host - the application is responsible
3425
+ * for ensuring that the appropriate address record exists, or creating it
3426
+ * via DNSServiceRegisterRecord().
3427
+ *
3428
+ * @param PortInNetworkByteOrder
3429
+ * The port, in network byte order, on which the service accepts connections.
3430
+ * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
3431
+ * by browsing, but will cause a name conflict if another client tries to
3432
+ * register that same name). Most clients will not use placeholder services.
3433
+ *
3434
+ * @param txtLen
3435
+ * The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
3436
+ *
3437
+ * @param txtRecord
3438
+ * The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
3439
+ * TXT record, i.e. <length byte> <data> <length byte> <data> ...
3440
+ * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
3441
+ * i.e. it creates a TXT record of length one containing a single empty string.
3442
+ * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
3443
+ * string is the smallest legal DNS TXT record.
3444
+ * As with the other parameters, the DNSServiceRegister call copies the txtRecord
3445
+ * data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
3446
+ * then you can safely free that memory right after the DNSServiceRegister call returns.
3447
+ *
3448
+ * @param attr
3449
+ * An DNSServiceAttribute pointer which is used to specify the attribute
3450
+ * (may be NULL).
3451
+ *
3452
+ * @param callBack
3453
+ * The function to be called when the registration completes or asynchronously
3454
+ * fails. The client MAY pass NULL for the callback - The client will NOT be notified
3455
+ * of the default values picked on its behalf, and the client will NOT be notified of any
3456
+ * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
3457
+ * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
3458
+ * The client may still deregister the service at any time via DNSServiceRefDeallocate().
3459
+ *
3460
+ * @param context
3461
+ * An application context pointer which is passed to the callback function
3462
+ * (may be NULL).
3463
+ *
3464
+ * @result
3465
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
3466
+ * errors are delivered to the callback), otherwise returns an error code indicating
3467
+ * the error that occurred (the callback is never invoked and the DNSServiceRef
3468
+ * is not initialized).
3469
+ *
3470
+ * @discussion
3471
+ * When atrr is NULL, the functionality of the this function will be the same as
3472
+ * DNSServiceRegister().
3473
+ */
3474
+ #ifndef __OPEN_SOURCE__
3475
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
3476
+ #else
3477
+ DNSSD_EXPORT
3478
+ #endif
3479
+ DNSServiceErrorType DNSSD_API DNSServiceRegisterWithAttribute
3480
+ (
3481
+ DNSServiceRef DNS_SD_NONNULL * DNS_SD_NULLABLE sdRef,
3482
+ DNSServiceFlags flags,
3483
+ uint32_t interfaceIndex,
3484
+ const char * DNS_SD_NULLABLE name,
3485
+ const char * DNS_SD_NULLABLE regtype,
3486
+ const char * DNS_SD_NULLABLE domain,
3487
+ const char * DNS_SD_NULLABLE host,
3488
+ uint16_t portInNetworkByteOrder,
3489
+ uint16_t txtLen,
3490
+ const void * DNS_SD_NULLABLE txtRecord,
3491
+ const DNSServiceAttributeRef DNS_SD_NULLABLE attr,
3492
+ DNSServiceRegisterReply DNS_SD_NULLABLE callBack,
3493
+ void * DNS_SD_NULLABLE context
3494
+ );
3495
+
3496
+ /*!
3497
+ * @brief
3498
+ * DNSServiceRegisterRecordWithAttribute is an extention to API DNSServiceRegisterRecord,
3499
+ * accepting another parameter with type DNSServiceAttributeRef to specify extra attributes.
3500
+ *
3501
+ * @param sdRef
3502
+ * The connected DNSServiceRef that was initialized by DNSServiceCreateConnection().
3503
+ *
3504
+ * @param flags
3505
+ * Required values are:
3506
+ * One of kDNSServiceFlagsShared, kDNSServiceFlagsUnique or kDNSServiceFlagsKnownUnique flags.
3507
+ *
3508
+ * Possible values are:
3509
+ * kDNSServiceFlagsForceMulticast: If it is specified, the registration will be performed just like
3510
+ * a link-local mDNS registration even if the name is an apparently non-local name (i.e. a name not
3511
+ * ending in ".local.")
3512
+ *
3513
+ * @param interfaceIndex
3514
+ * If non-zero, specifies the interface on which to register the record
3515
+ * (the index for a given interface is determined via the if_nametoindex()
3516
+ * family of calls.) Passing 0 causes the record to be registered on all interfaces.
3517
+ * See "Constants for specifying an interface index" for more details.
3518
+ *
3519
+ * @param fullname
3520
+ * The full domain name of the resource record.
3521
+ *
3522
+ * @param rrtype
3523
+ * The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
3524
+ *
3525
+ * @param rrclass
3526
+ * The class of the resource record (usually kDNSServiceClass_IN)
3527
+ *
3528
+ * @param rdlen
3529
+ * Length, in bytes, of the rdata.
3530
+ *
3531
+ * @param rdata
3532
+ * A pointer to the raw rdata, as it is to appear in the DNS record.
3533
+ *
3534
+ * @param ttl
3535
+ * The time to live of the resource record, in seconds.
3536
+ * Most clients should pass 0 to indicate that the system should
3537
+ * select a sensible default value.
3538
+ *
3539
+ * @param attr
3540
+ * An DNSServiceAttribute pointer which is used to specify the attribute
3541
+ * (may be NULL).
3542
+ *
3543
+ * @param callBack
3544
+ * The function to be called when a result is found, or if the call
3545
+ * asynchronously fails (e.g. because of a name conflict.)
3546
+ *
3547
+ * @param context
3548
+ * An application context pointer which is passed to the callback function
3549
+ * (may be NULL).
3550
+ *
3551
+ * @result
3552
+ * Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
3553
+ * errors are delivered to the callback), otherwise returns an error code indicating
3554
+ * the error that occurred (the callback is never invoked and the DNSServiceRef
3555
+ * is not initialized).
3556
+ *
3557
+ * @discussion
3558
+ * When atrr is NULL, the functionality of the this function will be the same as
3559
+ * DNSServiceRegister().
3560
+ */
3561
+ #ifndef __OPEN_SOURCE__
3562
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
3563
+ #else
3564
+ DNSSD_EXPORT
3565
+ #endif
3566
+ DNSServiceErrorType DNSSD_API DNSServiceRegisterRecordWithAttribute
3567
+ (
3568
+ DNSServiceRef DNS_SD_NULLABLE sdRef,
3569
+ DNSRecordRef DNS_SD_NONNULL * DNS_SD_NULLABLE recordRef,
3570
+ DNSServiceFlags flags,
3571
+ uint32_t interfaceIndex,
3572
+ const char * DNS_SD_NULLABLE fullname,
3573
+ uint16_t rrtype,
3574
+ uint16_t rrclass,
3575
+ uint16_t rdlen,
3576
+ const void * DNS_SD_NULLABLE rdata,
3577
+ uint32_t ttl,
3578
+ const DNSServiceAttributeRef DNS_SD_NULLABLE attr,
3579
+ DNSServiceRegisterRecordReply DNS_SD_NULLABLE callBack,
3580
+ void * DNS_SD_NULLABLE context
3581
+ );
3582
+
3583
+ /*!
3584
+ * @brief
3585
+ * Send all the queued requests to server in scatter/gather IO.
3586
+ *
3587
+ * @param sdRef
3588
+ * The connected DNSServiceRef that was initialized by DNSServiceCreateConnection.
3589
+ *
3590
+ * @result
3591
+ * Returns kDNSServiceErr_NoError on success;
3592
+ * Returns kDNSServiceErr_BadParam if the DNSServiceRef is not initialized;
3593
+ * Returns kDNSServiceErr_Invalid if there is no queued request;
3594
+ * Returns kDNSServiceErr_NoMemory if memory allocation fail.
3595
+ *
3596
+ * @discussion
3597
+ * The queued requests will be freed in this function.
3598
+ * Example of usage:
3599
+ * DNSServiceCreateConnection(sdRef) //create DNSServiceRef
3600
+ * DNSServiceRegisterRecord with flag kDNSServiceFlagsQueueRequest //create and queue request
3601
+ * DNSServiceRegisterRecord with flag kDNSServiceFlagsQueueRequest //create and queue another request
3602
+ * DNSServiceSendQueuedRequests(sdRef) //send the queued requests
3603
+ */
3604
+ #ifndef __OPEN_SOURCE__
3605
+ DNS_SD_API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
3606
+ #else
3607
+ DNSSD_EXPORT
3608
+ #endif
3609
+ DNSServiceErrorType DNSSD_API DNSServiceSendQueuedRequests
3610
+ (
3611
+ DNSServiceRef DNS_SD_NULLABLE sdRef
3612
+ );
3613
+
3614
+ __END_DECLS
3615
+
3616
+ #endif /* _DNS_SD_H */