xref: /onnv-gate/usr/src/cmd/ipf/lib/common/kvatoname.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate #include "ipf.h"
2*0Sstevel@tonic-gate 
3*0Sstevel@tonic-gate #include <fcntl.h>
4*0Sstevel@tonic-gate #include <sys/ioctl.h>
5*0Sstevel@tonic-gate 
kvatoname(func,iocfunc)6*0Sstevel@tonic-gate char *kvatoname(func, iocfunc)
7*0Sstevel@tonic-gate ipfunc_t func;
8*0Sstevel@tonic-gate ioctlfunc_t iocfunc;
9*0Sstevel@tonic-gate {
10*0Sstevel@tonic-gate 	static char funcname[40];
11*0Sstevel@tonic-gate 	ipfunc_resolve_t res;
12*0Sstevel@tonic-gate 	int fd;
13*0Sstevel@tonic-gate 
14*0Sstevel@tonic-gate 	res.ipfu_addr = func;
15*0Sstevel@tonic-gate 	res.ipfu_name[0] = '\0';
16*0Sstevel@tonic-gate 	fd = -1;
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate 	if ((opts & OPT_DONOTHING) == 0) {
19*0Sstevel@tonic-gate 		fd = open(IPL_NAME, O_RDONLY);
20*0Sstevel@tonic-gate 		if (fd == -1)
21*0Sstevel@tonic-gate 			return NULL;
22*0Sstevel@tonic-gate 	}
23*0Sstevel@tonic-gate 	(void) (*iocfunc)(fd, SIOCFUNCL, &res);
24*0Sstevel@tonic-gate 	if (fd >= 0)
25*0Sstevel@tonic-gate 		close(fd);
26*0Sstevel@tonic-gate 	strncpy(funcname, res.ipfu_name, sizeof(funcname));
27*0Sstevel@tonic-gate 	funcname[sizeof(funcname) - 1] = '\0';
28*0Sstevel@tonic-gate 	return funcname;
29*0Sstevel@tonic-gate }
30