-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-scanner.cpp
94 lines (74 loc) · 1.9 KB
/
main-scanner.cpp
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
//
// main-scanner.cpp
// pds-project
//
// Created by Jordán Jarolím on 13.04.17.
// Copyright © 2017 FIT VUTBR.
//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "pds-scanner.hpp"
#include "types.h"
#include <signal.h>
#include <stdlib.h>
#include <tuple>
#include <getopt.h>
using namespace std;
/**
* Signal handler
*/
void my_handler(int s){
printf(" Caught signal %d\n",s);
exit(0);
}
/**
* Parse arguments
*/
tuple<string, string> getOptions(int argc, char *argv[]) {
int c;
string filename = (string)"output.xml";
string interface = (string)"eth1";
bool isFilename = false;
bool isInterface = false;
opterr = 0;
while ((c = getopt(argc, argv, "i:f:")) != -1) {
switch (c) {
case 'i':
interface = std::string(optarg);
isInterface = true;
break;
case 'f':
filename = std::string(optarg);
isFilename = true;
break;
default:
cerr << "unknown option\n";
exit(1);
}
}
if (!isFilename)
cerr << "Program will use default filename: output.xml\n";
if (!isInterface)
cerr << "Program will use default interface: eth1\n";
return make_tuple(interface, filename);
}
/**
* Run scanning of network
*/
int main(int argc,char** argv)
{
int returnValue;
struct sigaction sigIntHandler;
tuple<string, string> options = getOptions(argc, argv);
// Register handler
sigIntHandler.sa_handler = my_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
// Scan
PdsScanner* scanner = new PdsScanner(get<0>(options), get<1>(options));
returnValue = scanner->scanIPv4();
delete scanner;
return returnValue;
}