-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
69 lines (62 loc) · 1.49 KB
/
main.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
/*
* Part of `snmp-query-engine`.
*
* Copyright 2012-2014, Anton Berezin <tobez@tobez.org>
* Modified BSD license.
* (See LICENSE file in the distribution.)
*
*/
#include "sqe.h"
void
usage(char *err)
{
FILE *f = err ? stderr : stdout;
if (err && *err)
fprintf(f, "%s\n", err);
fprintf(f, "Usage:\n");
fprintf(f, " %s [options]\n", thisprogname());
fprintf(f, "Usage parameters:\n");
fprintf(f, "\t-h\t\tproduce usage text and quit\n");
fprintf(f, "\t-p port\t\tlisten on port prt instead of default 7667\n");
if (0) {
fprintf(f, "\t-f\t\tstay in foreground\n");
fprintf(f, "\t-p pidfile\tstore process ID in pidfile\n\t\t\t(default: do not store process ID)\n");
fprintf(f, "\t-l logfile\tprint statistics and verbose output\n\t\t\tinto logfile (default: use stdout)\n");
fprintf(f, "\t\t\tSend HUP signal to reopen the logfile\n");
}
fprintf(f, "\t-q\t\tquiet operation\n");
exit(err ? 1 : 0);
}
int
main(int argc, char **argv)
{
int o;
int port = 7667;
gettimeofday(&prog_start, NULL);
bzero(&PS, sizeof(PS));
PS.max_packets_on_the_wire = 1000000;
PS.program_version = 2014052300;
while ( (o = getopt(argc, argv, "hp:q")) != -1) {
switch (o) {
case 'h':
usage(NULL);
break;
case 'p':
port = strtol(optarg, NULL, 10);
break;
case 'q':
opt_quiet = 1;
break;
default:
usage("");
}
}
argc -= optind;
argv += optind;
if (argc != 0)
usage("extraneous arguments");
create_snmp_socket();
create_listening_socket(port);
event_loop();
return 0;
}