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