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