certain wireless card drives break auto detection. This moves the
detection code after the option parsing, so that people can still work
around it with "-i wlan0".
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=464012

--- a/main.c
+++ b/main.c
@@ -31,6 +31,7 @@
 int main(int argc,char **argv)
 {
    char *dev, *app;
+   dev = NULL;
    char *filter, *buffer, ldname[50];
    char errbuf[PCAP_ERRBUF_SIZE];
    extern char *optarg;
@@ -105,14 +106,6 @@
         fprintf(stderr, "You must be root, Sorry\n\n");
         return -1;
      }
-
-   /* finding a suitable device */
-   dev = pcap_lookupdev(errbuf);
-   if (dev==NULL)
-     {
-	fprintf (stderr, "Error: can't find a suitable interface to use: %s\n", errbuf);
-	return -1;
-     }
    
    /*
    res = pcap_findalldevs(&devices, errbuf);
@@ -142,12 +135,6 @@
    pcap_freealldevs(devices);
    */
    
-   if  ((L = libnet_init (LIBNET_LINK, dev, errbuf))==NULL)
-     {
-	fprintf(stderr, "Error: can't initialize libnet engine: %s", errbuf);
-	fprintf(stderr, "Have you activate a non-loopback iface? (man ifconfig)\n");
-	exit(-1);
-     }
 
    line_s = row_s = cont = lg = 0;
    option_index = 0;
@@ -171,7 +158,7 @@
 	  break;
         case 'i':
 	  (app=optarg);
-	  strcpy(dev,app);
+	  dev = app;
 	  break;
 	case 'l': /* log to file */
 	  flags.l=1;
@@ -281,6 +268,22 @@
        }
    /* END OF ARGS SWITCH */
 
+   /* finding a suitable device */
+   if(dev == NULL) dev = pcap_lookupdev(errbuf);
+   if (dev==NULL)
+     {
+	fprintf (stderr, "Error: can't find a suitable interface to use: %s\n", errbuf);
+	return -1;
+     }
+
+   if  ((L = libnet_init (LIBNET_LINK, dev, errbuf))==NULL)
+     {
+	fprintf(stderr, "Error: can't initialize libnet engine: %s", errbuf);
+	fprintf(stderr, "Have you activate a non-loopback iface? (man ifconfig)\n");
+        fprintf(stderr, "Maybe autodetection is failing, try with \"-i interface\"\n");
+	exit(-1);
+     }
+
    if (dev==NULL)
      {
 	fprintf(stderr, "Cannot find a suitable network interface!\n");
