xref: /freebsd/sbin/ipf/libipf/checkrev.c (revision 41edb306f05651fcaf6c74f9e3557f59f80292e1)
1*41edb306SCy Schubert /*	$FreeBSD$	*/
2*41edb306SCy Schubert 
3*41edb306SCy Schubert /*
4*41edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
5*41edb306SCy Schubert  *
6*41edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
7*41edb306SCy Schubert  *
8*41edb306SCy Schubert  * $Id$
9*41edb306SCy Schubert  */
10*41edb306SCy Schubert 
11*41edb306SCy Schubert #include <sys/ioctl.h>
12*41edb306SCy Schubert #include <fcntl.h>
13*41edb306SCy Schubert 
14*41edb306SCy Schubert #include "ipf.h"
15*41edb306SCy Schubert #include "netinet/ipl.h"
16*41edb306SCy Schubert 
17*41edb306SCy Schubert int checkrev(ipfname)
18*41edb306SCy Schubert 	char *ipfname;
19*41edb306SCy Schubert {
20*41edb306SCy Schubert 	static int vfd = -1;
21*41edb306SCy Schubert 	struct friostat fio;
22*41edb306SCy Schubert 	ipfobj_t obj;
23*41edb306SCy Schubert 
24*41edb306SCy Schubert 	bzero((caddr_t)&obj, sizeof(obj));
25*41edb306SCy Schubert 	obj.ipfo_rev = IPFILTER_VERSION;
26*41edb306SCy Schubert 	obj.ipfo_size = sizeof(fio);
27*41edb306SCy Schubert 	obj.ipfo_ptr = (void *)&fio;
28*41edb306SCy Schubert 	obj.ipfo_type = IPFOBJ_IPFSTAT;
29*41edb306SCy Schubert 
30*41edb306SCy Schubert 	if ((vfd == -1) && ((vfd = open(ipfname, O_RDONLY)) == -1)) {
31*41edb306SCy Schubert 		perror("open device");
32*41edb306SCy Schubert 		return -1;
33*41edb306SCy Schubert 	}
34*41edb306SCy Schubert 
35*41edb306SCy Schubert 	if (ioctl(vfd, SIOCGETFS, &obj)) {
36*41edb306SCy Schubert 		ipferror(vfd, "ioctl(SIOCGETFS)");
37*41edb306SCy Schubert 		close(vfd);
38*41edb306SCy Schubert 		vfd = -1;
39*41edb306SCy Schubert 		return -1;
40*41edb306SCy Schubert 	}
41*41edb306SCy Schubert 
42*41edb306SCy Schubert 	if (strncmp(IPL_VERSION, fio.f_version, sizeof(fio.f_version))) {
43*41edb306SCy Schubert 		return -1;
44*41edb306SCy Schubert 	}
45*41edb306SCy Schubert 	return 0;
46*41edb306SCy Schubert }
47