1 
2 #include <sys/types.h>
3 #include <sys/socket.h>
4 #include <fcntl.h>
5 #include <sys/ioctl.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <netinet/in.h>
9 #include <net/if.h>
10 #include "ip_compat.h"
11 #include "ip_fil.h"
12 #include "ip_auth.h"
13 
14 extern	int	errno;
15 
16 main()
17 {
18 	struct frauth fra;
19 	struct frauth *frap = &fra;
20 	fr_info_t *fin = &fra.fra_info;
21 	fr_ip_t	*fi = &fin->fin_fi;
22 	char yn[16];
23 	int fd;
24 
25 	fd = open(IPL_NAME, O_RDWR);
26 	fra.fra_len = 0;
27 	fra.fra_buf = NULL;
28 	while (ioctl(fd, SIOCAUTHW, &frap) == 0) {
29 		if (fra.fra_info.fin_out)
30 			fra.fra_pass = FR_OUTQUE;
31 		else
32 			fra.fra_pass = FR_INQUE;
33 
34 		printf("%s ", inet_ntoa(fi->fi_src));
35 		if (fi->fi_flx & FI_TCPUDP)
36 			printf("port %d ", fin->fin_data[0]);
37 		printf("-> %s ", inet_ntoa(fi->fi_dst));
38 		if (fi->fi_flx & FI_TCPUDP)
39 			printf("port %d ", fin->fin_data[1]);
40 		printf("\n");
41 		printf("Allow packet through ? [y/n]");
42 		fflush(stdout);
43 		if (!fgets(yn, sizeof(yn), stdin))
44 			break;
45 		fflush(stdin);
46 		if (yn[0] == 'n' || yn[0] == 'N')
47 			fra.fra_pass |= FR_BLOCK;
48 		else if (yn[0] == 'y' || yn[0] == 'Y') {
49 			fra.fra_pass |= FR_PASS;
50 			if (fra.fra_info.fin_fi.fi_flx & FI_TCPUDP)
51 				fra.fra_pass |= FR_KEEPSTATE;
52 		} else
53 			fra.fra_pass |= FR_NOMATCH;
54 		printf("answer = %c (%x), id %d idx %d\n", yn[0],
55 			fra.fra_pass, fra.fra_info.fin_id, fra.fra_index);
56 		if (ioctl(fd, SIOCAUTHR, &frap) != 0)
57 			perror("SIOCAUTHR");
58 	}
59 	fprintf(stderr, "errno=%d \n", errno);
60 	perror("frauth-SIOCAUTHW");
61 }
62