]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ipfilter/lib/nametokva.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ipfilter / lib / nametokva.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * $Id$
9  */
10
11 #include "ipf.h"
12
13 #include <sys/ioctl.h>
14 #include <fcntl.h>
15
16 ipfunc_t nametokva(name, iocfunc)
17         char *name;
18         ioctlfunc_t iocfunc;
19 {
20         ipfunc_resolve_t res;
21         int fd;
22
23         strncpy(res.ipfu_name, name, sizeof(res.ipfu_name));
24         res.ipfu_addr = NULL;
25         fd = -1;
26
27         if ((opts & OPT_DONTOPEN) == 0) {
28                 fd = open(IPL_NAME, O_RDONLY);
29                 if (fd == -1)
30                         return NULL;
31         }
32         (void) (*iocfunc)(fd, SIOCFUNCL, &res);
33         if (fd >= 0)
34                 close(fd);
35         if (res.ipfu_addr == NULL)
36                 res.ipfu_addr = (ipfunc_t)-1;
37         return res.ipfu_addr;
38 }