xref: /freebsd/sbin/ipf/libipf/kvatoname.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  *
741edb306SCy Schubert  * $Id$
841edb306SCy Schubert  */
941edb306SCy Schubert 
1041edb306SCy Schubert #include "ipf.h"
1141edb306SCy Schubert 
1241edb306SCy Schubert #include <fcntl.h>
1341edb306SCy Schubert #include <sys/ioctl.h>
1441edb306SCy Schubert 
15efeb8bffSCy Schubert char *
kvatoname(ipfunc_t func,ioctlfunc_t iocfunc)16efeb8bffSCy Schubert kvatoname(ipfunc_t func, ioctlfunc_t iocfunc)
1741edb306SCy Schubert {
1841edb306SCy Schubert 	static char funcname[40];
1941edb306SCy Schubert 	ipfunc_resolve_t res;
2041edb306SCy Schubert 	int fd;
2141edb306SCy Schubert 
2241edb306SCy Schubert 	res.ipfu_addr = func;
2341edb306SCy Schubert 	res.ipfu_name[0] = '\0';
2441edb306SCy Schubert 	fd = -1;
2541edb306SCy Schubert 
2641edb306SCy Schubert 	if ((opts & OPT_DONTOPEN) == 0) {
2741edb306SCy Schubert 		fd = open(IPL_NAME, O_RDONLY);
2841edb306SCy Schubert 		if (fd == -1)
29*2582ae57SCy Schubert 			return (NULL);
3041edb306SCy Schubert 	}
3141edb306SCy Schubert 	(void) (*iocfunc)(fd, SIOCFUNCL, &res);
3241edb306SCy Schubert 	if (fd >= 0)
3341edb306SCy Schubert 		close(fd);
3441edb306SCy Schubert 	strncpy(funcname, res.ipfu_name, sizeof(funcname));
3541edb306SCy Schubert 	funcname[sizeof(funcname) - 1] = '\0';
36*2582ae57SCy Schubert 	return (funcname);
3741edb306SCy Schubert }
38