miniupnpd: add testportinuse test program
This commit is contained in:
parent
09bbaac63a
commit
dcce22647d
|
@ -1,4 +1,4 @@
|
|||
# $Id: Makefile,v 1.76 2014/03/10 10:26:15 nanard Exp $
|
||||
# $Id: Makefile,v 1.76.2.2 2014/03/14 10:49:08 nanard Exp $
|
||||
# MiniUPnP project
|
||||
# http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
# Author: Thomas Bernard
|
||||
|
@ -117,10 +117,13 @@ TESTUPNPPERMISSIONSOBJS = testupnppermissions.o upnppermissions.o
|
|||
TESTGETIFADDROBJS = testgetifaddr.o getifaddr.o
|
||||
MINIUPNPDCTLOBJS = miniupnpdctl.o
|
||||
TESTASYNCSENDTOOBJS = testasyncsendto.o asyncsendto.o upnputils.o bsd/getroute.o
|
||||
TESTPORTINUSEOBJS = testportinuse.o portinuse.o getifaddr.o
|
||||
|
||||
EXECUTABLES = miniupnpd testupnpdescgen testgetifstats \
|
||||
testupnppermissions miniupnpdctl \
|
||||
testgetifaddr testgetroute testasyncsendto
|
||||
testgetifaddr testgetroute testasyncsendto \
|
||||
testportinuse
|
||||
|
||||
.if $(OSNAME) == "Darwin"
|
||||
LIBS =
|
||||
.else
|
||||
|
@ -144,6 +147,7 @@ clean:
|
|||
testupnpdescgen.o \
|
||||
$(MISCOBJS) config.h testgetifstats.o testupnppermissions.o \
|
||||
miniupnpdctl.o testgetifaddr.o testgetroute.o testasyncsendto.o \
|
||||
testportinuse.o \
|
||||
$(PFOBJS) $(IPFOBJS) $(IPFWOBJS)
|
||||
|
||||
install: miniupnpd genuuid
|
||||
|
@ -174,7 +178,7 @@ genuuid:
|
|||
depend: config.h
|
||||
mkdep $(ALLOBJS:.o=.c) testupnpdescgen.c testgetifstats.c \
|
||||
testupnppermissions.c miniupnpdctl.c testgetifaddr.c \
|
||||
testgetroute.c
|
||||
testgetroute.c testportinuse.c testasyncsendto.c
|
||||
|
||||
miniupnpd: config.h $(ALLOBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(ALLOBJS) $(LIBS)
|
||||
|
@ -203,6 +207,9 @@ testgetroute: config.h $(TESTGETROUTEOBJS)
|
|||
testasyncsendto: config.h $(TESTASYNCSENDTOOBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(TESTASYNCSENDTOOBJS)
|
||||
|
||||
testportinuse: config.h $(TESTPORTINUSEOBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(TESTPORTINUSEOBJS) -lkvm
|
||||
|
||||
# gmake :
|
||||
# $(CC) $(CFLAGS) -o $@ $^
|
||||
# BSDmake :
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $Id: Makefile.linux,v 1.81 2014/01/27 10:06:58 nanard Exp $
|
||||
# $Id: Makefile.linux,v 1.83.2.3 2014/03/14 11:04:06 nanard Exp $
|
||||
# MiniUPnP project
|
||||
# (c) 2006-2014 Thomas Bernard
|
||||
# http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
|
@ -150,7 +150,7 @@ TESTUPNPDESCGENOBJS = testupnpdescgen.o upnpdescgen.o
|
|||
|
||||
EXECUTABLES = miniupnpd testupnpdescgen testgetifstats \
|
||||
testupnppermissions miniupnpdctl testgetifaddr \
|
||||
testgetroute testasyncsendto
|
||||
testgetroute testasyncsendto testportinuse
|
||||
|
||||
.PHONY: all clean install depend genuuid
|
||||
|
||||
|
@ -208,6 +208,9 @@ testgetroute: testgetroute.o linux/getroute.o upnputils.o -lnfnetlink
|
|||
testasyncsendto: testasyncsendto.o asyncsendto.o upnputils.o \
|
||||
linux/getroute.o -lnfnetlink
|
||||
|
||||
testportinuse: testportinuse.o portinuse.o getifaddr.o \
|
||||
netfilter/iptcrdr.o $(LIBS)
|
||||
|
||||
miniupnpdctl: miniupnpdctl.o
|
||||
|
||||
config.h: genconfig.sh VERSION
|
||||
|
@ -217,7 +220,8 @@ depend: config.h
|
|||
makedepend -f$(MAKEFILE_LIST) -Y \
|
||||
$(ALLOBJS:.o=.c) $(TESTUPNPDESCGENOBJS:.o=.c) \
|
||||
testgetifstats.c testupnppermissions.c testgetifaddr.c \
|
||||
testgetroute.c testasyncsendto.c miniupnpdctl.c 2>/dev/null
|
||||
testgetroute.c testasyncsendto.c testportinuse.c \
|
||||
miniupnpdctl.c 2>/dev/null
|
||||
|
||||
# DO NOT DELETE
|
||||
|
||||
|
@ -292,4 +296,5 @@ testgetifaddr.o: config.h getifaddr.h
|
|||
testgetroute.o: getroute.h upnputils.h upnpglobalvars.h upnppermissions.h
|
||||
testgetroute.o: config.h miniupnpdtypes.h
|
||||
testasyncsendto.o: miniupnpdtypes.h config.h upnputils.h asyncsendto.h
|
||||
testportinuse.o: macros.h config.h portinuse.h
|
||||
miniupnpdctl.o: macros.h
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/* $Id $ */
|
||||
/* MiniUPnP project
|
||||
* (c) 2014 Thomas Bernard
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "macros.h"
|
||||
#include "config.h"
|
||||
#include "portinuse.h"
|
||||
|
||||
#ifdef CHECK_PORTINUSE
|
||||
#ifdef USE_NETFILTER
|
||||
const char * miniupnpd_nat_chain = "MINIUPNPD";
|
||||
const char * miniupnpd_peer_chain = "MINIUPNPD-PCP-PEER";
|
||||
const char * miniupnpd_forward_chain = "MINIUPNPD";
|
||||
#endif /* USE_NETFILTER */
|
||||
#endif /* CHECK_PORTINUSE */
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
#ifndef CHECK_PORTINUSE
|
||||
UNUSED(argc); UNUSED(argv);
|
||||
printf("CHECK_PORTINUSE is not defined.\n");
|
||||
#else /* CHECK_PORTINUSE */
|
||||
int r;
|
||||
const char * if_name;
|
||||
unsigned eport;
|
||||
int proto;
|
||||
const char * iaddr;
|
||||
unsigned iport;
|
||||
|
||||
if(argc <= 5) {
|
||||
fprintf(stderr, "usage: %s if_name eport (tcp|udp) iaddr iport\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
openlog("testportinuse", LOG_CONS|LOG_PERROR, LOG_USER);
|
||||
if_name = argv[1];
|
||||
eport = (unsigned)atoi(argv[2]);
|
||||
proto = (0==strcmp(argv[3], "tcp"))?IPPROTO_TCP:IPPROTO_UDP;
|
||||
iaddr = argv[4];
|
||||
iport = (unsigned)atoi(argv[5]);
|
||||
|
||||
r = port_in_use(if_name, eport, proto, iaddr, iport);
|
||||
printf("port_in_use(%s, %u, %d, %s, %u) returned %d\n",
|
||||
if_name, eport, proto, iaddr, iport, r);
|
||||
closelog();
|
||||
#endif /* CHECK_PORTINUSE */
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue