summaryrefslogtreecommitdiff
path: root/external/bsd/ipf/dist/lib/poolio.c
blob: 5b52e083785e3390641415d060bf9e6913142e1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*	$NetBSD: poolio.c,v 1.2 2012/07/22 14:27:36 darrenr Exp $	*/

/*
 * Copyright (C) 2012 by Darren Reed.
 *
 * See the IPFILTER.LICENCE file for details on licencing.
 *
 * Id: poolio.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $
 */

#include <fcntl.h>
#include <sys/ioctl.h>
#include "ipf.h"
#include "netinet/ip_lookup.h"
#include "netinet/ip_pool.h"

static int poolfd = -1;


int
pool_open()
{

	if ((opts & OPT_DONTOPEN) != 0)
		return 0;

	if (poolfd == -1)
		poolfd = open(IPLOOKUP_NAME, O_RDWR);
	return poolfd;
}

int
pool_ioctl(iocfunc, cmd, ptr)
	ioctlfunc_t iocfunc;
	ioctlcmd_t cmd;
	void *ptr;
{
	return (*iocfunc)(poolfd, cmd, ptr);
}


void
pool_close()
{
	if (poolfd != -1) {
		close(poolfd);
		poolfd = -1;
	}
}

int
pool_fd()
{
	return poolfd;
}