]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/reachability/client.c
configd-453.16.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / reachability / client.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <CoreFoundation/CoreFoundation.h>
5 #include <SystemConfiguration/SystemConfiguration.h>
6 #include <SystemConfiguration/SCPrivate.h>
7
8 #include "SCNetworkReachabilityInternal.h"
9
10 int
11 main(int argc, char **argv)
12 {
13 Boolean ok;
14 SCNetworkReachabilityRef target1;
15 SCNetworkReachabilityRef target2;
16 SCNetworkReachabilityRef target3;
17 SCNetworkReachabilityRef target4;
18 SCNetworkReachabilityRef target5;
19
20 _sc_log = FALSE;
21 _sc_debug = TRUE; // extra reachability logging
22
23 target1 = SCNetworkReachabilityCreateWithName(NULL, "web.apple.com");
24 ok = __SCNetworkReachabilityServer_targetAdd(target1);
25 if (!ok) {
26 SCLog(TRUE, LOG_ERR, CFSTR("No reachability server"));
27 exit(1);
28 }
29
30 target2 = SCNetworkReachabilityCreateWithName(NULL, "www.comcast.net");
31 __SCNetworkReachabilityServer_targetAdd(target2);
32
33 target3 = SCNetworkReachabilityCreateWithName(NULL, "www.comcast.net");
34 __SCNetworkReachabilityServer_targetAdd(target3);
35
36 target4 = SCNetworkReachabilityCreateWithName(NULL, "www.nonexistenthost.com");
37 __SCNetworkReachabilityServer_targetAdd(target4);
38
39 target5 = SCNetworkReachabilityCreateWithName(NULL, "www.washingtonpost.com");
40 __SCNetworkReachabilityServer_targetAdd(target5);
41
42 __SCNetworkReachabilityServer_targetStatus(target1);
43 __SCNetworkReachabilityServer_targetStatus(target2);
44 __SCNetworkReachabilityServer_targetStatus(target3);
45 __SCNetworkReachabilityServer_targetStatus(target4);
46
47 __SCNetworkReachabilityServer_targetMonitor(target1, TRUE);
48 __SCNetworkReachabilityServer_targetMonitor(target4, TRUE);
49 __SCNetworkReachabilityServer_targetMonitor(target5, TRUE);
50
51 __SCNetworkReachabilityServer_targetStatus(target4);
52 __SCNetworkReachabilityServer_targetStatus(target3);
53 __SCNetworkReachabilityServer_targetStatus(target2);
54 __SCNetworkReachabilityServer_targetStatus(target1);
55
56 sleep(2);
57
58 __SCNetworkReachabilityServer_targetStatus(target1);
59 __SCNetworkReachabilityServer_targetStatus(target4);
60 __SCNetworkReachabilityServer_targetStatus(target1);
61 __SCNetworkReachabilityServer_targetStatus(target4);
62
63 __SCNetworkReachabilityServer_targetMonitor(target1, FALSE);
64
65 __SCNetworkReachabilityServer_targetStatus(target1);
66 __SCNetworkReachabilityServer_targetStatus(target4);
67 __SCNetworkReachabilityServer_targetStatus(target1);
68 __SCNetworkReachabilityServer_targetStatus(target4);
69
70 __SCNetworkReachabilityServer_targetMonitor(target4, FALSE);
71
72 __SCNetworkReachabilityServer_targetStatus(target1);
73 __SCNetworkReachabilityServer_targetStatus(target4);
74
75 // SCLog(TRUE, LOG_DEBUG, CFSTR("starting CFRunLoop"));
76 // CFRunLoopRun();
77 // SCLog(TRUE, LOG_DEBUG, CFSTR("CFRunLoop complete"));
78
79 SCLog(TRUE, LOG_DEBUG, CFSTR("sleeping"));
80 sleep(60);
81
82 __SCNetworkReachabilityServer_targetStatus(target5);
83 __SCNetworkReachabilityServer_targetRemove(target5);
84 CFRelease(target5);
85
86 __SCNetworkReachabilityServer_targetRemove(target4);
87 CFRelease(target4);
88
89 __SCNetworkReachabilityServer_targetRemove(target3);
90 CFRelease(target3);
91
92 // __SCNetworkReachabilityServer_targetRemove(target2);
93 // CFRelease(target2);
94
95 // __SCNetworkReachabilityServer_targetRemove(target1);
96 // CFRelease(target1);
97
98 exit(0);
99 }
100