1: /* $Id: testupnppermissions.c,v 1.1.1.1 2012/02/21 23:16:02 misho Exp $ */
2: /* (c) 2007-2009 Thomas Bernard
3: * MiniUPnP Project
4: * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5: */
6: #include <stdio.h>
7: #include <string.h>
8: #include <syslog.h>
9: #include <sys/types.h>
10: #include <sys/socket.h>
11: #include <netinet/in.h>
12: #include <arpa/inet.h>
13: #include "upnppermissions.h"
14:
15: void
16: print_upnpperm(const struct upnpperm * p)
17: {
18: switch(p->type)
19: {
20: case UPNPPERM_ALLOW:
21: printf("allow ");
22: break;
23: case UPNPPERM_DENY:
24: printf("deny ");
25: break;
26: default:
27: printf("error ! ");
28: }
29: printf("%hu-%hu ", p->eport_min, p->eport_max);
30: printf("%s/", inet_ntoa(p->address));
31: printf("%s ", inet_ntoa(p->mask));
32: printf("%hu-%hu", p->iport_min, p->iport_max);
33: putchar('\n');
34: }
35:
36: int main(int argc, char * * argv)
37: {
38: int i, r;
39: struct upnpperm p;
40: if(argc < 2) {
41: fprintf(stderr, "Usage: %s \"permission line\" [...]\n", argv[0]);
42: fprintf(stderr, "Example: %s \"allow 1234 10.10.10.10/32 1234\"\n", argv[0]);
43: return 1;
44: }
45: openlog("testupnppermissions", LOG_PERROR, LOG_USER);
46: /* for(i=0; i<argc; i++)
47: printf("%2d '%s'\n", i, argv[i]); */
48: for(i=1; i<argc; i++) {
49: printf("%2d '%s'\n", i, argv[i]);
50: memset(&p, 0, sizeof(struct upnpperm));
51: r = read_permission_line(&p, argv[i]);
52: if(r==0) {
53: printf("Permission read successfully\n");
54: print_upnpperm(&p);
55: } else {
56: printf("Permission read failed, please check its correctness\n");
57: }
58: putchar('\n');
59: }
60: return 0;
61: }
62:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>