Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / load_poolnode.c
blob16aab5e926d547abd8bbbaa0ed490063a7061614
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2003-2004 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: load_poolnode.c,v 1.3.2.3 2006/06/16 17:21:06 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_pool.h"
17 static int poolfd = -1;
20 int load_poolnode(role, name, node, iocfunc)
21 int role;
22 char *name;
23 ip_pool_node_t *node;
24 ioctlfunc_t iocfunc;
26 ip_pool_node_t pn;
27 iplookupop_t op;
28 int err;
30 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
31 poolfd = open(IPLOOKUP_NAME, O_RDWR);
32 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
33 return -1;
35 op.iplo_unit = role;
36 op.iplo_type = IPLT_POOL;
37 op.iplo_arg = 0;
38 op.iplo_struct = &pn;
39 op.iplo_size = sizeof(pn);
40 strncpy(op.iplo_name, name, sizeof(op.iplo_name));
42 bzero((char *)&pn, sizeof(pn));
43 bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
44 sizeof(pn.ipn_addr));
45 bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
46 sizeof(pn.ipn_mask));
47 pn.ipn_info = node->ipn_info;
48 strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
50 if ((opts & OPT_REMOVE) == 0)
51 err = (*iocfunc)(poolfd, SIOCLOOKUPADDNODE, &op);
52 else
53 err = (*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op);
55 if (err != 0) {
56 if ((opts & OPT_DONOTHING) == 0) {
57 perror("load_poolnode:SIOCLOOKUP*NODE");
58 return -1;
62 return 0;