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