]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ipfilter/lib/ipf_perror.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ipfilter / lib / ipf_perror.c
1 #include <fcntl.h>
2 #include <sys/ioctl.h>
3 #include "ipf.h"
4
5 void
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
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
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 }