Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / remove_hash.c
blobd1830ac76a2e40b3b15a3cd1fc743cb6a750ddf1
1 /*
2 * Copyright (C) 2002 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: remove_hash.c,v 1.1 2003/04/13 06:40:14 darrenr Exp $
7 */
9 #include <fcntl.h>
10 #include <sys/ioctl.h>
11 #include "ipf.h"
12 #include "netinet/ip_lookup.h"
13 #include "netinet/ip_htable.h"
15 static int hashfd = -1;
18 int remove_hash(iphp, iocfunc)
19 iphtable_t *iphp;
20 ioctlfunc_t iocfunc;
22 iplookupop_t op;
23 iphtable_t iph;
25 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
26 hashfd = open(IPLOOKUP_NAME, O_RDWR);
27 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
28 return -1;
30 op.iplo_type = IPLT_HASH;
31 op.iplo_unit = iphp->iph_unit;
32 strncpy(op.iplo_name, iphp->iph_name, sizeof(op.iplo_name));
33 if (*op.iplo_name == '\0')
34 op.iplo_arg = IPHASH_ANON;
35 op.iplo_size = sizeof(iph);
36 op.iplo_struct = &iph;
38 bzero((char *)&iph, sizeof(iph));
39 iph.iph_unit = iphp->iph_unit;
40 iph.iph_type = iphp->iph_type;
41 strncpy(iph.iph_name, iphp->iph_name, sizeof(iph.iph_name));
42 iph.iph_flags = iphp->iph_flags;
44 if ((*iocfunc)(hashfd, SIOCLOOKUPDELTABLE, &op))
45 if ((opts & OPT_DONOTHING) == 0) {
46 perror("remove_hash:SIOCLOOKUPDELTABLE");
47 return -1;
50 return 0;