Quellcode durchsuchen

netsplit.c format fix

MissValeska vor 10 Jahren
Ursprung
Commit
37deedce61
1 geänderte Dateien mit 200 neuen und 168 gelöschten Zeilen
  1. 200
    168
      src/netsplit.c

+ 200
- 168
src/netsplit.c Datei anzeigen

@@ -5,43 +5,52 @@
5 5
 #include <dirent.h>
6 6
 #include "getaddrinfodnstest.c"
7 7
 
8
-int isValidIpv6Address(char *ipAddress)
8
+int
9
+isValidIpv6Address (char *ipAddress)
9 10
 {
10
-    struct sockaddr_in6 sa;
11
-    int result = inet_pton(AF_INET6, ipAddress, &(sa.sin6_addr));
12
-    return result;
11
+  struct sockaddr_in6 sa;
12
+  int result = inet_pton (AF_INET6, ipAddress, &(sa.sin6_addr));
13
+  return result;
13 14
 }
14 15
 
15
-int isValidIpv4Address(char *ipAddress)
16
+int
17
+isValidIpv4Address (char *ipAddress)
16 18
 {
17
-    struct sockaddr_in sa;
18
-    int result = inet_pton(AF_INET, ipAddress, &(sa.sin_addr));
19
-    if(result == 0) {
20
-        if(isValidIpv6Address(ipAddress) == 1)
21
-            return 11;
22
-        else
23
-            return 0;
19
+  struct sockaddr_in sa;
20
+  int result = inet_pton (AF_INET, ipAddress, &(sa.sin_addr));
21
+  if (result == 0)
22
+    {
23
+      if (isValidIpv6Address (ipAddress) == 1)
24
+	return 11;
25
+      else
26
+	return 0;
24 27
     }
25
-    return result;
28
+  return result;
26 29
 }
27 30
 
28 31
 /* Forwards packets to this IP through the inet 
29 32
  * iptables forwarding rule. */
30
-void inetipForwarding(char *ipAddress, int family) {
31
-    return;
33
+void
34
+inetipForwarding (char *ipAddress, int family)
35
+{
36
+  return;
32 37
 }
33 38
 
34 39
 /* Forwards packets to this IP through the ntk 
35 40
  * iptables forwarding rule. */
36
-void ntkipForwarding(char *ipAddress, int family) {
37
-    return;
41
+void
42
+ntkipForwarding (char *ipAddress, int family)
43
+{
44
+  return;
38 45
 }
39 46
 
40 47
 /* Resolves the ntk domain name in ANDNA, 
41 48
  * Forwarding the originally desired packets
42 49
  * through the ntk iptables forwarding rule. */
43
-void ntkDNSResolution(char *domain) {
44
-    return;
50
+void
51
+ntkDNSResolution (char *domain)
52
+{
53
+  return;
45 54
 }
46 55
 
47 56
 /* Resolves the inet domain name via the commented out name servers
@@ -49,170 +58,193 @@ void ntkDNSResolution(char *domain) {
49 58
  * through the inet iptables forwarding rule.
50 59
  * Then, Forwards the originally desired packets
51 60
  * through the inet iptables forwarding rule. */
52
-void inetDNSResolution(char *domain) {
53
-    printf("Inet Domain name %s resolves to:\n", domain);
54
-    getaddrinfodnsresolution(domain);
55
-    return;
61
+void
62
+inetDNSResolution (char *domain)
63
+{
64
+  printf ("Inet Domain name %s resolves to:\n", domain);
65
+  getaddrinfodnsresolution (domain);
66
+  return;
56 67
 }
57 68
 
58
-void inet_mode(char *domain) {
59
-    
60
-    printf("inet_mode: %s\n", domain);
61
-    
62
-    char *ret;
63
-    char *ret1;
64
-    char new_domain[MAXNAMLEN];
65
-    int rt_value;
66
-    
67
-    strcpy(new_domain, domain);
68
-    
69
-    ret = strstr(new_domain, ".ntk");
70
-    
71
-    if(ret != NULL) {
72
-        printf("inet_mode .ntk\n");
73
-        goto inet_mode_ntk_rslv;
69
+void
70
+inet_mode (char *domain)
71
+{
72
+
73
+  printf ("inet_mode: %s\n", domain);
74
+
75
+  char *ret;
76
+  char *ret1;
77
+  char new_domain[MAXNAMLEN];
78
+  int rt_value;
79
+
80
+  strcpy (new_domain, domain);
81
+
82
+  ret = strstr (new_domain, ".ntk");
83
+
84
+  if (ret != NULL)
85
+    {
86
+      printf ("inet_mode .ntk\n");
87
+      goto inet_mode_ntk_rslv;
74 88
     }
75
-    
76
-    ret = strstr(new_domain, ".inet");
77
-    ret1 = strstr(new_domain, ".inet");
78
-    
79
-    if(ret1 != NULL) {
80
-        new_domain[strlen(new_domain)-6] = '\0';
81
-        printf("inet_mode abbrevate: %s\n", new_domain);
89
+
90
+  ret = strstr (new_domain, ".inet");
91
+  ret1 = strstr (new_domain, ".inet");
92
+
93
+  if (ret1 != NULL)
94
+    {
95
+      new_domain[strlen (new_domain) - 6] = '\0';
96
+      printf ("inet_mode abbrevate: %s\n", new_domain);
82 97
     }
83
-    
84
-    if(ret == NULL || ret1 != NULL) {
85
-        rt_value = isValidIpv4Address(new_domain);
86
-        if(rt_value == 1)
87
-            inetipForwarding(new_domain, AF_INET);
88
-        if(rt_value == 11)
89
-            inetipForwarding(new_domain, AF_INET6);
90
-        if(rt_value == 0)
91
-           inetDNSResolution(new_domain);
92
-        printf("inet_mode normal\n");
98
+
99
+  if (ret == NULL || ret1 != NULL)
100
+    {
101
+      rt_value = isValidIpv4Address (new_domain);
102
+      if (rt_value == 1)
103
+	inetipForwarding (new_domain, AF_INET);
104
+      if (rt_value == 11)
105
+	inetipForwarding (new_domain, AF_INET6);
106
+      if (rt_value == 0)
107
+	inetDNSResolution (new_domain);
108
+      printf ("inet_mode normal\n");
93 109
     }
94
-    
95
-    ret = strstr(new_domain, ".ntk");
96
-    
97
-    if(ret != NULL) {
98
-        inet_mode_ntk_rslv:
99
-        new_domain[strlen(new_domain)-5] = '\0';
100
-        rt_value = isValidIpv4Address(new_domain);
101
-        if(rt_value == 1)
102
-            ntkipForwarding(new_domain, AF_INET);
103
-        if(rt_value == 11)
104
-            ntkipForwarding(new_domain, AF_INET6);
105
-        if(rt_value == 0)
106
-           ntkDNSResolution(new_domain);
107
-        printf("inet_mode abnormal\n");
110
+
111
+  ret = strstr (new_domain, ".ntk");
112
+
113
+  if (ret != NULL)
114
+    {
115
+    inet_mode_ntk_rslv:
116
+      new_domain[strlen (new_domain) - 5] = '\0';
117
+      rt_value = isValidIpv4Address (new_domain);
118
+      if (rt_value == 1)
119
+	ntkipForwarding (new_domain, AF_INET);
120
+      if (rt_value == 11)
121
+	ntkipForwarding (new_domain, AF_INET6);
122
+      if (rt_value == 0)
123
+	ntkDNSResolution (new_domain);
124
+      printf ("inet_mode abnormal\n");
108 125
     }
109
-    
126
+
110 127
 }
111 128
 
112
-void ntk_mode(char *domain) {
113
-    
114
-    printf("ntk_mode: %s\n", domain);
115
-    
116
-    char *ret;
117
-    char *ret1;
118
-    char new_domain[MAXNAMLEN];
119
-    int rt_value;
120
-    
121
-    strcpy(new_domain, domain);
122
-    
123
-    ret = strstr(new_domain, ".inet");
124
-    
125
-    if(ret != NULL) {
126
-        printf("ntk_mode .inet\n");
127
-        goto ntk_mode_inet_rslv;
129
+void
130
+ntk_mode (char *domain)
131
+{
132
+
133
+  printf ("ntk_mode: %s\n", domain);
134
+
135
+  char *ret;
136
+  char *ret1;
137
+  char new_domain[MAXNAMLEN];
138
+  int rt_value;
139
+
140
+  strcpy (new_domain, domain);
141
+
142
+  ret = strstr (new_domain, ".inet");
143
+
144
+  if (ret != NULL)
145
+    {
146
+      printf ("ntk_mode .inet\n");
147
+      goto ntk_mode_inet_rslv;
128 148
     }
129
-    
130
-    ret = strstr(new_domain, ".ntk");
131
-    ret1 = strstr(new_domain, ".ntk");
132
-    
133
-    if(ret1 != NULL) {
134
-        new_domain[strlen(new_domain)-5] = '\0';
135
-        printf("ntk_mode abbrevate: %s\n", new_domain);
149
+
150
+  ret = strstr (new_domain, ".ntk");
151
+  ret1 = strstr (new_domain, ".ntk");
152
+
153
+  if (ret1 != NULL)
154
+    {
155
+      new_domain[strlen (new_domain) - 5] = '\0';
156
+      printf ("ntk_mode abbrevate: %s\n", new_domain);
136 157
     }
137
-    
138
-    if(ret == NULL || ret1 != NULL) {
139
-        rt_value = isValidIpv4Address(new_domain);
140
-        if(rt_value == 1)
141
-            ntkipForwarding(new_domain, AF_INET);
142
-        if(rt_value == 11)
143
-            ntkipForwarding(new_domain, AF_INET6);
144
-        if(rt_value == 0)
145
-           ntkDNSResolution(new_domain);
146
-        printf("ntk_mode normal\n");
158
+
159
+  if (ret == NULL || ret1 != NULL)
160
+    {
161
+      rt_value = isValidIpv4Address (new_domain);
162
+      if (rt_value == 1)
163
+	ntkipForwarding (new_domain, AF_INET);
164
+      if (rt_value == 11)
165
+	ntkipForwarding (new_domain, AF_INET6);
166
+      if (rt_value == 0)
167
+	ntkDNSResolution (new_domain);
168
+      printf ("ntk_mode normal\n");
147 169
     }
148
-    
149
-    ret = strstr(new_domain, ".inet");
150
-    
151
-    if(ret != NULL) {
152
-        ntk_mode_inet_rslv:
153
-        new_domain[strlen(new_domain)-6] = '\0';
154
-        rt_value = isValidIpv4Address(new_domain);
155
-        if(rt_value == 1)
156
-            inetipForwarding(new_domain, AF_INET);
157
-        if(rt_value == 11)
158
-            inetipForwarding(new_domain, AF_INET6);
159
-        if(rt_value == 0)
160
-           inetDNSResolution(new_domain);
161
-        printf("ntk_mode abnormal\n");
170
+
171
+  ret = strstr (new_domain, ".inet");
172
+
173
+  if (ret != NULL)
174
+    {
175
+    ntk_mode_inet_rslv:
176
+      new_domain[strlen (new_domain) - 6] = '\0';
177
+      rt_value = isValidIpv4Address (new_domain);
178
+      if (rt_value == 1)
179
+	inetipForwarding (new_domain, AF_INET);
180
+      if (rt_value == 11)
181
+	inetipForwarding (new_domain, AF_INET6);
182
+      if (rt_value == 0)
183
+	inetDNSResolution (new_domain);
184
+      printf ("ntk_mode abnormal\n");
162 185
     }
163
-    
186
+
164 187
 }
165 188
 
166
-void domain_ip_processing(char *domain) {    
167
-    char *ret;
168
-    char new_domain[MAXNAMLEN];
169
-    int rt_value;
170
-    int i;
171
-    ret = strstr(domain, ".inet");
172
-    strcpy(new_domain, domain);
173
-    if(ret != NULL) {
174
-        new_domain[strlen(new_domain)-6] = '\0';
175
-        rt_value = isValidIpv4Address(new_domain);
176
-        if(rt_value == 1)
177
-            inetipForwarding(new_domain, AF_INET);
178
-        if(rt_value == 11)
179
-            inetipForwarding(new_domain, AF_INET6);
180
-        if(rt_value == 0)
181
-           inetDNSResolution(new_domain);
182
-        
183
-        printf("This domain/ip address is an inet domain/ip address. %d\n", rt_value);
184
-        
189
+void
190
+domain_ip_processing (char *domain)
191
+{
192
+  char *ret;
193
+  char new_domain[MAXNAMLEN];
194
+  int rt_value;
195
+  int i;
196
+  ret = strstr (domain, ".inet");
197
+  strcpy (new_domain, domain);
198
+  if (ret != NULL)
199
+    {
200
+      new_domain[strlen (new_domain) - 6] = '\0';
201
+      rt_value = isValidIpv4Address (new_domain);
202
+      if (rt_value == 1)
203
+	inetipForwarding (new_domain, AF_INET);
204
+      if (rt_value == 11)
205
+	inetipForwarding (new_domain, AF_INET6);
206
+      if (rt_value == 0)
207
+	inetDNSResolution (new_domain);
208
+
209
+      printf ("This domain/ip address is an inet domain/ip address. %d\n",
210
+	      rt_value);
211
+
185 212
     }
186
-    
187
-    ret = strstr(domain, ".ntk");
188
-    if(ret != NULL) {
189
-	new_domain[strlen(new_domain)-5] = '\0';
190
-        rt_value = isValidIpv4Address(new_domain);
191
-        if(rt_value == 1)
192
-            ntkipForwarding(new_domain, AF_INET);
193
-        if(rt_value == 11)
194
-            ntkipForwarding(new_domain, AF_INET6);
195
-        if(rt_value == 0)
196
-           ntkDNSResolution(new_domain);
197
-        
198
-        printf("This domain/ip address is an ntk domain/ip address. %d\n", rt_value);
213
+
214
+  ret = strstr (domain, ".ntk");
215
+  if (ret != NULL)
216
+    {
217
+      new_domain[strlen (new_domain) - 5] = '\0';
218
+      rt_value = isValidIpv4Address (new_domain);
219
+      if (rt_value == 1)
220
+	ntkipForwarding (new_domain, AF_INET);
221
+      if (rt_value == 11)
222
+	ntkipForwarding (new_domain, AF_INET6);
223
+      if (rt_value == 0)
224
+	ntkDNSResolution (new_domain);
225
+
226
+      printf ("This domain/ip address is an ntk domain/ip address. %d\n",
227
+	      rt_value);
199 228
     }
200
-    
201
-    printf("Domain/IP: %s %s\n", new_domain, domain);
202
-    
229
+
230
+  printf ("Domain/IP: %s %s\n", new_domain, domain);
231
+
203 232
 }
204 233
 
205
-int main(void) {
206
-    for (;;) {
207
-        char *request = (char *)malloc(100);
208
-	printf("\n> ");
209
-	fgets(request, 100, stdin);
210
-        if(strcmp(request, "quit\n") == 0 || strcmp(request, "exit\n") == 0)
211
-            exit(0);
212
-	fflush(stdin);
213
-	inet_mode(request);
214
-	free(request);
215
-	}
216
-    
217
-    return 0;
218
-}
234
+int
235
+main (void)
236
+{
237
+  for (;;)
238
+    {
239
+      char *request = (char *) malloc (100);
240
+      printf ("\n> ");
241
+      fgets (request, 100, stdin);
242
+      if (strcmp (request, "quit\n") == 0 || strcmp (request, "exit\n") == 0)
243
+	exit (0);
244
+      fflush (stdin);
245
+      inet_mode (request);
246
+      free (request);
247
+    }
248
+
249
+  return 0;
250
+}

Laden…
Abbrechen
Speichern