xref: /freebsd/sbin/ipf/libipf/kvatoname.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
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 <fcntl.h>
14 #include <sys/ioctl.h>
15 
16 char *
17 kvatoname(ipfunc_t func, ioctlfunc_t iocfunc)
18 {
19 	static char funcname[40];
20 	ipfunc_resolve_t res;
21 	int fd;
22 
23 	res.ipfu_addr = func;
24 	res.ipfu_name[0] = '\0';
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 	strncpy(funcname, res.ipfu_name, sizeof(funcname));
36 	funcname[sizeof(funcname) - 1] = '\0';
37 	return (funcname);
38 }
39