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