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