SCNetworkReachability.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. {
  2. * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://www.opensource.apple.com/apsl/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY of ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES of MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. }
  23. { Pascal Translation: Peter N Lewis, <[email protected]>, 2004 }
  24. {
  25. Modified for use with Free Pascal
  26. Version 200
  27. Please report any bugs to <[email protected]>
  28. }
  29. {$mode macpas}
  30. {$packenum 1}
  31. {$macro on}
  32. {$inline on}
  33. {$CALLING MWPASCAL}
  34. unit SCNetworkReachability;
  35. interface
  36. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  37. {$setc GAP_INTERFACES_VERSION := $0200}
  38. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  39. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  40. {$endc}
  41. {$ifc defined CPUPOWERPC and defined CPUI386}
  42. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  43. {$endc}
  44. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  45. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  46. {$endc}
  47. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  48. {$setc __ppc__ := 1}
  49. {$elsec}
  50. {$setc __ppc__ := 0}
  51. {$endc}
  52. {$ifc not defined __i386__ and defined CPUI386}
  53. {$setc __i386__ := 1}
  54. {$elsec}
  55. {$setc __i386__ := 0}
  56. {$endc}
  57. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  58. {$error Conflicting definitions for __ppc__ and __i386__}
  59. {$endc}
  60. {$ifc defined __ppc__ and __ppc__}
  61. {$setc TARGET_CPU_PPC := TRUE}
  62. {$setc TARGET_CPU_X86 := FALSE}
  63. {$elifc defined __i386__ and __i386__}
  64. {$setc TARGET_CPU_PPC := FALSE}
  65. {$setc TARGET_CPU_X86 := TRUE}
  66. {$elsec}
  67. {$error Neither __ppc__ nor __i386__ is defined.}
  68. {$endc}
  69. {$setc TARGET_CPU_PPC_64 := FALSE}
  70. {$ifc defined FPC_BIG_ENDIAN}
  71. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  72. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  73. {$elifc defined FPC_LITTLE_ENDIAN}
  74. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  75. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  76. {$elsec}
  77. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  78. {$endc}
  79. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  80. {$setc CALL_NOT_IN_CARBON := FALSE}
  81. {$setc OLDROUTINENAMES := FALSE}
  82. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  83. {$setc OPAQUE_UPP_TYPES := TRUE}
  84. {$setc OTCARBONAPPLICATION := TRUE}
  85. {$setc OTKERNEL := FALSE}
  86. {$setc PM_USE_SESSION_APIS := TRUE}
  87. {$setc TARGET_API_MAC_CARBON := TRUE}
  88. {$setc TARGET_API_MAC_OS8 := FALSE}
  89. {$setc TARGET_API_MAC_OSX := TRUE}
  90. {$setc TARGET_CARBON := TRUE}
  91. {$setc TARGET_CPU_68K := FALSE}
  92. {$setc TARGET_CPU_MIPS := FALSE}
  93. {$setc TARGET_CPU_SPARC := FALSE}
  94. {$setc TARGET_OS_MAC := TRUE}
  95. {$setc TARGET_OS_UNIX := FALSE}
  96. {$setc TARGET_OS_WIN32 := FALSE}
  97. {$setc TARGET_RT_MAC_68881 := FALSE}
  98. {$setc TARGET_RT_MAC_CFM := FALSE}
  99. {$setc TARGET_RT_MAC_MACHO := TRUE}
  100. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  101. {$setc TYPE_BOOL := FALSE}
  102. {$setc TYPE_EXTENDED := FALSE}
  103. {$setc TYPE_LONGLONG := TRUE}
  104. uses MacTypes,CFBase,SCNetwork,MacOSXPosix,CFRunLoop;
  105. {$ALIGN MAC68K}
  106. {!
  107. @header SCNetworkReachability
  108. The SCNetworkReachabilityXXX() APIs allow an application to determine the status
  109. of a system's current network configuration and the reachability
  110. of a target host. In addition, the reachability can be monitored
  111. with a notification being provided when/if the status has changed.
  112. The term "reachable" reflects whether a data packet, sent by
  113. an application into the network stack, can be sent to the
  114. the target host/address. Please note that there is no
  115. guarantee that the data packet will actually be received by
  116. the host.
  117. }
  118. {!
  119. @typedef SCNetworkReachabilityRef
  120. @discussion This is the handle to a network address/name.
  121. }
  122. type
  123. SCNetworkReachabilityRef = ^SInt32; { an opaque 32-bit type }
  124. {!
  125. @typedef SCNetworkReachabilityContext
  126. }
  127. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  128. type
  129. SCNetworkReachabilityContext = record
  130. version: CFIndex;
  131. info: Ptr;
  132. retain: function( info: Ptr ): Ptr;
  133. release: procedure( info: Ptr );
  134. copyDescription: function( info: Ptr ): CFStringRef;
  135. end;
  136. SCNetworkReachabilityContextPtr = ^SCNetworkReachabilityContext;
  137. {!
  138. @typedef SCNetworkReachabilityCallBack
  139. @discussion Type of the callback function used when the
  140. reachability of a network address/name changes.
  141. @param target The SCNetworkReachability reference being monitored for changes.
  142. @param flags The new SCNetworkConnectionFlags representing the
  143. reachability status of the network address/name.
  144. @param info ....
  145. }
  146. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  147. type SCNetworkReachabilityCallBack = procedure( target: SCNetworkReachabilityRef; flags: SCNetworkConnectionFlags; info: UnivPtr );
  148. {!
  149. @function SCNetworkReachabilityCreateWithAddress
  150. @discussion Creates a reference to the specified network
  151. address. This reference can later be used to monitor
  152. the reachability of the target host.
  153. @param address The address of the desired host.
  154. @result A reference to the new immutable SCNetworkReachabilityRef.
  155. You must release the returned value.
  156. }
  157. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  158. function SCNetworkReachabilityCreateWithAddress( allocator: CFAllocatorRef; address: sockaddr_ptr ): SCNetworkReachabilityRef; external name '_SCNetworkReachabilityCreateWithAddress';
  159. {!
  160. @function SCNetworkReachabilityCreateWithAddressPair
  161. @discussion Creates a reference to the specified network
  162. address. This reference can later be used to monitor
  163. the reachability of the target host.
  164. @param localAddress The local address associated with a network
  165. connection. If NULL, only the remote address is of interest.
  166. @param remoteAddress The remote address associated with a network
  167. connection. If NULL, only the local address is of interest.
  168. @result A reference to the new immutable SCNetworkReachabilityRef.
  169. You must release the returned value.
  170. }
  171. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  172. function SCNetworkReachabilityCreateWithAddressPair( allocator: CFAllocatorRef; localAddress: sockaddr_ptr; remoteAddress: sockaddr_ptr ): SCNetworkReachabilityRef; external name '_SCNetworkReachabilityCreateWithAddressPair';
  173. {!
  174. @function SCNetworkReachabilityCreateWithName
  175. @discussion Creates a reference to the specified network host/node
  176. name. This reference can later be used to monitor the
  177. reachability of the target host.
  178. @param nodename The node name of the desired host. This name would
  179. be the same as that passed to gethostbyname() or getaddrinfo().
  180. @result A reference to the new immutable SCNetworkReachabilityRef.
  181. You must release the returned value.
  182. }
  183. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  184. function SCNetworkReachabilityCreateWithName( allocator: CFAllocatorRef; nodename: CStringPtr ): SCNetworkReachabilityRef; external name '_SCNetworkReachabilityCreateWithName';
  185. {!
  186. @function SCNetworkReachabilityGetTypeID
  187. Returns the type identifier of all SCNetworkReachability instances.
  188. }
  189. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  190. function SCNetworkReachabilityGetTypeID: CFTypeID; external name '_SCNetworkReachabilityGetTypeID';
  191. {!
  192. @function SCNetworkReachabilityGetFlags
  193. @discussion Determines if the given target is reachable using the
  194. current network configuration.
  195. @param target The network reference associated with the address/name
  196. to be checked for reachability.
  197. @param flags A pointer to memory that will be filled with the
  198. SCNetworkConnectionFlags detailing the reachability
  199. of the specified target.
  200. @result TRUE if the network connection flags are valid; FALSE if the
  201. status could not be determined.
  202. }
  203. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  204. function SCNetworkReachabilityGetFlags( target: SCNetworkReachabilityRef; var flags: SCNetworkConnectionFlags ): Boolean; external name '_SCNetworkReachabilityGetFlags';
  205. {!
  206. @function SCNetworkReachabilitySetCallback
  207. @discussion Assigns a client to a target, which receives callbacks
  208. when the reachability of the target changes.
  209. @param target The network reference associated with the address/name
  210. to be checked for reachability.
  211. @param callout The function to be called when the reachability of
  212. target changes. If NULL, the current client for the target
  213. is removed.
  214. @param context The SCNetworkReachabilityContext associated with
  215. the callout.
  216. @result TRUE if the notification client was successfully set.
  217. }
  218. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  219. function SCNetworkReachabilitySetCallback( target: SCNetworkReachabilityRef; callout: SCNetworkReachabilityCallBack; var context: SCNetworkReachabilityContext ): Boolean; external name '_SCNetworkReachabilitySetCallback';
  220. {!
  221. @function SCNetworkReachabilityScheduleWithRunLoop
  222. @discussion Schedule the given target from the given run loop and mode.
  223. @param target The address/name which is set up for asynchronous mode. Must be non-NULL.
  224. @param runLoop A reference to a runloop on which the target should be scheduled. Must be non-NULL.
  225. @param runLoopMode The mode on which to schedule the target. Must be non-NULL.
  226. }
  227. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  228. function SCNetworkReachabilityScheduleWithRunLoop( target: SCNetworkReachabilityRef; runLoop: CFRunLoopRef; runLoopMode: CFStringRef ): Boolean; external name '_SCNetworkReachabilityScheduleWithRunLoop';
  229. {!
  230. @function SCNetworkReachabilityUnscheduleFromRunLoop
  231. @discussion Unschedule the given target from the given run loop and mode.
  232. @param target The address/name which is set up for asynchronous mode. Must be non-NULL.
  233. @param runLoop A reference to a runloop on which the target should be scheduled. Must be non-NULL.
  234. @param runLoopMode The mode on which to schedule the target. Must be non-NULL.
  235. }
  236. // AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
  237. function SCNetworkReachabilityUnscheduleFromRunLoop( target: SCNetworkReachabilityRef; runLoop: CFRunLoopRef; runLoopMode: CFStringRef ): Boolean; external name '_SCNetworkReachabilityUnscheduleFromRunLoop';
  238. end.