xref: /titanic_51/usr/src/cmd/ipf/lib/common/checkrev.c (revision ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (C) 1993-2001 by Darren Reed.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
57c478bd9Sstevel@tonic-gate  *
6*ab25eeb5Syz155240  * $Id: checkrev.c,v 1.12.2.1 2004/03/09 14:44:39 darrenr Exp $
77c478bd9Sstevel@tonic-gate  */
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
107c478bd9Sstevel@tonic-gate #include <fcntl.h>
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate #include "ipf.h"
13*ab25eeb5Syz155240 #include "netinet/ipl.h"
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate int checkrev(ipfname)
167c478bd9Sstevel@tonic-gate char *ipfname;
177c478bd9Sstevel@tonic-gate {
18*ab25eeb5Syz155240 	static int vfd = -1;
197c478bd9Sstevel@tonic-gate 	struct friostat fio, *fiop = &fio;
207c478bd9Sstevel@tonic-gate 	ipfobj_t ipfo;
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate 	bzero((caddr_t)&ipfo, sizeof(ipfo));
237c478bd9Sstevel@tonic-gate 	ipfo.ipfo_rev = IPFILTER_VERSION;
247c478bd9Sstevel@tonic-gate 	ipfo.ipfo_size = sizeof(*fiop);
257c478bd9Sstevel@tonic-gate 	ipfo.ipfo_ptr = (void *)fiop;
267c478bd9Sstevel@tonic-gate 	ipfo.ipfo_type = IPFOBJ_IPFSTAT;
277c478bd9Sstevel@tonic-gate 
28*ab25eeb5Syz155240 	if ((vfd == -1) && ((vfd = open(ipfname, O_RDONLY)) == -1)) {
297c478bd9Sstevel@tonic-gate 		perror("open device");
307c478bd9Sstevel@tonic-gate 		return -1;
317c478bd9Sstevel@tonic-gate 	}
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate 	if (ioctl(vfd, SIOCGETFS, &ipfo)) {
347c478bd9Sstevel@tonic-gate 		perror("ioctl(SIOCGETFS)");
357c478bd9Sstevel@tonic-gate 		close(vfd);
36*ab25eeb5Syz155240 		vfd = -1;
377c478bd9Sstevel@tonic-gate 		return -1;
387c478bd9Sstevel@tonic-gate 	}
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 	if (strncmp(IPL_VERSION, fio.f_version, sizeof(fio.f_version))) {
417c478bd9Sstevel@tonic-gate 		return -1;
427c478bd9Sstevel@tonic-gate 	}
437c478bd9Sstevel@tonic-gate 	return 0;
447c478bd9Sstevel@tonic-gate }
45