示例#1
0
文件: airspf.c 项目: davll/airspf
int main(int argc, char **argv)
{
	airspf_ctx *ctx = calloc(1, sizeof(airspf_ctx));
	pcap_monitor(ctx->monitor_if, ctx);
	
	return 0;
}
示例#2
0
int main(int argc, char **argv){
  char *conf_file = NULL;
  char lnet_err[LIBNET_ERRBUF_SIZE];
  char *filterstr=NULL;
  int drivertype=INJ_NODRIVER; /* for lorcon */
  wepkey *tmpkey;
  
  if (argc < 7) { // minimum # of arguments
    usage();
    exit(1);
  }

  airpwn_ctx *ctx = calloc(1, sizeof(airpwn_ctx));
  if(ctx == NULL){
    perror("calloc");
    exit(1);
  }

  // some default ctx values
  ctx->iface_mtu = 1460;
  ctx->fcs_present = 1;

  for(;;){
    int c = getopt(argc, argv, "i:o:c:l:f:vhd:C:M:I:k:m:F");

    if(c < 0)
      break;

    switch(c){
      case 'h':
	     usage();
	     exit(0);
      case 'v':
	     ctx->verbosity++;
	     break;
      case 'i':
				ctx->control_if = optarg;
				ctx->inject_if = optarg;
				ctx->monitor_if = optarg;
				break;
      case 'c':
				conf_file = optarg;
				break;
      case 'f':
				filterstr = optarg;
				break;
      case 'l':
				ctx->logfile = fopen(optarg, "a");
				if(ctx ->logfile == NULL){
				  perror("fopen");
				  exit(1);
				}
      	break;
      case 'd':
        drivertype = tx80211_resolvecard(optarg);
      	break;
      case 'M':
				ctx->monitor_if = optarg;
				break;
      case 'C':
				ctx->control_if = optarg;
				break;
      case 'I':
				ctx->inject_if = optarg;
				break;
      case 'k':
				tmpkey = parse_wepkey(optarg);
				if(tmpkey == NULL){
				  fprintf(stderr, "Error parsing WEP key: %s\n", optarg);
				  exit(1);
				}
				tmpkey->next = ctx->keys;
				ctx->keys = tmpkey;
				break;
		  case 'm':
		    ctx->iface_mtu = (uint16_t)strtol(optarg, NULL, 10);
		    break;
      case 'F':
        ctx->fcs_present = 0;
        break;
      default:
				usage();
				exit(1);
    }
  }

  if(ctx->control_if == NULL || ctx->monitor_if == NULL || 
      ctx->inject_if == NULL || conf_file == NULL){
    usage();
    exit(1);
  }
	
  printlog(ctx, 1, "Parsing configuration file..\n");
  
  ctx->conf_list = parse_config_file(conf_file);
  if(ctx->conf_list == NULL){
    printf("Error parsing configuration file.\n");
    exit(1);
  }

  /* Initialize lorcon here */
  if (drivertype == INJ_NODRIVER) {
    fprintf(stderr, "Driver name not recognized.\n");
    usage();
    return 1;
  }

  printlog(ctx, 1, "Opening command socket..\n");

  /* Initialize lorcon function pointers and other parameters */
  if (tx80211_init(&ctx->control_tx, ctx->control_if, drivertype) < 0) {
    fprintf(stderr, "Error initializing lorcon.\n");
    return 1;
  }

  printlog(ctx, 1, "Opening monitor socket..\n");

  /* Initialize lorcon function pointers and other parameters */
  if (tx80211_init(&ctx->monitor_tx, ctx->monitor_if, drivertype) < 0) {
    fprintf(stderr, "Error initializing lorcon.\n");
    return 1;
  }
  
  printlog(ctx, 1, "Opening injection socket..\n");

  /* Initialize lorcon function pointers and other parameters */
  if (tx80211_init(&ctx->inject_tx, ctx->inject_if, drivertype) < 0) {
    fprintf(stderr, "Error initializing lorcon.\n");
    return 1;
  }
 
  /* Set monitor mode */
  if (tx80211_setmode(&ctx->monitor_tx, IW_MODE_MONITOR) != 0) {
    fprintf(stderr, "Error setting monitor mode for interface %s.\n",
        ctx->monitor_tx.ifname);
    //return 1;
  }

  /* Open the interface to get a socket */
  if (tx80211_open(&ctx->inject_tx) < 0) {
    fprintf(stderr, "Unable to open interface %s.\n", ctx->inject_tx.ifname);
    return 1;
  }

  /* ctx->lnet = libnet_init(LIBNET_LINK_ADV, ctx->in_if, lnet_err); */
  ctx->lnet = libnet_init(LIBNET_LINK_ADV, "lo", lnet_err);
  if(ctx->lnet == NULL){
    printf("Error in libnet_init: %s\n", lnet_err);

    exit(1);
  }

  printlog(ctx, 0, "Listening for packets...\n");
  
  pthread_t thread;
  if(pthread_create(&thread, NULL, channel_thread, ctx)){
    perror("pthread_create");
    exit(1);
  }
  
  pcap_monitor(ctx->monitor_if, ctx, filterstr);

  return 0;
}