miniupnpd 1.9 (20160113)
[tomato.git] / release / src / router / miniupnpd / testportinuse.c
blob4e2625e39962807c32209c11bd15a0c6dea7a835
1 /* $Id: testportinuse.c,v 1.3 2014/03/28 12:13:17 nanard Exp $ */
2 /* MiniUPnP project
3 * (c) 2014 Thomas Bernard
4 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5 * This software is subject to the conditions detailed
6 * in the LICENCE file provided within the distribution */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <netinet/in.h>
11 #include <syslog.h>
13 #include "macros.h"
14 #include "config.h"
15 #include "portinuse.h"
17 #ifdef USE_NETFILTER
18 const char * miniupnpd_nat_chain = "MINIUPNPD";
19 const char * miniupnpd_peer_chain = "MINIUPNPD-PCP-PEER";
20 const char * miniupnpd_forward_chain = "MINIUPNPD";
21 #endif /* USE_NETFILTER */
23 int main(int argc, char * * argv)
25 #ifndef CHECK_PORTINUSE
26 UNUSED(argc); UNUSED(argv);
27 printf("CHECK_PORTINUSE is not defined.\n");
28 #else /* CHECK_PORTINUSE */
29 int r;
30 const char * if_name;
31 unsigned eport;
32 int proto;
33 const char * iaddr;
34 unsigned iport;
36 if(argc <= 5) {
37 fprintf(stderr, "usage: %s if_name eport (tcp|udp) iaddr iport\n",
38 argv[0]);
39 return 1;
41 openlog("testportinuse", LOG_CONS|LOG_PERROR, LOG_USER);
42 if_name = argv[1];
43 eport = (unsigned)atoi(argv[2]);
44 proto = (0==strcmp(argv[3], "tcp"))?IPPROTO_TCP:IPPROTO_UDP;
45 iaddr = argv[4];
46 iport = (unsigned)atoi(argv[5]);
48 r = port_in_use(if_name, eport, proto, iaddr, iport);
49 printf("port_in_use(%s, %u, %d, %s, %u) returned %d\n",
50 if_name, eport, proto, iaddr, iport, r);
51 closelog();
52 #endif /* CHECK_PORTINUSE */
53 return 0;