xref: /freebsd/sbin/ipf/libipf/kvatoname.c (revision 4543ef516683042d46f3bd3bb8a4f3f746e00499)
1 
2 /*
3  * Copyright (C) 2012 by Darren Reed.
4  *
5  * See the IPFILTER.LICENCE file for details on licencing.
6  *
7  * $Id$
8  */
9 
10 #include "ipf.h"
11 
12 #include <fcntl.h>
13 #include <sys/ioctl.h>
14 
15 char *
16 kvatoname(ipfunc_t func, 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 }
38