xref: /freebsd/sbin/ipf/libipf/nametokva.c (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1 /*	$FreeBSD$	*/
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * $Id$
9  */
10 
11 #include "ipf.h"
12 
13 #include <sys/ioctl.h>
14 #include <fcntl.h>
15 
16 ipfunc_t
17 nametokva(char *name, ioctlfunc_t iocfunc)
18 {
19 	ipfunc_resolve_t res;
20 	int fd;
21 
22 	strncpy(res.ipfu_name, name, sizeof(res.ipfu_name));
23 	res.ipfu_addr = NULL;
24 	fd = -1;
25 
26 	if ((opts & OPT_DONTOPEN) == 0) {
27 		fd = open(IPL_NAME, O_RDONLY);
28 		if (fd == -1)
29 			return (NULL);
30 	}
31 	(void) (*iocfunc)(fd, SIOCFUNCL, &res);
32 	if (fd >= 0)
33 		close(fd);
34 	if (res.ipfu_addr == NULL)
35 		res.ipfu_addr = (ipfunc_t)-1;
36 	return (res.ipfu_addr);
37 }
38