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