2 * Copyright (c) 2000, 2001, 2003-2007, 2018 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * January 19, 2003 Allan Nathanson <ajn@apple.com>
28 * - add advanced reachability APIs
30 * June 10, 2001 Allan Nathanson <ajn@apple.com>
31 * - updated to use service-based "State:" information
33 * June 1, 2001 Allan Nathanson <ajn@apple.com>
34 * - public API conversion
36 * January 30, 2001 Allan Nathanson <ajn@apple.com>
40 #include <sys/types.h>
41 #include <netinet/in.h>
43 #include <sys/socket.h>
45 #include <SystemConfiguration/SystemConfiguration.h>
46 #include <SystemConfiguration/SCPrivate.h>
49 SCNetworkCheckReachabilityByAddress(const struct sockaddr
*address
,
51 SCNetworkConnectionFlags
*flags
)
53 SCNetworkReachabilityRef networkAddress
;
55 struct sockaddr_storage ss
;
59 (addrlen
> (int)sizeof(struct sockaddr_storage
))) {
60 _SCErrorSet(kSCStatusInvalidArgument
);
64 memset(&ss
, 0, sizeof(ss
));
65 memcpy(&ss
, address
, addrlen
);
68 networkAddress
= SCNetworkReachabilityCreateWithAddress(NULL
, (struct sockaddr
*)&ss
);
69 if (networkAddress
== NULL
) {
73 ok
= SCNetworkReachabilityGetFlags(networkAddress
, flags
);
74 CFRelease(networkAddress
);
80 SCNetworkCheckReachabilityByName(const char *nodename
,
81 SCNetworkConnectionFlags
*flags
)
83 SCNetworkReachabilityRef networkAddress
;
87 _SCErrorSet(kSCStatusInvalidArgument
);
91 networkAddress
= SCNetworkReachabilityCreateWithName(NULL
, nodename
);
92 if (networkAddress
== NULL
) {
96 ok
= SCNetworkReachabilityGetFlags(networkAddress
, flags
);
97 CFRelease(networkAddress
);