# -sam k (commport5@lucidx.com)

sub get_args { 
 for ($i = 0; $i < @ARGV; $i++) {
  if ($ARGV[$i] =~ /^[^-]/ and $ARGV[$i-1] =~ /^[^-]/) {
   &error;
  }
  if ($ARGV[$i] =~ /^-/) {
   if ($ARGV[$i] =~ /^-([a-z]+)$/i) {
    $tmp = $1;
    $temp = $tmp;
    for ($j = 0; $j < length($tmp); $j++) {
     $temp =~ s/^(.{1})//;
     $arg = $1;
     if ($arg !~ /^[a-z]*$/i) {
      &error;
     }
     unless ($arg =~ /^(?:a|b|C|f|g|G|I|J|L|m|M|n|N|O|p|q|Q|R|S|t|T|u|U|v|W|x|X|z|Z)$/) {
      unless ($ARGV[$i+1] =~ /^.+$/) {
       &error;
      }
     }
     if ($arg =~ /^s$/) {
      unless ($ARGV[$i+1] =~ /^\d+$/) {
       &error;
      }
      else {
       $snaplen = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^B$/) {
      unless ($ARGV[$i+1] =~ /^\d+$/) {
       &error;
      }
      else {
       $expr++;
       $ntsnf++;
       $ntsbr++;
       $ntshst = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^i$/) {
      unless ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $dev = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^P$/) {
      unless ($ARGV[$i+1] =~ /.+/) {
       &error;
      }
      else {
       $prgx = $ARGV[$i+1];
       $pgnr++;
      }
     }
     if ($arg =~ /^d$/) {
      unless ($ARGV[$i+1] =~ /.+/) {
       &error;
      }
      else {
       $d_port = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^D$/) {
      unless ($ARGV[$i+1] =~ /.+/) {
       &error;
      }
      else {
       $d_host = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^y$/) {
      unless ($ARGV[$i+1] =~ /.+/) {
       &error;
      }
      else {
       $s_port = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^Y$/) {
      unless ($ARGV[$i+1] =~ /.+/) {
       &error;
      }
      else {
       $s_host = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^H$/) {
      unless ($ARGV[$i+1] =~ /.+/) {
       &error;
      }
      else {
       $regx = $ARGV[$i+1];
       $ignr++;
      }
     }
     if ($arg =~ /^E$/) {
      unless ($ARGV[$i+1] =~ /.+/) {
       &error;
      }
      else {
       $xprc = $ARGV[$i+1];
       $expr++;
      }
     }
     if ($arg =~ /^c$/) {
      if ($ARGV[$i+1] !~ /^\d+$/) {
       &error;
      }
      else {
       $amt = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^w$/) {
      if ($ARGV[$i+1] !~ /.+/) {
       &error;
      }
      else {
       $write = $ARGV[$i+1];
       $wrt++;
      }
     }
     if ($arg =~ /^A$/) {
      if ($ARGV[$i+1] !~ /.+/) {
       &error;
      }
      else {
       $send{'data'} = $ARGV[$i+1];
       $sndd++;
      }
     }
     if ($arg =~ /^e$/) {
      if ($ARGV[$i+1] !~ /.+/) {
       &error;
      }
      else {
       $strg = $ARGV[$i+1];
       $strn++;
      }
     }
     if ($arg =~ /^v$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $verb++;
      }
     }
     if ($arg =~ /^g$/) {
      if ($ARGV[$i+1] =~ /^-/ or $ARGV[$i+1] !~ /.+/) {
       $ngra++;
       $ngrp++;
      }
      else {
       $ngrr = $ARGV[$i+1];
       $ngrp++;
      }
     }
     if ($arg =~ /^J$/) {
      if ($ARGV[$i+1] =~ /^-/ or $ARGV[$i+1] !~ /.+/) {
       $brute = 3;
       $term++;
       $ntsnf++;
       $expr++;
      }
      else {
       $brute = $ARGV[$i+1];
       $ntsnf++;
       $expr++;
       $term++;
      }
     }
     if ($arg =~ /^Q$/) {
      if ($ARGV[$i+1] =~ /^-/ or $ARGV[$i+1] !~ /.+/) {
       $rndmc++;
      }
      else {
       $macd = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^r$/) {
      if ($ARGV[$i+1] !~ /.+/) {
       &error;
      }
      else {
       $read = $ARGV[$i+1];
       $test1 = new pdump::Sniff;
       $test2 = $test1->open_offline($read);
       print $test2;
      }
     }
     if ($arg =~ /^F$/) {
      if ($ARGV[$i+1] !~ /.+/) {
       &error;
      }
      else {
       $xprs = $ARGV[$i+1];
       open(XPR, "<$xprs") || die "Can't open $xprs for reading: $!\n";
       $expr++;
       while (<XPR>) {
        ($xprc .= $_) =~ s/\s+/ /g;
       }
      }
     }
     if ($arg =~ /^f$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $nons++;
      }
     }
     if ($arg =~ /^I$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $pnrc++;
      }
     }
     if ($arg =~ /^b$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $expr++;
       $ntsnf++;
       $ntsbr++;
      }
     }
     if ($arg =~ /^U$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $expr++;
       $ntsnf++;
      }
     }
     if ($arg =~ /^T$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $tstm++;
       $tstm++;
      }
     }
     if ($arg =~ /^t$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $tstm++;
      }
     }
     if ($arg =~ /^W$/) {
      if ($ARGV[$i+1] =~ /^-/ or $ARGV[$i+1] !~ /.+/) {
       print STDERR "$0 version $version\n";
       print "Valid services for sniffing:\n";
       print "ftp, telnet, pop, imap, irc, web, aim, icq, napster\n";
       die "Example: $0 -W 'pop, imap, ftp'\n";
      }
      else {
       $expr++;
       $snff++;
       $snft = $ARGV[$i+1];
      }
     }
     if ($arg =~ /^X$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $hexa++;
      }
     }
     if ($arg =~ /^x$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $hex++;
      }
     }
     if ($arg =~ /^N$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $nofl++;
      }
     }
#     if ($arg =~ /^a$/) {
#      if ($ARGV[$i+1] =~ /^\w+$/) {
#       &error;
#      }
#      else {
#       $osdt++;
#      }
#     }
     if ($arg =~ /^O$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $ngrx++;
      }
     }
     if ($arg =~ /^L$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $omni++;
       $ntsnf++;
       $expr++;
      }
     }
     if ($arg =~ /^G$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $ngrc++;
      }
     }
     if ($arg =~ /^a$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $spfp++;
      }
     }
     if ($arg =~ /^z$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $ngra++;
       $ngrp++;
      }
     }
     if ($arg =~ /^M$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $macof++;
      }
     }
     if ($arg =~ /^Z$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $expr++;
       $ntsnf++;
       $flsp++;
      }
     }
     if ($arg =~ /^m$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $dmth++;
      }
     }
     if ($arg =~ /^q$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $ngrq++;
      }
     }
     if ($arg =~ /^C$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $gnrc++;
      }
     }
     if ($arg =~ /^p$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $nopr++;
      }
     }
     if ($arg =~ /^n$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $nons++;
       $nosv++;
      }
     }
     if ($arg =~ /^R$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $rndmc++;
      }
     }
     if ($arg =~ /^u$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $ansi++;
      }
     }
     if ($arg =~ /^S$/) {
      if ($ARGV[$i+1] =~ /^\w+$/) {
       &error;
      }
      else {
       $nosv++;
      }
     }
     if ($pnrc and !$pgnr) {
      &error;
     }
     if ($gnrc and !$ignr) {
      &error;
     }
    }
   }
   else {
    &error;
   }
  }
 }
}

1;
