aboutsummaryrefslogtreecommitdiff
path: root/contrib/ipfilter/lib/ipf_perror.c
blob: 08e31648b053b6da935bae7f7b405af776b2a723 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <fcntl.h>
#include <sys/ioctl.h>
#include "ipf.h"

void
ipf_perror(err, string)
	int err;
	char *string;
{
	if (err == 0)
		fprintf(stderr, "%s\n", string);
	else
		fprintf(stderr, "%s: %s\n", string, ipf_strerror(err));
}

int
ipf_perror_fd(fd, iocfunc, string)
	int fd;
	ioctlfunc_t iocfunc;
	char *string;
{
	int save;
	int realerr;

	save = errno;
	if ((*iocfunc)(fd, SIOCIPFINTERROR, &realerr) == -1)
		realerr = 0;

	errno = save;
	fprintf(stderr, "%d:", realerr);
	ipf_perror(realerr, string);
	return realerr ? realerr : save;

}

void
ipferror(fd, msg)
	int fd;
	char *msg;
{
	if (fd >= 0) {
		ipf_perror_fd(fd, ioctl, msg);
	} else {
		fprintf(stderr, "0:");
		perror(msg);
	}
}