BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file arpprobe_test.c |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | #include <stddef.h> |
||
31 | #include <sys/socket.h> |
||
32 | #include <netinet/in.h> |
||
33 | #include <arpa/inet.h> |
||
34 | |||
35 | #include <misc/debug.h> |
||
36 | #include <base/DebugObject.h> |
||
37 | #include <base/BLog.h> |
||
38 | #include <system/BReactor.h> |
||
39 | #include <system/BSignal.h> |
||
40 | #include <system/BTime.h> |
||
41 | #include <system/BNetwork.h> |
||
42 | #include <arpprobe/BArpProbe.h> |
||
43 | |||
44 | BReactor reactor; |
||
45 | BArpProbe arpprobe; |
||
46 | |||
47 | static void signal_handler (void *user); |
||
48 | static void arpprobe_handler (void *unused, int event); |
||
49 | |||
50 | int main (int argc, char **argv) |
||
51 | { |
||
52 | if (argc <= 0) { |
||
53 | return 1; |
||
54 | } |
||
55 | |||
56 | if (argc != 3) { |
||
57 | printf("Usage: %s <interface> <addr>\n", argv[0]); |
||
58 | goto fail0; |
||
59 | } |
||
60 | |||
61 | char *ifname = argv[1]; |
||
62 | uint32_t addr = inet_addr(argv[2]); |
||
63 | |||
64 | BTime_Init(); |
||
65 | |||
66 | BLog_InitStdout(); |
||
67 | |||
68 | if (!BNetwork_GlobalInit()) { |
||
69 | DEBUG("BNetwork_GlobalInit failed"); |
||
70 | goto fail1; |
||
71 | } |
||
72 | |||
73 | if (!BReactor_Init(&reactor)) { |
||
74 | DEBUG("BReactor_Init failed"); |
||
75 | goto fail1; |
||
76 | } |
||
77 | |||
78 | if (!BSignal_Init(&reactor, signal_handler, NULL)) { |
||
79 | DEBUG("BSignal_Init failed"); |
||
80 | goto fail2; |
||
81 | } |
||
82 | |||
83 | if (!BArpProbe_Init(&arpprobe, ifname, addr, &reactor, NULL, arpprobe_handler)) { |
||
84 | DEBUG("BArpProbe_Init failed"); |
||
85 | goto fail3; |
||
86 | } |
||
87 | |||
88 | BReactor_Exec(&reactor); |
||
89 | |||
90 | BArpProbe_Free(&arpprobe); |
||
91 | fail3: |
||
92 | BSignal_Finish(); |
||
93 | fail2: |
||
94 | BReactor_Free(&reactor); |
||
95 | fail1: |
||
96 | BLog_Free(); |
||
97 | fail0: |
||
98 | DebugObjectGlobal_Finish(); |
||
99 | |||
100 | return 1; |
||
101 | } |
||
102 | |||
103 | void signal_handler (void *user) |
||
104 | { |
||
105 | DEBUG("termination requested"); |
||
106 | |||
107 | BReactor_Quit(&reactor, 0); |
||
108 | } |
||
109 | |||
110 | void arpprobe_handler (void *unused, int event) |
||
111 | { |
||
112 | switch (event) { |
||
113 | case BARPPROBE_EVENT_EXIST: { |
||
114 | printf("ARPPROBE: exist\n"); |
||
115 | } break; |
||
116 | |||
117 | case BARPPROBE_EVENT_NOEXIST: { |
||
118 | printf("ARPPROBE: noexist\n"); |
||
119 | } break; |
||
120 | |||
121 | case BARPPROBE_EVENT_ERROR: { |
||
122 | printf("ARPPROBE: error\n"); |
||
123 | |||
124 | // exit reactor |
||
125 | BReactor_Quit(&reactor, 0); |
||
126 | } break; |
||
127 | |||
128 | default: |
||
129 | ASSERT(0); |
||
130 | } |
||
131 | } |