forked from ZerBea/hcxtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hcxmactool.c
executable file
·829 lines (758 loc) · 18.8 KB
/
hcxmactool.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
#define _GNU_SOURCE
#include <fcntl.h>
#include <getopt.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <time.h>
#include <limits.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#if defined(__APPLE__) || defined(__OpenBSD__)
#include <libgen.h>
#else
#include <stdio_ext.h>
#endif
#include "include/version.h"
#include "include/hcxmactool.h"
#include "include/strings.c"
#include "include/fileops.c"
/*===========================================================================*/
/* global var */
static int ouicount;
static int pmkidcount = 0;
static int hccapxcount = 0;
static intoui_t *ouilist = NULL;
static intpmkid_t *pmkidlist = NULL;
static inthccapx_t *hccapxlist = NULL;
static char *hccapxinname = NULL;
static char *pmkidinname = NULL;
static char *hccapxoutname = NULL;
static char *pmkidoutname = NULL;
static char *vendorapname = NULL;
static char *vendorstaname = NULL;
static bool ouiapflag = false;
static bool nicapflag = false;
static bool macapflag = false;
static bool vendorapflag = false;
static bool ouistaflag = false;
static bool nicstaflag = false;
static bool macstaflag = false;
static bool vendorstaflag = false;
static uint8_t ouiap[3];
static uint8_t nicap[3];
static uint8_t macap[6];
static uint8_t ouista[3];
static uint8_t nicsta[3];
static uint8_t macsta[6];
static char separator = ':';
/*===========================================================================*/
static void globalclose()
{
if(ouilist != NULL)
{
free(ouilist);
}
if(pmkidlist != NULL)
{
free(pmkidlist);
}
if(hccapxlist != NULL)
{
free(hccapxlist);
}
return;
}
/*===========================================================================*/
static bool isvendorsta(uint8_t *macsta)
{
static intoui_t *zeiger;
if(ouicount == 0)
{
return false;
}
zeiger = ouilist;
for(zeiger = ouilist; zeiger < (ouilist +ouicount); zeiger++)
{
if(memcmp(zeiger->oui, macsta, 3) == 0)
{
if(strstr(zeiger->vendor, vendorstaname) != NULL)
{
return true;
}
}
}
return false;
}
/*===========================================================================*/
static bool isvendorap(uint8_t *macap)
{
static intoui_t *zeiger;
if(ouicount == 0)
{
return false;
}
zeiger = ouilist;
for(zeiger = ouilist; zeiger < (ouilist +ouicount); zeiger++)
{
if(memcmp(zeiger->oui, macap, 3) == 0)
{
if(strstr(zeiger->vendor, vendorapname) != NULL)
{
return true;
}
}
if(memcmp(zeiger->oui, macap, 3) > 0)
{
return false;
}
}
return false;
}
/*===========================================================================*/
static int writehccapxline(int fd_file, inthccapx_t *hccapxline, int written)
{
if((write(fd_file, hccapxline, INTHCCAPX_SIZE)) == -1)
{
perror("failed to write hccapx record");
}
written++;
return written;
}
/*===========================================================================*/
static void writehccapxfile()
{
static int written;
static int fd_file;
static inthccapx_t *zeiger;
if((fd_file = open(hccapxoutname, O_WRONLY | O_CREAT | O_APPEND, 0644)) == -1)
{
perror("f");
fprintf(stderr, "failed to open HCCAPX file %s\n", hccapxoutname);
return;
}
written = 0;
zeiger = hccapxlist;
for(zeiger = hccapxlist; zeiger < (hccapxlist +hccapxcount); zeiger++)
{
if((ouiapflag == true) && (memcmp(zeiger->macap, ouiap, 3) == 0))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
if((nicapflag == true) && (memcmp(&zeiger->macap[3], nicap, 3) == 0))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
if((macapflag == true) && (memcmp(zeiger->macap, macap, 6) == 0))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
if((vendorapflag == true) && (isvendorap(zeiger->macap) == true))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
if((ouistaflag == true) && (memcmp(zeiger->macsta, ouista, 3) == 0))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
if((nicstaflag == true) && (memcmp(&zeiger->macsta[3], nicsta, 3) == 0))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
if((macstaflag == true) && (memcmp(zeiger->macsta, macsta, 6) == 0))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
if((vendorstaflag == true) && (isvendorsta(zeiger->macsta) == true))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
if((ouiapflag != true) && (nicapflag != true) && (macapflag != true) && (vendorapflag != true) && (ouistaflag != true) && (nicstaflag != true) && (macstaflag != true) && (vendorstaflag != true))
{
written = writehccapxline(fd_file, zeiger, written);
continue;
}
}
close(fd_file);
printf("%d record(s) written to %s\n", written, basename(hccapxoutname));
return;
}
/*===========================================================================*/
static bool readhccapxfile()
{
static int count;
static inthccapx_t *zeiger;
static struct stat st;
static int fd_file;
if(stat(hccapxinname, &st) == -1)
{
perror("stat hccapx failed\n");
return false;
}
if((st.st_size %INTHCCAPX_SIZE) != 0)
{
fprintf(stderr, "failed to open corrupt HCCAPX file %s\n", hccapxinname);
return false;
}
hccapxlist = malloc(st.st_size +INTHCCAPX_SIZE);
if(hccapxlist == NULL)
{
printf("failed to allocate memory\n");
return false;
}
if((fd_file = open(hccapxinname, O_RDONLY)) == -1)
{
fprintf(stderr, "failed to open hccapx file %s\n", hccapxinname);
return false;
}
hccapxcount = 0;
zeiger = hccapxlist;
while((count = read(fd_file, zeiger, INTHCCAPX_SIZE)))
{
if(zeiger->signature != HCCAPX_SIGNATURE)
{
fprintf(stderr, "%d record has a wrong HCCAPX signature\n", hccapxcount);
break;
}
hccapxcount++;
zeiger++;
}
memset(zeiger, 0, INTHCCAPX_SIZE);
close(fd_file);
if(hccapxcount > 0)
{
qsort(hccapxlist, hccapxcount, INTHCCAPX_SIZE, sort_inthccapx_by_macap);
}
printf("%d record(s) read from %s\n", hccapxcount, hccapxinname);
return true;
}
/*===========================================================================*/
/*===========================================================================*/
static int writepmkidline(FILE *fh_file, intpmkid_t *pmkidline, int written)
{
static int c;
for(c = 0; c < 16; c++)
{
fprintf(fh_file, "%02x", pmkidline->pmkid[c]);
}
fprintf(fh_file, "%c", separator);
for(c = 0; c < 6; c++)
{
fprintf(fh_file, "%02x", pmkidline->macap[c]);
}
fprintf(fh_file, "%c", separator);
for(c = 0; c < 6; c++)
{
fprintf(fh_file, "%02x", pmkidline->macsta[c]);
}
fprintf(fh_file, "%c", separator);
for(c = 0; c < pmkidline->essidlen; c++)
{
fprintf(fh_file, "%02x", pmkidline->essid[c]);
}
fprintf(fh_file, "\n");
written++;
return written;
}
/*===========================================================================*/
static void writepmkidfile()
{
static int written;
static FILE *fh_file;
static intpmkid_t *zeiger;
if((fh_file = fopen(pmkidoutname, "a")) == NULL)
{
fprintf(stderr, "failed to open PMKID file %s\n", pmkidoutname);
return;
}
written = 0;
zeiger = pmkidlist;
for(zeiger = pmkidlist; zeiger < (pmkidlist +pmkidcount); zeiger++)
{
if((ouiapflag == true) && (memcmp(zeiger->macap, ouiap, 3) == 0))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
if((nicapflag == true) && (memcmp(&zeiger->macap[3], nicap, 3) == 0))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
if((macapflag == true) && (memcmp(zeiger->macap, macap, 6) == 0))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
if((vendorapflag == true) && (isvendorap(zeiger->macap) == true))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
if((ouistaflag == true) && (memcmp(zeiger->macsta, ouista, 3) == 0))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
if((nicstaflag == true) && (memcmp(&zeiger->macsta[3], nicsta, 3) == 0))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
if((macstaflag == true) && (memcmp(zeiger->macsta, macsta, 6) == 0))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
if((vendorapflag == true) && (isvendorsta(zeiger->macsta) == true))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
if((ouiapflag != true) && (nicapflag != true) && (macapflag != true) && (vendorapflag != true) && (ouistaflag != true) && (nicstaflag != true) && (macstaflag != true) && (vendorstaflag != true))
{
written = writepmkidline(fh_file, zeiger, written);
continue;
}
}
fclose(fh_file);
printf("%d record(s) written to %s\n", written, basename(pmkidoutname));
return;
}
/*===========================================================================*/
static size_t chop(char *buffer, size_t len)
{
static char *ptr;
ptr = buffer +len -1;
while(len)
{
if (*ptr != '\n')
break;
*ptr-- = 0;
len--;
}
while(len)
{
if (*ptr != '\r')
break;
*ptr-- = 0;
len--;
}
return len;
}
/*---------------------------------------------------------------------------*/
static int fgetline(FILE *inputstream, size_t size, char *buffer)
{
static size_t len;
static char *buffptr;
if(feof(inputstream))
return -1;
buffptr = fgets (buffer, size, inputstream);
if(buffptr == NULL)
return -1;
len = strlen(buffptr);
len = chop(buffptr, len);
return len;
}
/*===========================================================================*/
static bool readpmkidfile()
{
static int len;
static int aktread;
static intpmkid_t *zeiger;
static struct stat st;
static FILE *fh_file;
static char linein[PMKID_LINE_LEN];
if(stat(pmkidinname, &st) == -1)
{
perror("stat pmkid file failed\n");
return false;
}
pmkidlist = malloc(st.st_size +INTPMKID_SIZE);
if(pmkidlist == NULL)
{
printf("failed to allocate memory\n");
return false;
}
if((fh_file = fopen(pmkidinname, "r")) == NULL)
{
fprintf(stderr, "failed to read PMKID file %s\n", pmkidinname);
return false;
}
pmkidcount = 0;
zeiger = pmkidlist;
while(1)
{
memset(zeiger, 0, INTPMKID_SIZE);
if((len = fgetline(fh_file, PMKID_LINE_LEN, linein)) == -1)
{
break;
}
if((len < 61) || ((len > 59 +(ESSID_LEN_MAX *2))))
{
fprintf(stderr, "skipping line %d: %s\n", aktread, linein);
aktread++;
continue;
}
if((linein[32] == ':') && (linein[45] == ':') && (linein[58] == ':'))
{
separator = ':';
}
else if((linein[32] == '*') && (linein[45] == '*') && (linein[58] == '*'))
{
separator = '*';
}
else
{
fprintf(stderr, "skipping line %d: %s\n", aktread, linein);
aktread++;
continue;
}
if(hex2bin(&linein[0], zeiger->pmkid, 16) == false)
{
fprintf(stderr, "skipping line %d: %s:\n", aktread, linein);
aktread++;
continue;
}
if(hex2bin(&linein[33], zeiger->macap, 6) == false)
{
fprintf(stderr, "skipping line %d: %s:\n", aktread, linein);
aktread++;
continue;
}
if(hex2bin(&linein[46], zeiger->macsta, 6) == false)
{
fprintf(stderr, "skipping line %d: %s:\n", aktread, linein);
aktread++;
continue;
}
zeiger->essidlen = len -59;
if((zeiger->essidlen == 0) || (zeiger->essidlen > 64) || ((zeiger->essidlen %2) != 0))
{
fprintf(stderr, "skipping line %d: %s:\n", aktread, linein);
aktread++;
continue;
}
zeiger->essidlen = zeiger->essidlen /2;
if(hex2bin(&linein[59], zeiger->essid, zeiger->essidlen) ==false)
{
fprintf(stderr, "skipping line %d: %s:\n", aktread, linein);
aktread++;
continue;
}
pmkidcount++;
zeiger++;
aktread++;
}
fclose(fh_file);
if(pmkidcount > 0)
{
qsort(pmkidlist, pmkidcount, INTPMKID_SIZE, sort_intpmkid_by_macap);
}
printf("%d record(s) read from %s\n", pmkidcount, pmkidinname);
return true;
}
/*===========================================================================*/
static void readouifile()
{
static int len;
static int uid;
struct passwd *pwd;
static intoui_t *zeiger;
static struct stat st;
static FILE *fh_file;
static char *ouiname = NULL;
static char *vendorname = NULL;
static char *ouinameuser = "/.hcxtools/oui.txt";
static char *ouinamesystemwide = "/usr/share/ieee-data/oui.txt";
static char ouinameuserhome[PATH_MAX +1];
static char linein[OUI_LINE_LEN];
if(stat(ouinamesystemwide, &st) == 0)
{
ouiname = ouinamesystemwide;
}
uid = getuid();
pwd = getpwuid(uid);
if(pwd != NULL)
{
strncpy(ouinameuserhome, pwd->pw_dir, PATH_MAX);
strncat(ouinameuserhome, ouinameuser, PATH_MAX);
if(stat(ouinameuserhome, &st) == 0)
{
ouiname = ouinameuserhome;
}
}
if(ouiname == NULL)
{
printf("no oui file found\n");
return;
}
printf("using oui from %s\n", ouiname);
ouilist = malloc(st.st_size +INTOUI_SIZE);
if(ouilist == NULL)
{
printf("failed to allocate memory\n");
return;
}
if((fh_file = fopen(ouiname, "r")) == NULL)
{
fprintf(stderr, "failed to read OUI file %s\n", ouiname);
return;
}
ouicount = 0;
zeiger = ouilist;
while(1)
{
memset(zeiger, 0, INTOUI_SIZE);
if((len = fgetline(fh_file, OUI_LINE_LEN, linein)) == -1)
{
break;
}
if(strstr(linein, "(base 16)") == NULL)
{
continue;
}
if(hex2bin(&linein[0], zeiger->oui, 3) == false)
{
continue;
}
vendorname = strrchr(linein, '\t');
if(vendorname == NULL)
{
continue;
}
strncpy(zeiger->vendor, vendorname, OUI_LINE_LEN);
ouicount++;
zeiger++;
}
fclose(fh_file);
if(ouicount > 0)
{
qsort(ouilist, ouicount, INTOUI_SIZE, sort_intoui_by_oui);
}
return;
}
/*===========================================================================*/
__attribute__ ((noreturn))
static void version(char *eigenname)
{
printf("%s %s (C) %s ZeroBeat\n", eigenname, VERSION, VERSION_JAHR);
exit(EXIT_SUCCESS);
}
/*---------------------------------------------------------------------------*/
__attribute__ ((noreturn))
static void usage(char *eigenname)
{
printf("%s %s (C) %s ZeroBeat\n"
"usage:\n"
"%s <options>\n"
"\n"
"options:\n"
"-o <oui> : filter access point by OUI\n"
"-n <nic> : filter access point by NIC\n"
"-m <mac> : filter access point by MAC\n"
"-a <vendor> : filter access point by VENDOR name\n"
"-O <oui> : filter client by OUI\n"
"-N <nic> : filter client by NIC\n"
"-M <mac> : filter client by MAC\n"
"-A <vendor> : filter client by VENDOR name\n"
"-h : show this help\n"
"-v : show version\n"
"\n"
"--pmkidin=<file> : input PMKID file\n"
"--pmkidout=<file> : output PMKID file\n"
"--hccapxin=<file> : input HCCAPX file\n"
"--hccapxout=<file> : output HCCAPX file\n"
"--help : show this help\n"
"--version : show version\n"
"\n", eigenname, VERSION, VERSION_JAHR, eigenname);
exit(EXIT_SUCCESS);
}
/*---------------------------------------------------------------------------*/
__attribute__ ((noreturn))
static void usageerror(char *eigenname)
{
printf("%s %s (C) %s by ZeroBeat\n"
"usage: %s -h for help\n", eigenname, VERSION, VERSION_JAHR, eigenname);
exit(EXIT_FAILURE);
}
/*===========================================================================*/
int main(int argc, char *argv[])
{
static int auswahl;
static int index;
unsigned long long int macinput;
static const char *short_options = "e:E:l:o:n:m:a:O:N:M:A:hv";
static const struct option long_options[] =
{
{"pmkidin", required_argument, NULL, HCXD_PMKID_IN},
{"pmkidout", required_argument, NULL, HCXD_PMKID_OUT},
{"hccapxin", required_argument, NULL, HCXD_HCCAPX_IN},
{"hccapxout", required_argument, NULL, HCXD_HCCAPX_OUT},
{"version", no_argument, NULL, HCXD_VERSION},
{"help", no_argument, NULL, HCXD_HELP},
{NULL, 0, NULL, 0}
};
auswahl = -1;
index = 0;
optind = 1;
optopt = 0;
while((auswahl = getopt_long (argc, argv, short_options, long_options, &index)) != -1)
{
switch (auswahl)
{
case HCXD_PMKID_IN:
pmkidinname = optarg;
break;
case HCXD_PMKID_OUT:
pmkidoutname = optarg;
break;
case HCXD_HCCAPX_IN:
hccapxinname = optarg;
break;
case HCXD_HCCAPX_OUT:
hccapxoutname = optarg;
break;
case HCXD_FILTER_OUI_AP:
if(strlen(optarg) != 6)
{
fprintf(stderr, "wrong OUI format (allowed: 112233)\n");
exit(EXIT_FAILURE);
}
macinput = strtoull(optarg, NULL, 16);
ouiap[2] = macinput & 0xff;
ouiap[1] = (macinput >> 8) & 0xff;
ouiap[0] = (macinput >> 16) & 0xff;
ouiapflag = true;
break;
case HCXD_FILTER_NIC_AP:
if(strlen(optarg) != 6)
{
fprintf(stderr, "wrong OUI format (allowed: 112233)\n");
exit(EXIT_FAILURE);
}
macinput = strtoull(optarg, NULL, 16);
nicap[2] = macinput & 0xff;
nicap[1] = (macinput >> 8) & 0xff;
nicap[0] = (macinput >> 16) & 0xff;
nicapflag = true;
break;
case HCXD_FILTER_MAC_AP:
if(strlen(optarg) != 12)
{
fprintf(stderr, "wrong OUI format (allowed: 112233445566)\n");
exit(EXIT_FAILURE);
}
macinput = strtoull(optarg, NULL, 16);
macap[5] = macinput & 0xff;
macap[4] = (macinput >> 8) & 0xff;
macap[3] = (macinput >> 16) & 0xff;
macap[2] = (macinput >> 24) & 0xff;
macap[1] = (macinput >> 32) & 0xff;
macap[0] = (macinput >> 40) & 0xff;
macapflag = true;
break;
case HCXD_FILTER_VENDOR_AP:
vendorapname = optarg;
vendorapflag = true;
break;
case HCXD_FILTER_OUI_STA:
if(strlen(optarg) != 6)
{
fprintf(stderr, "wrong OUI format (allowed: 112233)\n");
exit(EXIT_FAILURE);
}
macinput = strtoull(optarg, NULL, 16);
ouista[2] = macinput & 0xff;
ouista[1] = (macinput >> 8) & 0xff;
ouista[0] = (macinput >> 16) & 0xff;
ouistaflag = true;
break;
case HCXD_FILTER_NIC_STA:
if(strlen(optarg) != 6)
{
fprintf(stderr, "wrong OUI format (allowed: 112233)\n");
exit(EXIT_FAILURE);
}
macinput = strtoull(optarg, NULL, 16);
nicsta[2] = macinput & 0xff;
nicsta[1] = (macinput >> 8) & 0xff;
nicsta[0] = (macinput >> 16) & 0xff;
nicstaflag = true;
break;
case HCXD_FILTER_MAC_STA:
if(strlen(optarg) != 12)
{
fprintf(stderr, "wrong OUI format (allowed: 112233445566)\n");
exit(EXIT_FAILURE);
}
macinput = strtoull(optarg, NULL, 16);
macsta[5] = macinput & 0xff;
macsta[4] = (macinput >> 8) & 0xff;
macsta[3] = (macinput >> 16) & 0xff;
macsta[2] = (macinput >> 24) & 0xff;
macsta[1] = (macinput >> 32) & 0xff;
macsta[0] = (macinput >> 40) & 0xff;
macstaflag = true;
break;
case HCXD_FILTER_VENDOR_STA:
vendorstaname = optarg;
vendorstaflag = true;
break;
case HCXD_HELP:
usage(basename(argv[0]));
break;
case HCXD_VERSION:
version(basename(argv[0]));
break;
case '?':
usageerror(basename(argv[0]));
break;
}
}
if(argc < 2)
{
fprintf(stderr, "no option selected\n");
return EXIT_SUCCESS;
}
readouifile();
if(((vendorapflag == true) || (vendorstaflag == true)) && (ouicount == 0))
{
fprintf(stderr, "VENDOR requested, but no OUI file found)\n");
globalclose();
exit(EXIT_FAILURE);
}
if(pmkidinname != NULL)
{
readpmkidfile();
}
if(hccapxinname != NULL)
{
readhccapxfile();
}
if((pmkidoutname != NULL) && (pmkidcount > 0))
{
writepmkidfile();
}
if((hccapxoutname != NULL) && (hccapxcount > 0))
{
writehccapxfile();
}
globalclose();
return EXIT_SUCCESS;
}
/*===========================================================================*/