1 /* $Id: testportinuse.c,v 1.4 2016/02/09 09:37:44 nanard Exp $ */
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 */
10 #include <netinet/in.h>
15 #include "portinuse.h"
18 const char * miniupnpd_nat_chain
= "MINIUPNPD";
19 const char * miniupnpd_nat_postrouting_chain
= "MINIUPNPD-POSTROUTING";
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 */
37 fprintf(stderr
, "usage: %s if_name eport (tcp|udp) iaddr iport\n",
41 openlog("testportinuse", LOG_CONS
|LOG_PERROR
, LOG_USER
);
43 eport
= (unsigned)atoi(argv
[2]);
44 proto
= (0==strcmp(argv
[3], "tcp"))?IPPROTO_TCP
:IPPROTO_UDP
;
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
);
52 #endif /* CHECK_PORTINUSE */