diff options
Diffstat (limited to 'contrib/ipfilter/ipfs.c')
-rw-r--r-- | contrib/ipfilter/ipfs.c | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/contrib/ipfilter/ipfs.c b/contrib/ipfilter/ipfs.c index 84fadc0..ffbd71b 100644 --- a/contrib/ipfilter/ipfs.c +++ b/contrib/ipfilter/ipfs.c @@ -45,7 +45,7 @@ #include "ipf.h" #if !defined(lint) -static const char rcsid[] = "@(#)$Id: ipfs.c,v 2.6.2.12 2002/09/26 12:25:19 darrenr Exp $"; +static const char rcsid[] = "@(#)$Id: ipfs.c,v 2.6.2.15 2003/05/31 02:12:21 darrenr Exp $"; #endif #ifndef IPF_SAVEDIR @@ -63,6 +63,7 @@ extern char *index __P((const char *, int)); #endif extern char *optarg; +extern int optind; int main __P((int, char *[])); void usage __P((void)); @@ -80,22 +81,24 @@ int writenat __P((int, char *)); char *concat __P((char *, char *)); int opts = 0; +char *progname; void usage() { fprintf(stderr, "\ -usage: ipfs [-nv] -l\n\ -usage: ipfs [-nv] -u\n\ -usage: ipfs [-nv] [-d <dir>] -R\n\ -usage: ipfs [-nv] [-d <dir>] -W\n\ -usage: ipfs [-nv] -N [-f <file> | -d <dir>] -r\n\ -usage: ipfs [-nv] -S [-f <file> | -d <dir>] -r\n\ -usage: ipfs [-nv] -N [-f <file> | -d <dir>] -w\n\ -usage: ipfs [-nv] -S [-f <file> | -d <dir>] -w\n\ -usage: ipfs [-nv] -N [-f <filename> | -d <dir> ] -i <if1>,<if2>\n\ -usage: ipfs [-nv] -S [-f <filename> | -d <dir> ] -i <if1>,<if2>\n\ -"); +usage: %s [-nv] -l\n\ +usage: %s [-nv] -u\n\ +usage: %s [-nv] [-d <dir>] -R\n\ +usage: %s [-nv] [-d <dir>] -W\n\ +usage: %s [-nv] -N [-f <file> | -d <dir>] -r\n\ +usage: %s [-nv] -S [-f <file> | -d <dir>] -r\n\ +usage: %s [-nv] -N [-f <file> | -d <dir>] -w\n\ +usage: %s [-nv] -S [-f <file> | -d <dir>] -w\n\ +usage: %s [-nv] -N [-f <filename> | -d <dir> ] -i <if1>,<if2>\n\ +usage: %s [-nv] -S [-f <filename> | -d <dir> ] -i <if1>,<if2>\n\ +", progname, progname, progname, progname, progname, progname, + progname, progname, progname, progname); exit(1); } @@ -214,6 +217,8 @@ char *argv[]; int c, lock = -1, devfd = -1, err = 0, rw = -1, ns = -1, set = 0; char *dirname = NULL, *filename = NULL, *ifs = NULL; + progname = argv[0]; + while ((c = getopt(argc, argv, "d:f:i:lNnSRruvWw")) != -1) switch (c) { @@ -287,10 +292,14 @@ char *argv[]; rw = 3; set = 1; break; + case '?' : default : usage(); } + if (optind < 2) + usage(); + if (filename == NULL) { if (ns == 0) { if (dirname == NULL) @@ -560,9 +569,11 @@ int readnat(fd, file) int fd; char *file; { - nat_save_t ipn, *in, *ipnhead = NULL, *in1, *ipntail = NULL, *ipnp; + nat_save_t ipn, *in, *ipnhead = NULL, *in1, *ipntail = NULL; int nfd = -1, i; nat_t *nat; + char *s; + int n; if (!file) file = IPF_NATFILE; @@ -575,7 +586,6 @@ char *file; } bzero((char *)&ipn, sizeof(ipn)); - ipnp = &ipn; /* * 1. Read all state information in. @@ -597,30 +607,35 @@ char *file; } if (ipn.ipn_dsize > 0) { - char *s = ipnp->ipn_data; - int n = ipnp->ipn_dsize; + n = ipn.ipn_dsize; - n -= sizeof(ipnp->ipn_data); + if (n > sizeof(ipn.ipn_data)) + n -= sizeof(ipn.ipn_data); + else + n = 0; in = malloc(sizeof(*in) + n); if (!in) break; - s += sizeof(ipnp->ipn_data); - i = read(nfd, s, n); - if (i == 0) - break; - if (i != n) { - fprintf(stderr, "incomplete read: %d != %d\n", - i, n); - close(nfd); - return 1; + if (n > 0) { + s = in->ipn_data + sizeof(in->ipn_data); + i = read(nfd, s, n); + if (i == 0) + break; + if (i != n) { + fprintf(stderr, + "incomplete read: %d != %d\n", + i, n); + close(nfd); + return 1; + } } } else in = (nat_save_t *)malloc(sizeof(*in)); - bcopy((char *)ipnp, (char *)in, sizeof(ipn)); + bcopy((char *)&ipn, (char *)in, sizeof(ipn)); /* - * Check to see if this is the first state entry that will + * Check to see if this is the first NAT entry that will * reference a particular rule and if so, flag it as such * else just adjust the rule pointer to become a pointer to * the other. We do this so we have a means later for tracking @@ -650,6 +665,7 @@ char *file; } while (1); close(nfd); + nfd = -1; for (in = ipnhead; in; in = in->ipn_next) { if (opts & OPT_VERBOSE) @@ -758,6 +774,7 @@ char *dirname; dirname = IPF_SAVEDIR; if (chdir(dirname)) { + fprintf(stderr, "IPF_SAVEDIR=%s: ", dirname); perror("chdir(IPF_SAVEDIR)"); return 1; } |