xref: /netbsd-src/external/bsd/ipf/dist/lib/kvatoname.c (revision 13885a665959c62f13a82b3caedf986eaa17aa31)
1*13885a66Sdarrenr /*	$NetBSD: kvatoname.c,v 1.2 2012/07/22 14:27:36 darrenr Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
8*13885a66Sdarrenr  * Id: kvatoname.c,v 1.1.1.2 2012/07/22 13:44:39 darrenr Exp $
9bc4097aaSchristos  */
10bc4097aaSchristos 
11bc4097aaSchristos #include "ipf.h"
12bc4097aaSchristos 
13bc4097aaSchristos #include <fcntl.h>
14bc4097aaSchristos #include <sys/ioctl.h>
15bc4097aaSchristos 
kvatoname(func,iocfunc)16bc4097aaSchristos char *kvatoname(func, iocfunc)
17bc4097aaSchristos 	ipfunc_t func;
18bc4097aaSchristos 	ioctlfunc_t iocfunc;
19bc4097aaSchristos {
20bc4097aaSchristos 	static char funcname[40];
21bc4097aaSchristos 	ipfunc_resolve_t res;
22bc4097aaSchristos 	int fd;
23bc4097aaSchristos 
24bc4097aaSchristos 	res.ipfu_addr = func;
25bc4097aaSchristos 	res.ipfu_name[0] = '\0';
26bc4097aaSchristos 	fd = -1;
27bc4097aaSchristos 
28bc4097aaSchristos 	if ((opts & OPT_DONTOPEN) == 0) {
29bc4097aaSchristos 		fd = open(IPL_NAME, O_RDONLY);
30bc4097aaSchristos 		if (fd == -1)
31bc4097aaSchristos 			return NULL;
32bc4097aaSchristos 	}
33bc4097aaSchristos 	(void) (*iocfunc)(fd, SIOCFUNCL, &res);
34bc4097aaSchristos 	if (fd >= 0)
35bc4097aaSchristos 		close(fd);
36bc4097aaSchristos 	strncpy(funcname, res.ipfu_name, sizeof(funcname));
37bc4097aaSchristos 	funcname[sizeof(funcname) - 1] = '\0';
38bc4097aaSchristos 	return funcname;
39bc4097aaSchristos }
40