|
@@ -327,32 +327,59 @@ void free_server_opt(void)
|
327
|
327
|
void exclude_interface(void) {
|
328
|
328
|
char *ifs = "null1";
|
329
|
329
|
char *old_tmp = "null2";
|
|
330
|
+ char *old_tmp1 = "null3";
|
330
|
331
|
struct ifaddrs *addrs,*tmp;
|
331
|
|
- struct ifreq *a_ifs;
|
332
|
|
- getifaddrs(&addrs);
|
|
332
|
+
|
|
333
|
+ if (getifaddrs(&addrs) !=0) {
|
|
334
|
+ printf("%s\n", strerror(errno));
|
|
335
|
+ exit(1);
|
|
336
|
+ }
|
333
|
337
|
tmp = addrs;
|
334
|
338
|
while(tmp) {
|
|
339
|
+
|
335
|
340
|
old_tmp = ifs;
|
336
|
341
|
|
337
|
|
- if(tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET)
|
338
|
|
- ifs = tmp->ifa_name;
|
|
342
|
+ Re_Check:
|
339
|
343
|
|
340
|
|
- if(strncmp(ifs, "lo", 2) == 0 || strncmp(ifs, "tunl0", 5) == 0 || strncmp(ifs, "tunl1", 5) == 0 || strcmp(ifs, optarg) == 0)
|
341
|
|
- goto Check_Active;
|
342
|
|
-
|
343
|
|
- Check_Active:
|
|
344
|
+ old_tmp1 = ifs;
|
|
345
|
+ if(tmp && tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET && tmp->ifa_flags & IFF_UP)
|
|
346
|
+ ifs = tmp->ifa_name;
|
|
347
|
+
|
|
348
|
+ else if(tmp && strcmp(old_tmp1, ifs) == 0) {
|
|
349
|
+ tmp = tmp->ifa_next;
|
|
350
|
+ goto Re_Check;
|
|
351
|
+ }
|
|
352
|
+
|
|
353
|
+ Re_Check1:
|
|
354
|
+
|
|
355
|
+ printf("Possibly bad ifs is: %s\n", ifs);
|
344
|
356
|
|
345
|
|
- a_ifs = ifs;
|
346
|
|
- if(a_ifs->ifr_name != IFF_UP) {
|
347
|
|
- tmp = tmp->ifa_next;
|
348
|
|
- if(tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET)
|
349
|
|
- ifs = tmp->ifa_name;
|
|
357
|
+ if(tmp && (strncmp(ifs, "lo", 2) == 0 || strncmp(ifs, "tunl0", 5) == 0 || strncmp(ifs, "tunl1", 5) == 0 || strcmp(optarg, ifs) == 0)) {
|
|
358
|
+ printf("Bad Interface: %s\n", ifs);
|
|
359
|
+ tmp = tmp->ifa_next;
|
|
360
|
+ old_tmp1 = ifs;
|
|
361
|
+ if(tmp && tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET && tmp->ifa_flags & IFF_UP)
|
|
362
|
+ ifs = tmp->ifa_name;
|
|
363
|
+
|
|
364
|
+ if(tmp && strcmp(old_tmp1, ifs) == 0) {
|
|
365
|
+ tmp = tmp->ifa_next;
|
|
366
|
+
|
|
367
|
+ if(tmp && tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET && tmp->ifa_flags & IFF_UP)
|
|
368
|
+ ifs = tmp->ifa_name;
|
|
369
|
+ goto Re_Check1;
|
|
370
|
+ }
|
|
371
|
+ }
|
|
372
|
+
|
|
373
|
+ printf("Good ifs is: %s\n", ifs);
|
|
374
|
+
|
|
375
|
+ if(strcmp(old_tmp, ifs) == 0) {
|
|
376
|
+ printf("Loop finished: %s\n", ifs);
|
|
377
|
+ break;
|
350
|
378
|
}
|
351
|
379
|
|
352
|
380
|
tmp = tmp->ifa_next;
|
353
|
|
- if(strcmp(old_tmp, ifs) == 0)
|
354
|
|
- break;
|
355
|
|
- server_opt.ifs[server_opt.ifs_n++]=xstrndup(ifs, IFNAMSIZ-1);
|
|
381
|
+ server_opt.ifs[server_opt.ifs_n++]=xstrndup(ifs, IFNAMSIZ-1);
|
|
382
|
+ printf("Using Interface: %s\n", ifs);
|
356
|
383
|
}
|
357
|
384
|
|
358
|
385
|
freeifaddrs(addrs);
|