xref: /freebsd/sbin/ipf/libipf/checkrev.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  *
741edb306SCy Schubert  * $Id$
841edb306SCy Schubert  */
941edb306SCy Schubert 
1041edb306SCy Schubert #include <sys/ioctl.h>
1141edb306SCy Schubert #include <fcntl.h>
1241edb306SCy Schubert 
1341edb306SCy Schubert #include "ipf.h"
1441edb306SCy Schubert #include "netinet/ipl.h"
1541edb306SCy Schubert 
16efeb8bffSCy Schubert int
checkrev(char * ipfname)17efeb8bffSCy Schubert checkrev(char *ipfname)
1841edb306SCy Schubert {
1941edb306SCy Schubert 	static int vfd = -1;
2041edb306SCy Schubert 	struct friostat fio;
2141edb306SCy Schubert 	ipfobj_t obj;
2241edb306SCy Schubert 
2341edb306SCy Schubert 	bzero((caddr_t)&obj, sizeof(obj));
2441edb306SCy Schubert 	obj.ipfo_rev = IPFILTER_VERSION;
2541edb306SCy Schubert 	obj.ipfo_size = sizeof(fio);
2641edb306SCy Schubert 	obj.ipfo_ptr = (void *)&fio;
2741edb306SCy Schubert 	obj.ipfo_type = IPFOBJ_IPFSTAT;
2841edb306SCy Schubert 
2941edb306SCy Schubert 	if ((vfd == -1) && ((vfd = open(ipfname, O_RDONLY)) == -1)) {
3041edb306SCy Schubert 		perror("open device");
31*2582ae57SCy Schubert 		return (-1);
3241edb306SCy Schubert 	}
3341edb306SCy Schubert 
3441edb306SCy Schubert 	if (ioctl(vfd, SIOCGETFS, &obj)) {
3541edb306SCy Schubert 		ipferror(vfd, "ioctl(SIOCGETFS)");
3641edb306SCy Schubert 		close(vfd);
3741edb306SCy Schubert 		vfd = -1;
38*2582ae57SCy Schubert 		return (-1);
3941edb306SCy Schubert 	}
4041edb306SCy Schubert 
4141edb306SCy Schubert 	if (strncmp(IPL_VERSION, fio.f_version, sizeof(fio.f_version))) {
42*2582ae57SCy Schubert 		return (-1);
4341edb306SCy Schubert 	}
44*2582ae57SCy Schubert 	return (0);
4541edb306SCy Schubert }
46