]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetwork.c
configd-130.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;
103
104 store = SCDynamicStoreCreate(NULL,
105 CFSTR("SCNetworkInterfaceRefreshConfiguration"),
106 NULL, NULL);
107 if (store == NULL) {
108 return FALSE;
109 }
110
111 key = SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL,
112 kSCDynamicStoreDomainState,
113 ifName,
114 kSCEntNetRefreshConfiguration);
115 ret = SCDynamicStoreNotifyValue(store, key);
116 CFRelease(key);
117 CFRelease(store);
118 return (ret);
119 }