Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / remove_hashnode.c
blob62f27fc592b0449c3b77177ddaff4b65316cb2b6
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2003 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: remove_hashnode.c,v 1.1.4.1 2006/06/16 17:21:16 darrenr Exp
9 */
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13 #include "ipf.h"
14 #include "netinet/ip_lookup.h"
15 #include "netinet/ip_htable.h"
17 static int hashfd = -1;
20 int remove_hashnode(unit, name, node, iocfunc)
21 int unit;
22 char *name;
23 iphtent_t *node;
24 ioctlfunc_t iocfunc;
26 iplookupop_t op;
27 iphtent_t ipe;
29 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
30 hashfd = open(IPLOOKUP_NAME, O_RDWR);
31 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
32 return -1;
34 op.iplo_type = IPLT_HASH;
35 op.iplo_unit = unit;
36 op.iplo_size = sizeof(ipe);
37 op.iplo_struct = &ipe;
38 op.iplo_arg = 0;
39 strncpy(op.iplo_name, name, sizeof(op.iplo_name));
41 bzero((char *)&ipe, sizeof(ipe));
42 bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
43 sizeof(ipe.ipe_addr));
44 bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
45 sizeof(ipe.ipe_mask));
47 if (opts & OPT_DEBUG) {
48 printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
49 printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
52 if ((*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op))
53 if (!(opts & OPT_DONOTHING)) {
54 perror("remove_hash:SIOCLOOKUPDELNODE");
55 return -1;
57 return 0;