]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetwork.c
configd-84.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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26 /*
27 * Modification History
28 *
29 * January 19, 2003 Allan Nathanson <ajn@apple.com>
30 * - add advanced reachability APIs
31 *
32 * June 10, 2001 Allan Nathanson <ajn@apple.com>
33 * - updated to use service-based "State:" information
34 *
35 * June 1, 2001 Allan Nathanson <ajn@apple.com>
36 * - public API conversion
37 *
38 * January 30, 2001 Allan Nathanson <ajn@apple.com>
39 * - initial revision
40 */
41
42 #include <sys/types.h>
43 #include <netinet/in.h>
44 #include <unistd.h>
45 #include <sys/socket.h>
46
47 #include <SystemConfiguration/SystemConfiguration.h>
48 #include <SystemConfiguration/SCPrivate.h>
49
50 #ifndef kSCEntNetRefreshConfiguration
51 #define kSCEntNetRefreshConfiguration CFSTR("RefreshConfiguration")
52 #endif kSCEntNetRefreshConfiguration
53
54 Boolean
55 SCNetworkCheckReachabilityByAddress(const struct sockaddr *address,
56 const int addrlen,
57 SCNetworkConnectionFlags *flags)
58 {
59 SCNetworkReachabilityRef networkAddress;
60 Boolean ok;
61 struct sockaddr_storage ss;
62
63 if (!address ||
64 (addrlen == 0) ||
65 (addrlen > (int)sizeof(struct sockaddr_storage))) {
66 _SCErrorSet(kSCStatusInvalidArgument);
67 return FALSE;
68 }
69
70 bzero(&ss, sizeof(ss));
71 bcopy(address, &ss, addrlen);
72 ss.ss_len = addrlen;
73
74 networkAddress = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&ss);
75 ok = SCNetworkReachabilityGetFlags(networkAddress, flags);
76 CFRelease(networkAddress);
77 return ok;
78 }
79
80
81 Boolean
82 SCNetworkCheckReachabilityByName(const char *nodename,
83 SCNetworkConnectionFlags *flags)
84 {
85 SCNetworkReachabilityRef networkAddress;
86 Boolean ok;
87
88 if (!nodename) {
89 _SCErrorSet(kSCStatusInvalidArgument);
90 return FALSE;
91 }
92
93 networkAddress = SCNetworkReachabilityCreateWithName(NULL, nodename);
94 ok = SCNetworkReachabilityGetFlags(networkAddress, flags);
95 CFRelease(networkAddress);
96 return ok;
97 }
98
99 Boolean
100 SCNetworkInterfaceRefreshConfiguration(CFStringRef ifName)
101 {
102 CFStringRef key;
103 Boolean ret = FALSE;
104 SCDynamicStoreRef store = NULL;
105
106 store = SCDynamicStoreCreate(NULL,
107 CFSTR("SCNetworkInterfaceRefreshConfiguration"),
108 NULL, NULL);
109 if (store == NULL) {
110 goto done;
111 }
112 key = SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL,
113 kSCDynamicStoreDomainState,
114 ifName,
115 kSCEntNetRefreshConfiguration);
116 ret = SCDynamicStoreNotifyValue(store, key);
117 CFRelease(key);
118
119 done:
120 if (store != NULL) {
121 CFRelease(store);
122 }
123 return (ret);
124 }