]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/kvatoname.c
Import IP-Filter 5.1.2 into vendor branches using the existing license that
[FreeBSD/FreeBSD.git] / lib / kvatoname.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 <fcntl.h>
12 #include <sys/ioctl.h>
13
14 char *kvatoname(func, iocfunc)
15         ipfunc_t func;
16         ioctlfunc_t iocfunc;
17 {
18         static char funcname[40];
19         ipfunc_resolve_t res;
20         int fd;
21
22         res.ipfu_addr = func;
23         res.ipfu_name[0] = '\0';
24         fd = -1;
25
26         if ((opts & OPT_DONTOPEN) == 0) {
27                 fd = open(IPL_NAME, O_RDONLY);
28                 if (fd == -1)
29                         return NULL;
30         }
31         (void) (*iocfunc)(fd, SIOCFUNCL, &res);
32         if (fd >= 0)
33                 close(fd);
34         strncpy(funcname, res.ipfu_name, sizeof(funcname));
35         funcname[sizeof(funcname) - 1] = '\0';
36         return funcname;
37 }