associate sta with ssid of ap's
[my-code/hdw-sniff.git] / main.c
diff --git a/main.c b/main.c
index d26fbf2..1542621 100644 (file)
--- a/main.c
+++ b/main.c
@@ -216,8 +216,8 @@ int usage(void) {
   puts("\t\t-m <mode> \tieee80211 or prism");
   puts("\t\t-d <device> \twlan0,eth0");
   puts("\t\t-l <logfile>");
-  puts("\t\t-k <key> \t(string)");
-  puts("\t\t-D <file> \t(dump packages to file)");
+  //puts("\t\t-k <key> \t(string)");
+  puts("\t\t-D <file> \t(dump packages to file (pcap format))");
   puts("\t\t-h \tdisplay this help message");
   puts("");
 
@@ -286,10 +286,8 @@ int main(int argc, char **argv) {
      ++i;
      break;
     case 'D':
-     if((info.dump_fd=open(argv[i+1],O_RDWR|O_CREAT))!=0)
-      printf("dump file -> %s\n",argv[i+1]);
-     else
-      puts("warning: can't dump to file.");
+     printf("dump file -> %s\n",argv[i+1]);
+     strncpy(info.dump_file,argv[i+1],128);
      ++i;
      break;
     case 'd':
@@ -337,6 +335,14 @@ int main(int argc, char **argv) {
  pcap_fd=pcap_fileno(info.pcap_handle);
  /* -> non blocking? */
 
+ /* pcap dump */
+ if(strcmp(info.dump_file,"")) {
+  if((info.dump_handle=pcap_dump_open(info.pcap_handle,info.dump_file))==NULL) {
+   puts("pcap open dump file failed");
+   return -23;
+  }
+ }
+
  /* socket fd for channel hopping */
  info.channel_hop_fd=socket(AF_INET,SOCK_DGRAM,0);
 
@@ -381,6 +387,8 @@ int main(int argc, char **argv) {
  list_shutdown(&(info.sniffed_sta));
  input_shutdown(&(info.input));
  display_shutdown(&(info.display));
+
+ if(info.dump_handle!=NULL) pcap_dump_close(info.dump_handle);
  
  puts("");
  puts("");