]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetwork.c
configd-84.6.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCNetwork.c
1 /*
2 * Copyright (c) 2000-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
24 /*
25 * Modification History
26 *
27 * January 19, 2003 Allan Nathanson <ajn@apple.com>
28 * - add advanced reachability APIs
29 *
30 * June 10, 2001 Allan Nathanson <ajn@apple.com>
31 * - updated to use service-based "State:" information
32 *
33 * June 1, 2001 Allan Nathanson <ajn@apple.com>
34 * - public API conversion
35 *
36 * January 30, 2001 Allan Nathanson <ajn@apple.com>
37 * - initial revision
38 */
39
40 #include <sys/types.h>
41 #include <netinet/in.h>
42 #include <unistd.h>
43 #include <sys/socket.h>
44
45 #include <SystemConfiguration/SystemConfiguration.h>
46 #include <SystemConfiguration/SCPrivate.h>
47
48 #ifndef kSCEntNetRefreshConfiguration
49 #define kSCEntNetRefreshConfiguration CFSTR("RefreshConfiguration")
50 #endif kSCEntNetRefreshConfiguration
51
52 Boolean
53 SCNetworkCheckReachabilityByAddress(const struct sockaddr *address,
54 const int addrlen,
55 SCNetworkConnectionFlags *flags)
56 {
57 SCNetworkReachabilityRef networkAddress;
58 Boolean ok;
59 struct sockaddr_storage ss;
60
61 if (!address ||
62 (addrlen == 0) ||
63 (addrlen > (int)sizeof(struct sockaddr_storage))) {
64 _SCErrorSet(kSCStatusInvalidArgument);
65 return FALSE;
66 }
67
68 bzero(&ss, sizeof(ss));
69 bcopy(address, &ss, addrlen);
70 ss.ss_len = addrlen;
71
72 networkAddress = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&ss);
73 ok = SCNetworkReachabilityGetFlags(networkAddress, flags);
74 CFRelease(networkAddress);
75 return ok;
76 }
77
78
79 Boolean
80 SCNetworkCheckReachabilityByName(const char *nodename,
81 SCNetworkConnectionFlags *flags)
82 {
83 SCNetworkReachabilityRef networkAddress;
84 Boolean ok;
85
86 if (!nodename) {
87 _SCErrorSet(kSCStatusInvalidArgument);
88 return FALSE;
89 }
90
91 networkAddress = SCNetworkReachabilityCreateWithName(NULL, nodename);
92 ok = SCNetworkReachabilityGetFlags(networkAddress, flags);
93 CFRelease(networkAddress);
94 return ok;
95 }
96
97 Boolean
98 SCNetworkInterfaceRefreshConfiguration(CFStringRef ifName)
99 {
100 CFStringRef key;
101 Boolean ret = FALSE;
102 SCDynamicStoreRef store = NULL;
103
104 store = SCDynamicStoreCreate(NULL,
105 CFSTR("SCNetworkInterfaceRefreshConfiguration"),
106 NULL, NULL);
107 if (store == NULL) {
108 goto done;
109 }
110 key = SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL,
111 kSCDynamicStoreDomainState,
112 ifName,
113 kSCEntNetRefreshConfiguration);
114 ret = SCDynamicStoreNotifyValue(store, key);
115 CFRelease(key);
116
117 done:
118 if (store != NULL) {
119 CFRelease(store);
120 }
121 return (ret);
122 }