| 1 |
certain wireless card drives break auto detection. This moves the |
| 2 |
detection code after the option parsing, so that people can still work |
| 3 |
around it with "-i wlan0". |
| 4 |
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=464012 |
| 5 |
|
| 6 |
--- a/main.c |
| 7 |
+++ b/main.c |
| 8 |
@@ -31,6 +31,7 @@ |
| 9 |
int main(int argc,char **argv) |
| 10 |
{ |
| 11 |
char *dev, *app; |
| 12 |
+ dev = NULL; |
| 13 |
char *filter, *buffer, ldname[50]; |
| 14 |
char errbuf[PCAP_ERRBUF_SIZE]; |
| 15 |
extern char *optarg; |
| 16 |
@@ -105,14 +106,6 @@ |
| 17 |
fprintf(stderr, "You must be root, Sorry\n\n"); |
| 18 |
return -1; |
| 19 |
} |
| 20 |
- |
| 21 |
- /* finding a suitable device */ |
| 22 |
- dev = pcap_lookupdev(errbuf); |
| 23 |
- if (dev==NULL) |
| 24 |
- { |
| 25 |
- fprintf (stderr, "Error: can't find a suitable interface to use: %s\n", errbuf); |
| 26 |
- return -1; |
| 27 |
- } |
| 28 |
|
| 29 |
/* |
| 30 |
res = pcap_findalldevs(&devices, errbuf); |
| 31 |
@@ -142,12 +135,6 @@ |
| 32 |
pcap_freealldevs(devices); |
| 33 |
*/ |
| 34 |
|
| 35 |
- if ((L = libnet_init (LIBNET_LINK, dev, errbuf))==NULL) |
| 36 |
- { |
| 37 |
- fprintf(stderr, "Error: can't initialize libnet engine: %s", errbuf); |
| 38 |
- fprintf(stderr, "Have you activate a non-loopback iface? (man ifconfig)\n"); |
| 39 |
- exit(-1); |
| 40 |
- } |
| 41 |
|
| 42 |
line_s = row_s = cont = lg = 0; |
| 43 |
option_index = 0; |
| 44 |
@@ -171,7 +158,7 @@ |
| 45 |
break; |
| 46 |
case 'i': |
| 47 |
(app=optarg); |
| 48 |
- strcpy(dev,app); |
| 49 |
+ dev = app; |
| 50 |
break; |
| 51 |
case 'l': /* log to file */ |
| 52 |
flags.l=1; |
| 53 |
@@ -281,6 +268,22 @@ |
| 54 |
} |
| 55 |
/* END OF ARGS SWITCH */ |
| 56 |
|
| 57 |
+ /* finding a suitable device */ |
| 58 |
+ if(dev == NULL) dev = pcap_lookupdev(errbuf); |
| 59 |
+ if (dev==NULL) |
| 60 |
+ { |
| 61 |
+ fprintf (stderr, "Error: can't find a suitable interface to use: %s\n", errbuf); |
| 62 |
+ return -1; |
| 63 |
+ } |
| 64 |
+ |
| 65 |
+ if ((L = libnet_init (LIBNET_LINK, dev, errbuf))==NULL) |
| 66 |
+ { |
| 67 |
+ fprintf(stderr, "Error: can't initialize libnet engine: %s", errbuf); |
| 68 |
+ fprintf(stderr, "Have you activate a non-loopback iface? (man ifconfig)\n"); |
| 69 |
+ fprintf(stderr, "Maybe autodetection is failing, try with \"-i interface\"\n"); |
| 70 |
+ exit(-1); |
| 71 |
+ } |
| 72 |
+ |
| 73 |
if (dev==NULL) |
| 74 |
{ |
| 75 |
fprintf(stderr, "Cannot find a suitable network interface!\n"); |