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