]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/lib/checkrev.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / lib / checkrev.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2000-2004 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * $Id: checkrev.c,v 1.12.2.2 2006/06/16 17:20:56 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, *fiop = &fio;
22         ipfobj_t ipfo;
23
24         bzero((caddr_t)&ipfo, sizeof(ipfo));
25         ipfo.ipfo_rev = IPFILTER_VERSION;
26         ipfo.ipfo_size = sizeof(*fiop);
27         ipfo.ipfo_ptr = (void *)fiop;
28         ipfo.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, &ipfo)) {
36                 perror("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 }