aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index b02320a..6c72c38 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,29 +1,29 @@
/* This file is part of IPACCT
- Copyright (C) 1999,2000,2001,2002,2003,2004,2005 Sergey Poznyakoff
+ Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2008 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-/* $Id: main.c,v 1.9 2005/05/20 12:59:53 gray Exp $ */
+/* $Id: main.c,v 1.10 2008/07/07 13:27:02 gray Exp $ */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
@@ -117,69 +117,69 @@ static struct argp_option options[] = {
/*ARGSUSED*/
static error_t
parse_opt (key, arg, state)
int key;
char *arg;
struct argp_state *state;
{
switch (key) {
case 'b':
dump_bytecode++;
break;
case 'c':
- profile = optarg;
+ profile = arg;
break;
case 'f':
foreground++;
break;
case 'F':
- infile = optarg;
+ infile = arg;
break;
case 'i':
- device = optarg;
+ device = arg;
break;
case 'l':
- log_name = optarg;
+ log_name = arg;
break;
case 'O':
optimize_expr++;
break;
case 'p':
promisc_off++;
break;
case 's':
single_process++;
break;
case 'S':
syntax_check++;
break;
case 't':
- ttw = atoi(optarg);
+ ttw = atoi(arg);
if (ttw <= 0)
die(1, "invalid timeslice value (%d)", ttw);
break;
case 'T':
test_mode++;
foreground++;
break;
case 'v':
verbose++;
if (verbose > 2)
debug_profile();
break;
case 'x':
fixed_clocks++;
break;
case 'u':
- user = optarg;
+ user = arg;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = {
options,
parse_opt,
NULL,
doc,
@@ -304,42 +304,43 @@ change_user ()
(int) geteuid (), (int) getegid ());
}
}
int
main(argc, argv)
int argc;
char **argv;
{
int c, type;
pcap_handler callback;
pid_t pid;
+ int index;
- if (argp_parse(&argp, argc, argv, 0, 0, NULL))
+ if (argp_parse(&argp, argc, argv, 0, &index, NULL))
exit(1);
read_profile(profile);
if (syntax_check)
return 0;
if (test_mode)
return test_shell();
alloc_snap_buffer();
if (infile) {
- if (optind < argc)
- die(1, "excess arguments after %s", argv[optind]);
+ if (index < argc)
+ die(1, "excess arguments after %s", argv[index]);
expr = read_expr(infile);
- } else if (optind < argc)
- expr = copy_argv(argc, argv, optind);
+ } else if (index < argc)
+ expr = copy_argv(argc, argv, index);
pcap = init(device, expr);
if (!(callback = lookup_pcap_callback(type = pcap_datalink(pcap))))
die(1, "unknown data link type 0x%x", type);
if (pcap->fd < 0)
die(1, "can't listen to %d", pcap->fd);
start_time = time(NULL);
if (ttw)
slice_interval = ttw;
@@ -399,25 +400,25 @@ init(device, cmdbuf)
if (pd = pcap_open_live(device, snaplen, !promisc_off, 1000, buf)) {
if ((pcap_lookupnet(device,
(u_int *) &localnet, (u_int *) & netmask,
buf)) < 0)
die(1, buf);
} else
die(1, buf);
setuid(getuid());
- bzero((char *) &bpfcode, sizeof(bpfcode));
+ memset(&bpfcode, 0, sizeof(bpfcode));
if (pcap_compile(pd, &bpfcode, cmdbuf, optimize_expr, netmask) < 0)
die(1, pcap_geterr(pd));
if (dump_bytecode) {
bpf_dump(&bpfcode, dump_bytecode);
exit(0);
}
if (pcap_setfilter(pd, &bpfcode) < 0)
die(1, pcap_geterr(pd));
signal(SIGPIPE, SIG_IGN);

Return to:

Send suggestions and report system problems to the System administrator.