-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipar_read.cpp
More file actions
70 lines (65 loc) · 1.67 KB
/
ipar_read.cpp
File metadata and controls
70 lines (65 loc) · 1.67 KB
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
// Program ipar_read
// ----------------
// Reads a list of IP address ranges from standard input.
// Writes out equivalent list of ranges in one of three formats, to
// standard output:
// * standard form.
// * intervals, with dashes.
// * individual 32-bit numbers, in hex format.
// The last format is useful for testing.
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;
#include "ipar_iplist.h"
#include "ipar_common.h"
int main (int argc, char* argv[])
{
// Process arguments
IPAR::OutputStyle style;
switch (argc)
{
case 1:
style = IPAR::Scidr;
break;
case 2:
style = IPAR::o_style(argv[1]);
if (style == IPAR::Sunknown)
{
cerr << "Usage: ipar_read [-cidr|-dashes|-hex]" << endl;
cerr << "(no other arguments)" << endl;
return 1;
}
break;
default:
cerr << "Usage: ipar_read [-cidr|-dashes|-hex]" << endl;
cerr << "(no other arguments)" << endl;
return 1;
}
IPAR::List iplist;
if (int retval = IPAR::common_read (cin, iplist) != 0) return retval;
// Report
cerr << iplist.num_operations() << " operations applied, ";
auto numLines = iplist.num_output();
if (style == IPAR::Shex)
{
iplist.verify();
cout << hex << setfill('0');
for (auto iter = iplist.cbegin() ; iter != iplist.cend() ; ++iter)
{
uint32_t lower = iter->first;
while (lower <= iter->second)
{
cout << setw(8) << lower++ << endl;
}
}
}
else
{
// TODO: write a manipulator for iplist.
iplist.print(cout, (style == IPAR::Sdashes));
}
cerr << iplist.num_output() - numLines << " lines output" << endl;
return 0;
}