xref: /netbsd-src/external/bsd/ipf/dist/lib/ipf_perror.c (revision c9d5dc6c77aa32fd07899a7a63638e95ffa433dd)
1 /*	$NetBSD: ipf_perror.c,v 1.1.1.2 2012/07/22 13:44:39 darrenr Exp $	*/
2 
3 #include <fcntl.h>
4 #include <sys/ioctl.h>
5 #include "ipf.h"
6 
7 void
ipf_perror(err,string)8 ipf_perror(err, string)
9 	int err;
10 	char *string;
11 {
12 	if (err == 0)
13 		fprintf(stderr, "%s\n", string);
14 	else
15 		fprintf(stderr, "%s %s\n", string, ipf_strerror(err));
16 }
17 
18 int
ipf_perror_fd(fd,iocfunc,string)19 ipf_perror_fd(fd, iocfunc, string)
20 	int fd;
21 	ioctlfunc_t iocfunc;
22 	char *string;
23 {
24 	int save;
25 	int realerr;
26 
27 	save = errno;
28 	if ((*iocfunc)(fd, SIOCIPFINTERROR, &realerr) == -1)
29 		realerr = 0;
30 
31 	errno = save;
32 	fprintf(stderr, "%d:", realerr);
33 	ipf_perror(realerr, string);
34 	return realerr ? realerr : save;
35 
36 }
37 
38 void
ipferror(fd,msg)39 ipferror(fd, msg)
40 	int fd;
41 	char *msg;
42 {
43 	if (fd >= 0) {
44 		ipf_perror_fd(fd, ioctl, msg);
45 	} else {
46 		fprintf(stderr, "0:");
47 		perror(msg);
48 	}
49 }
50