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