Remove unused files from lib/netplay/miniupnpc.
parent
435f352672
commit
583c318c2e
|
@ -3,29 +3,32 @@ AM_CFLAGS = -DSTATICLIB $(WZ_CFLAGS)
|
|||
|
||||
noinst_LIBRARIES = libminiupnpc.a
|
||||
noinst_HEADERS = \
|
||||
bsdqueue.h \
|
||||
codelength.h \
|
||||
declspec.h \
|
||||
igd_desc_parse.h \
|
||||
minisoap.h \
|
||||
minissdpc.h \
|
||||
miniupnpc.h \
|
||||
miniupnpcstrings.h \
|
||||
miniwget.h \
|
||||
minixml.h \
|
||||
minisoap.h \
|
||||
minissdpc.h \
|
||||
codelength.h \
|
||||
upnpcommands.h \
|
||||
igd_desc_parse.h \
|
||||
upnpreplyparse.h \
|
||||
upnperrors.h \
|
||||
declspec.h \
|
||||
bsdqueue.h
|
||||
upnpreplyparse.h
|
||||
|
||||
libminiupnpc_a_SOURCES = \
|
||||
miniwget.c \
|
||||
minixml.c \
|
||||
igd_desc_parse.c \
|
||||
minisoap.c \
|
||||
miniupnpc.c \
|
||||
upnpreplyparse.c \
|
||||
upnpcommands.c \
|
||||
minissdpc.c \
|
||||
upnperrors.c
|
||||
miniupnpc.c \
|
||||
miniwget.c \
|
||||
minixml.c \
|
||||
upnpcommands.c \
|
||||
upnperrors.c \
|
||||
upnpreplyparse.c
|
||||
|
||||
EXTRA_DIST = LICENCE README
|
||||
EXTRA_DIST = \
|
||||
Changelog.txt \
|
||||
LICENCE \
|
||||
README
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
# $Id: Makefile.mingw,v 1.9 2008/07/02 23:31:15 nanard Exp $
|
||||
# Miniupnp project.
|
||||
# http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
# (c) 2005-2008 Thomas Bernard
|
||||
CC = gcc
|
||||
#CFLAGS = -Wall -g -DDEBUG
|
||||
CFLAGS = -Wall -Os -DNDEBUG
|
||||
LDLIBS = -lws2_32
|
||||
# -lwsock32
|
||||
PYTHON=\utils\python25\python
|
||||
OBJS=miniwget.o minixml.o igd_desc_parse.o minisoap.o \
|
||||
miniupnpc.o upnpreplyparse.o upnpcommands.o upnperrors.o
|
||||
OBJSDLL=$(addprefix dll/, $(OBJS))
|
||||
|
||||
all: init upnpc-static upnpc-shared testminixml libminiupnpc.a miniupnpc.dll
|
||||
|
||||
init:
|
||||
mkdir dll
|
||||
echo "" > init
|
||||
|
||||
clean:
|
||||
del upnpc testminixml *.o
|
||||
del dll/*.o
|
||||
|
||||
libminiupnpc.a: $(OBJS)
|
||||
$(AR) cr $@ $?
|
||||
|
||||
pythonmodule: libminiupnpc.a
|
||||
$(PYTHON) setupmingw32.py build --compiler=mingw32
|
||||
$(PYTHON) setupmingw32.py install --skip-build
|
||||
|
||||
miniupnpc.dll: libminiupnpc.a $(OBJSDLL)
|
||||
dllwrap -k --driver-name gcc --def miniupnpc.def \
|
||||
--output-def miniupnpc.dll.def --implib miniupnpc.lib -o $@ \
|
||||
$(OBJSDLL) $(LDLIBS)
|
||||
|
||||
miniupnpc.lib: miniupnpc.dll
|
||||
echo $@ generated with $<
|
||||
|
||||
dll/upnpc.o: upnpc.o
|
||||
echo $@ generated with $<
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -DSTATICLIB -c -o $@ $<
|
||||
$(CC) $(CFLAGS) -DMINIUPNP_EXPORTS -c -o dll/$@ $<
|
||||
|
||||
upnpc.o:
|
||||
$(CC) $(CFLAGS) -DSTATICLIB -c -o $@ $<
|
||||
$(CC) $(CFLAGS) -c -o dll/$@ $<
|
||||
|
||||
upnpc-static: upnpc.o libminiupnpc.a
|
||||
$(CC) -o $@ $^ $(LDLIBS)
|
||||
|
||||
upnpc-shared: dll/upnpc.o miniupnpc.lib
|
||||
$(CC) -o $@ $^ $(LDLIBS)
|
||||
|
||||
minixml.o: minixml.c minixml.h
|
||||
|
||||
upnpc.o: upnpc.c miniwget.h minisoap.h miniupnpc.h igd_desc_parse.h upnpreplyparse.h upnpcommands.h
|
||||
|
||||
miniwget.o: miniwget.c miniwget.h
|
||||
|
||||
minisoap.o: minisoap.c minisoap.h
|
||||
|
||||
miniupnpc.o: miniupnpc.c miniupnpc.h minisoap.h miniwget.h minixml.h
|
||||
|
||||
igd_desc_parse.o: igd_desc_parse.c igd_desc_parse.h
|
||||
|
||||
testminixml: minixml.o igd_desc_parse.o testminixml.c
|
||||
|
||||
upnpreplyparse.o: upnpreplyparse.c upnpreplyparse.h minixml.h
|
||||
|
||||
upnpcommands.o: upnpcommands.c upnpcommands.h upnpreplyparse.h miniupnpc.h
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
# $Id: Makefile,v 1.55 2009/10/10 19:15:34 nanard Exp $
|
||||
# MiniUPnP Project
|
||||
# http://miniupnp.free.fr/
|
||||
# (c) 2005-2009 Thomas Bernard
|
||||
# to install use :
|
||||
# $ PREFIX=/tmp/dummylocation make install
|
||||
# or
|
||||
# $ INSTALLPREFIX=/usr/local make install
|
||||
# or
|
||||
# make install (will go to /usr/bin, /usr/lib, etc...)
|
||||
OS = $(shell uname -s)
|
||||
CC ?= gcc
|
||||
#AR = gar
|
||||
#CFLAGS = -fPIC -O -Wall -g -DDEBUG
|
||||
CFLAGS ?= -fPIC -O -Wall -DNDEBUG -DMINIUPNPC_SET_SOCKET_TIMEOUT
|
||||
INSTALL = install
|
||||
SH = /bin/sh
|
||||
#following libs are needed on Solaris
|
||||
#LDLIBS=-lsocket -lnsl -lresolv
|
||||
|
||||
# APIVERSION is used to build SONAME
|
||||
APIVERSION = 4
|
||||
|
||||
SRCS = igd_desc_parse.c miniupnpc.c minixml.c minisoap.c miniwget.c \
|
||||
upnpc.c upnpcommands.c upnpreplyparse.c testminixml.c \
|
||||
minixmlvalid.c testupnpreplyparse.c minissdpc.c \
|
||||
upnperrors.c testigddescparse.c
|
||||
|
||||
LIBOBJS = miniwget.o minixml.o igd_desc_parse.o minisoap.o \
|
||||
miniupnpc.o upnpreplyparse.o upnpcommands.o minissdpc.o \
|
||||
upnperrors.o
|
||||
|
||||
OBJS = $(patsubst %.c,%.o,$(SRCS))
|
||||
|
||||
# HEADERS to install
|
||||
HEADERS = miniupnpc.h miniwget.h upnpcommands.h igd_desc_parse.h \
|
||||
upnpreplyparse.h upnperrors.h declspec.h
|
||||
# library names
|
||||
LIBRARY = libminiupnpc.a
|
||||
ifeq ($(OS), Darwin)
|
||||
SHAREDLIBRARY = libminiupnpc.dylib
|
||||
SONAME = $(basename $(SHAREDLIBRARY)).$(APIVERSION).dylib
|
||||
else
|
||||
SHAREDLIBRARY = libminiupnpc.so
|
||||
SONAME = $(SHAREDLIBRARY).$(APIVERSION)
|
||||
endif
|
||||
|
||||
EXECUTABLES = upnpc-static upnpc-shared \
|
||||
testminixml minixmlvalid testupnpreplyparse \
|
||||
testigddescparse
|
||||
|
||||
# install directories
|
||||
INSTALLPREFIX ?= $(PREFIX)/usr
|
||||
INSTALLDIRINC = $(INSTALLPREFIX)/include/miniupnpc
|
||||
INSTALLDIRLIB = $(INSTALLPREFIX)/lib
|
||||
INSTALLDIRBIN = $(INSTALLPREFIX)/bin
|
||||
|
||||
.PHONY: install clean depend all installpythonmodule
|
||||
|
||||
all: validateminixml $(LIBRARY) $(EXECUTABLES)
|
||||
|
||||
pythonmodule: $(LIBRARY) miniupnpcmodule.c setup.py
|
||||
python setup.py build
|
||||
touch $@
|
||||
|
||||
installpythonmodule: pythonmodule
|
||||
python setup.py install
|
||||
|
||||
validateminixml: minixmlvalid
|
||||
@echo "minixml validation test"
|
||||
./minixmlvalid
|
||||
touch $@
|
||||
|
||||
clean:
|
||||
$(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) miniupnpcstrings.h
|
||||
# clean python stuff
|
||||
$(RM) pythonmodule validateminixml
|
||||
$(RM) -r build/ dist/
|
||||
#python setup.py clean
|
||||
|
||||
install: $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES)
|
||||
$(INSTALL) -d $(INSTALLDIRINC)
|
||||
$(INSTALL) -m 644 $(HEADERS) $(INSTALLDIRINC)
|
||||
$(INSTALL) -d $(INSTALLDIRLIB)
|
||||
$(INSTALL) -m 644 $(LIBRARY) $(INSTALLDIRLIB)
|
||||
$(INSTALL) -m 644 $(SHAREDLIBRARY) $(INSTALLDIRLIB)/$(SONAME)
|
||||
$(INSTALL) -d $(INSTALLDIRBIN)
|
||||
$(INSTALL) -m 755 upnpc-shared $(INSTALLDIRBIN)/upnpc
|
||||
ln -fs $(SONAME) $(INSTALLDIRLIB)/$(SHAREDLIBRARY)
|
||||
|
||||
cleaninstall:
|
||||
$(RM) -r $(INSTALLDIRINC)
|
||||
$(RM) $(INSTALLDIRLIB)/$(LIBRARY)
|
||||
$(RM) $(INSTALLDIRLIB)/$(SHAREDLIBRARY)
|
||||
|
||||
depend:
|
||||
makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null
|
||||
|
||||
$(LIBRARY): $(LIBOBJS)
|
||||
$(AR) crs $@ $?
|
||||
|
||||
$(SHAREDLIBRARY): $(LIBOBJS)
|
||||
ifeq ($(OS), Darwin)
|
||||
$(CC) -dynamiclib -Wl,-install_name,$(SONAME) -o $@ $^
|
||||
else
|
||||
$(CC) -shared -Wl,-soname,$(SONAME) -o $@ $^
|
||||
endif
|
||||
|
||||
upnpc-static: upnpc.o $(LIBRARY) $(LDLIBS)
|
||||
$(CC) -o $@ $^
|
||||
|
||||
upnpc-shared: upnpc.o $(SHAREDLIBRARY) $(LDLIBS)
|
||||
$(CC) -o $@ $^
|
||||
|
||||
testminixml: minixml.o igd_desc_parse.o testminixml.o
|
||||
|
||||
minixmlvalid: minixml.o minixmlvalid.o
|
||||
|
||||
testupnpreplyparse: testupnpreplyparse.o minixml.o upnpreplyparse.o
|
||||
|
||||
testigddescparse: testigddescparse.o igd_desc_parse.o minixml.o
|
||||
|
||||
miniupnpcstrings.h: miniupnpcstrings.h.in updateminiupnpcstrings.sh
|
||||
$(SH) updateminiupnpcstrings.sh
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
igd_desc_parse.o: igd_desc_parse.h
|
||||
miniupnpc.o: miniupnpc.h declspec.h igd_desc_parse.h minissdpc.h miniwget.h
|
||||
miniupnpc.o: minisoap.h minixml.h upnpcommands.h upnpreplyparse.h
|
||||
minixml.o: minixml.h
|
||||
minisoap.o: minisoap.h miniupnpcstrings.h
|
||||
miniwget.o: miniupnpc.h declspec.h igd_desc_parse.h miniupnpcstrings.h
|
||||
miniwget.o: miniwget.h
|
||||
upnpc.o: miniwget.h declspec.h miniupnpc.h igd_desc_parse.h upnpcommands.h
|
||||
upnpc.o: upnpreplyparse.h upnperrors.h
|
||||
upnpcommands.o: upnpcommands.h upnpreplyparse.h declspec.h miniupnpc.h
|
||||
upnpcommands.o: igd_desc_parse.h
|
||||
upnpreplyparse.o: upnpreplyparse.h minixml.h
|
||||
testminixml.o: minixml.h igd_desc_parse.h
|
||||
minixmlvalid.o: minixml.h
|
||||
testupnpreplyparse.o: upnpreplyparse.h
|
||||
minissdpc.o: minissdpc.h miniupnpc.h declspec.h igd_desc_parse.h codelength.h
|
||||
upnperrors.o: upnperrors.h declspec.h upnpcommands.h upnpreplyparse.h
|
||||
testigddescparse.o: igd_desc_parse.h minixml.h
|
|
@ -1,52 +0,0 @@
|
|||
\" $Id: miniupnpc.3,v 1.2 2008/10/07 13:51:55 nanard Exp $
|
||||
.TH miniupnpc 3
|
||||
.SH NAME
|
||||
miniupnpc \- UPnP client library
|
||||
.SH SYNOPSIS
|
||||
.SH DESCRIPTION
|
||||
The miniupnpc library implement the UPnP protocol defined
|
||||
to dialog with Internet Gateway Devices. It also has
|
||||
the ability to use data gathered by minissdpd(1) about
|
||||
UPnP devices up on the network in order to skip the
|
||||
long UPnP device discovery process.
|
||||
.PP
|
||||
At first, upnpDiscover(3) has to be used to discover UPnP IGD present
|
||||
on the network. Then UPNP_GetValidIGD(3) to select the right one.
|
||||
Alternatively, UPNP_GetIGDFromUrl(3) could be used to bypass discovery
|
||||
process if the root description url of the device to use is known.
|
||||
Then all the UPNP_* functions can be used, such as
|
||||
UPNP_GetConnectionTypeInfo(3), UPNP_AddPortMapping(3), etc...
|
||||
.SH "HEADER FILES"
|
||||
.IP miniupnpc.h
|
||||
That's the main header file for the miniupnpc library API.
|
||||
It contains all the functions and structures related to device discovery.
|
||||
.IP upnpcommands.h
|
||||
This header file contain the UPnP IGD methods that are accessible
|
||||
through the miniupnpc API. The name of the C functions are matching
|
||||
the UPnP methods names. ie: GetGenericPortMappingEntry is
|
||||
UPNP_GetGenericPortMappingEntry.
|
||||
.SH "API FUNCTIONS"
|
||||
.IP "struct UPNPDev * upnpDiscover(int delay, const char * multicastif, const char * minissdpdsock, int sameport);"
|
||||
execute the discovery process.
|
||||
delay (in millisecond) is the maximum time for waiting any device response.
|
||||
If available, device list will be obtained from MiniSSDPd.
|
||||
Default path for minissdpd socket will be used if minissdpdsock argument is NULL.
|
||||
If multicastif is not NULL, it will be used instead of the default multicast interface for sending SSDP discover packets.
|
||||
If sameport is not null, SSDP packets will be sent from the source port 1900 (same as destination port) otherwise system assign a source port.
|
||||
.IP "void freeUPNPDevlist(struct UPNPDev * devlist);"
|
||||
free the list returned by upnpDiscover().
|
||||
.IP "int UPNP_GetValidIGD(struct UPNPDev * devlist, struct UPNPUrls * urls, struct IGDdatas * data, char * lanaddr, int lanaddrlen);"
|
||||
browse the list of device returned by upnpDiscover(), find
|
||||
a live UPnP internet gateway device and fill structures passed as arguments
|
||||
with data used for UPNP methods invokation.
|
||||
.IP "int UPNP_GetIGDFromUrl(const char * rootdescurl, struct UPNPUrls * urls, struct IGDdatas * data, char * lanaddr, int lanaddrlen);"
|
||||
permit to bypass the upnpDiscover() call if the xml root description
|
||||
URL of the UPnP IGD is known.
|
||||
Fill structures passed as arguments
|
||||
with data used for UPNP methods invokation.
|
||||
.IP "void GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *, const char *);"
|
||||
.IP "void FreeUPNPUrls(struct UPNPUrls *);"
|
||||
|
||||
.SH "SEE ALSO"
|
||||
minissdpd(1)
|
||||
.SH BUGS
|
|
@ -1,7 +0,0 @@
|
|||
@mingw32-make -f Makefile.mingw %1
|
||||
@if errorlevel 1 goto end
|
||||
@strip upnpc-static.exe
|
||||
@upx --best upnpc-static.exe
|
||||
@strip upnpc-shared.exe
|
||||
@upx --best upnpc-shared.exe
|
||||
:end
|
|
@ -1,31 +0,0 @@
|
|||
LIBRARY
|
||||
; miniupnpc library
|
||||
|
||||
EXPORTS
|
||||
; miniupnpc
|
||||
upnpDiscover
|
||||
freeUPNPDevlist
|
||||
parserootdesc
|
||||
UPNP_GetValidIGD
|
||||
UPNP_GetIGDFromUrl
|
||||
GetUPNPUrls
|
||||
FreeUPNPUrls
|
||||
; miniwget
|
||||
miniwget
|
||||
miniwget_getaddr
|
||||
; upnpcommands
|
||||
UPNP_GetTotalBytesSent
|
||||
UPNP_GetTotalBytesReceived
|
||||
UPNP_GetTotalPacketsSent
|
||||
UPNP_GetTotalPacketsReceived
|
||||
UPNP_GetStatusInfo
|
||||
UPNP_GetConnectionTypeInfo
|
||||
UPNP_GetExternalIPAddress
|
||||
UPNP_GetLinkLayerMaxBitRates
|
||||
UPNP_AddPortMapping
|
||||
UPNP_DeletePortMapping
|
||||
UPNP_GetPortMappingNumberOfEntries
|
||||
UPNP_GetSpecificPortMappingEntry
|
||||
UPNP_GetGenericPortMappingEntry
|
||||
; upnperrors
|
||||
strupnperror
|
|
@ -1,494 +0,0 @@
|
|||
/* $Id: miniupnpcmodule.c,v 1.14 2009/10/16 09:02:47 nanard Exp $*/
|
||||
/* Project : miniupnp
|
||||
* Author : Thomas BERNARD
|
||||
* website : http://miniupnp.tuxfamily.org/
|
||||
* copyright (c) 2007-2009 Thomas Bernard
|
||||
* This software is subjet to the conditions detailed in the
|
||||
* provided LICENCE file. */
|
||||
#include <Python.h>
|
||||
#define STATICLIB
|
||||
#include "structmember.h"
|
||||
#include "miniupnpc.h"
|
||||
#include "upnpcommands.h"
|
||||
#include "upnperrors.h"
|
||||
|
||||
/* for compatibility with Python < 2.4 */
|
||||
#ifndef Py_RETURN_NONE
|
||||
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
|
||||
#endif
|
||||
|
||||
#ifndef Py_RETURN_TRUE
|
||||
#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
|
||||
#endif
|
||||
|
||||
#ifndef Py_RETURN_FALSE
|
||||
#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
/* Type-specific fields go here. */
|
||||
struct UPNPDev * devlist;
|
||||
struct UPNPUrls urls;
|
||||
struct IGDdatas data;
|
||||
unsigned int discoverdelay; /* value passed to upnpDiscover() */
|
||||
char lanaddr[16]; /* our ip address on the LAN */
|
||||
char * multicastif;
|
||||
char * minissdpdsocket;
|
||||
} UPnPObject;
|
||||
|
||||
static PyMemberDef UPnP_members[] = {
|
||||
{"lanaddr", T_STRING_INPLACE, offsetof(UPnPObject, lanaddr),
|
||||
READONLY, "ip address on the LAN"
|
||||
},
|
||||
{"discoverdelay", T_UINT, offsetof(UPnPObject, discoverdelay),
|
||||
0/*READWRITE*/, "value in ms used to wait for SSDP responses"
|
||||
},
|
||||
/* T_STRING is allways readonly :( */
|
||||
{"multicastif", T_STRING, offsetof(UPnPObject, multicastif),
|
||||
0, "IP of the network interface to be used for multicast operations"
|
||||
},
|
||||
{"minissdpdsocket", T_STRING, offsetof(UPnPObject, multicastif),
|
||||
0, "path of the MiniSSDPd unix socket"
|
||||
},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static void
|
||||
UPnPObject_dealloc(UPnPObject *self)
|
||||
{
|
||||
freeUPNPDevlist(self->devlist);
|
||||
FreeUPNPUrls(&self->urls);
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_discover(UPnPObject *self)
|
||||
{
|
||||
struct UPNPDev * dev;
|
||||
int i;
|
||||
PyObject *res = NULL;
|
||||
if(self->devlist)
|
||||
{
|
||||
freeUPNPDevlist(self->devlist);
|
||||
self->devlist = 0;
|
||||
}
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
self->devlist = upnpDiscover((int)self->discoverdelay/*timeout in ms*/,
|
||||
0/* multicast if*/,
|
||||
0/*minissdpd socket*/,
|
||||
0/*sameport flag*/);
|
||||
Py_END_ALLOW_THREADS
|
||||
/* Py_RETURN_NONE ??? */
|
||||
for(dev = self->devlist, i = 0; dev; dev = dev->pNext)
|
||||
i++;
|
||||
res = Py_BuildValue("i", i);
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_selectigd(UPnPObject *self)
|
||||
{
|
||||
int r;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
r = UPNP_GetValidIGD(self->devlist, &self->urls, &self->data,
|
||||
self->lanaddr, sizeof(self->lanaddr));
|
||||
Py_END_ALLOW_THREADS
|
||||
if(r)
|
||||
{
|
||||
return Py_BuildValue("s", self->urls.controlURL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: have our own exception type ! */
|
||||
PyErr_SetString(PyExc_Exception, "No UPnP device discovered");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_totalbytesent(UPnPObject *self)
|
||||
{
|
||||
UNSIGNED_INTEGER i;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
i = UPNP_GetTotalBytesSent(self->urls.controlURL_CIF,
|
||||
self->data.servicetype_CIF);
|
||||
Py_END_ALLOW_THREADS
|
||||
return Py_BuildValue("I", i);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_totalbytereceived(UPnPObject *self)
|
||||
{
|
||||
UNSIGNED_INTEGER i;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
i = UPNP_GetTotalBytesReceived(self->urls.controlURL_CIF,
|
||||
self->data.servicetype_CIF);
|
||||
Py_END_ALLOW_THREADS
|
||||
return Py_BuildValue("I", i);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_totalpacketsent(UPnPObject *self)
|
||||
{
|
||||
UNSIGNED_INTEGER i;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
i = UPNP_GetTotalPacketsSent(self->urls.controlURL_CIF,
|
||||
self->data.servicetype_CIF);
|
||||
Py_END_ALLOW_THREADS
|
||||
return Py_BuildValue("I", i);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_totalpacketreceived(UPnPObject *self)
|
||||
{
|
||||
UNSIGNED_INTEGER i;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
i = UPNP_GetTotalPacketsReceived(self->urls.controlURL_CIF,
|
||||
self->data.servicetype_CIF);
|
||||
Py_END_ALLOW_THREADS
|
||||
return Py_BuildValue("I", i);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_statusinfo(UPnPObject *self)
|
||||
{
|
||||
char status[64];
|
||||
char lastconnerror[64];
|
||||
unsigned int uptime = 0;
|
||||
int r;
|
||||
status[0] = '\0';
|
||||
lastconnerror[0] = '\0';
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
r = UPNP_GetStatusInfo(self->urls.controlURL, self->data.servicetype,
|
||||
status, &uptime, lastconnerror);
|
||||
Py_END_ALLOW_THREADS
|
||||
if(r==UPNPCOMMAND_SUCCESS) {
|
||||
return Py_BuildValue("(s,I,s)", status, uptime, lastconnerror);
|
||||
} else {
|
||||
/* TODO: have our own exception type ! */
|
||||
PyErr_SetString(PyExc_Exception, strupnperror(r));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_connectiontype(UPnPObject *self)
|
||||
{
|
||||
char connectionType[64];
|
||||
int r;
|
||||
connectionType[0] = '\0';
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
r = UPNP_GetConnectionTypeInfo(self->urls.controlURL,
|
||||
self->data.servicetype,
|
||||
connectionType);
|
||||
Py_END_ALLOW_THREADS
|
||||
if(r==UPNPCOMMAND_SUCCESS) {
|
||||
return Py_BuildValue("s", connectionType);
|
||||
} else {
|
||||
/* TODO: have our own exception type ! */
|
||||
PyErr_SetString(PyExc_Exception, strupnperror(r));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_externalipaddress(UPnPObject *self)
|
||||
{
|
||||
char externalIPAddress[16];
|
||||
int r;
|
||||
externalIPAddress[0] = '\0';
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
r = UPNP_GetExternalIPAddress(self->urls.controlURL,
|
||||
self->data.servicetype,
|
||||
externalIPAddress);
|
||||
Py_END_ALLOW_THREADS
|
||||
if(r==UPNPCOMMAND_SUCCESS) {
|
||||
return Py_BuildValue("s", externalIPAddress);
|
||||
} else {
|
||||
/* TODO: have our own exception type ! */
|
||||
PyErr_SetString(PyExc_Exception, strupnperror(r));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* AddPortMapping(externalPort, protocol, internalHost, internalPort, desc,
|
||||
* remoteHost)
|
||||
* protocol is 'UDP' or 'TCP' */
|
||||
static PyObject *
|
||||
UPnP_addportmapping(UPnPObject *self, PyObject *args)
|
||||
{
|
||||
char extPort[6];
|
||||
unsigned short ePort;
|
||||
char inPort[6];
|
||||
unsigned short iPort;
|
||||
const char * proto;
|
||||
const char * host;
|
||||
const char * desc;
|
||||
const char * remoteHost;
|
||||
int r;
|
||||
if (!PyArg_ParseTuple(args, "HssHss", &ePort, &proto,
|
||||
&host, &iPort, &desc, &remoteHost))
|
||||
return NULL;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
sprintf(extPort, "%hu", ePort);
|
||||
sprintf(inPort, "%hu", iPort);
|
||||
r = UPNP_AddPortMapping(self->urls.controlURL, self->data.servicetype,
|
||||
extPort, inPort, host, desc, proto, remoteHost);
|
||||
Py_END_ALLOW_THREADS
|
||||
if(r==UPNPCOMMAND_SUCCESS)
|
||||
{
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: RAISE an Exception. See upnpcommands.h for errors codes.
|
||||
// upnperrors.c
|
||||
//Py_RETURN_FALSE;
|
||||
/* TODO: have our own exception type ! */
|
||||
PyErr_SetString(PyExc_Exception, strupnperror(r));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* DeletePortMapping(extPort, proto, removeHost='')
|
||||
* proto = 'UDP', 'TCP' */
|
||||
static PyObject *
|
||||
UPnP_deleteportmapping(UPnPObject *self, PyObject *args)
|
||||
{
|
||||
char extPort[6];
|
||||
unsigned short ePort;
|
||||
const char * proto;
|
||||
const char * remoteHost = "";
|
||||
int r;
|
||||
if(!PyArg_ParseTuple(args, "Hs|z", &ePort, &proto, &remoteHost))
|
||||
return NULL;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
sprintf(extPort, "%hu", ePort);
|
||||
r = UPNP_DeletePortMapping(self->urls.controlURL, self->data.servicetype,
|
||||
extPort, proto, remoteHost);
|
||||
Py_END_ALLOW_THREADS
|
||||
if(r==UPNPCOMMAND_SUCCESS) {
|
||||
Py_RETURN_TRUE;
|
||||
} else {
|
||||
/* TODO: have our own exception type ! */
|
||||
PyErr_SetString(PyExc_Exception, strupnperror(r));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
UPnP_getportmappingnumberofentries(UPnPObject *self)
|
||||
{
|
||||
unsigned int n = 0;
|
||||
int r;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
r = UPNP_GetPortMappingNumberOfEntries(self->urls.controlURL,
|
||||
self->data.servicetype,
|
||||
&n);
|
||||
Py_END_ALLOW_THREADS
|
||||
if(r==UPNPCOMMAND_SUCCESS) {
|
||||
return Py_BuildValue("I", n);
|
||||
} else {
|
||||
/* TODO: have our own exception type ! */
|
||||
PyErr_SetString(PyExc_Exception, strupnperror(r));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* GetSpecificPortMapping(ePort, proto)
|
||||
* proto = 'UDP' or 'TCP' */
|
||||
static PyObject *
|
||||
UPnP_getspecificportmapping(UPnPObject *self, PyObject *args)
|
||||
{
|
||||
char extPort[6];
|
||||
unsigned short ePort;
|
||||
const char * proto;
|
||||
char intClient[16];
|
||||
char intPort[6];
|
||||
unsigned short iPort;
|
||||
if(!PyArg_ParseTuple(args, "Hs", &ePort, &proto))
|
||||
return NULL;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
sprintf(extPort, "%hu", ePort);
|
||||
UPNP_GetSpecificPortMappingEntry(self->urls.controlURL,
|
||||
self->data.servicetype,
|
||||
extPort, proto,
|
||||
intClient, intPort);
|
||||
Py_END_ALLOW_THREADS
|
||||
if(intClient[0])
|
||||
{
|
||||
iPort = (unsigned short)atoi(intPort);
|
||||
return Py_BuildValue("(s,H)", intClient, iPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/* GetGenericPortMapping(index) */
|
||||
static PyObject *
|
||||
UPnP_getgenericportmapping(UPnPObject *self, PyObject *args)
|
||||
{
|
||||
int i, r;
|
||||
char index[8];
|
||||
char intClient[16];
|
||||
char intPort[6];
|
||||
unsigned short iPort;
|
||||
char extPort[6];
|
||||
unsigned short ePort;
|
||||
char protocol[4];
|
||||
char desc[80];
|
||||
char enabled[6];
|
||||
char rHost[64];
|
||||
char duration[16]; /* lease duration */
|
||||
unsigned int dur;
|
||||
if(!PyArg_ParseTuple(args, "i", &i))
|
||||
return NULL;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
snprintf(index, sizeof(index), "%d", i);
|
||||
rHost[0] = '\0'; enabled[0] = '\0';
|
||||
duration[0] = '\0'; desc[0] = '\0';
|
||||
extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0';
|
||||
r = UPNP_GetGenericPortMappingEntry(self->urls.controlURL,
|
||||
self->data.servicetype,
|
||||
index,
|
||||
extPort, intClient, intPort,
|
||||
protocol, desc, enabled, rHost,
|
||||
duration);
|
||||
Py_END_ALLOW_THREADS
|
||||
if(r==UPNPCOMMAND_SUCCESS)
|
||||
{
|
||||
ePort = (unsigned short)atoi(extPort);
|
||||
iPort = (unsigned short)atoi(intPort);
|
||||
dur = (unsigned int)strtoul(duration, 0, 0);
|
||||
return Py_BuildValue("(H,s,(s,H),s,s,s,I)",
|
||||
ePort, protocol, intClient, iPort,
|
||||
desc, enabled, rHost, dur);
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/* miniupnpc.UPnP object Method Table */
|
||||
static PyMethodDef UPnP_methods[] = {
|
||||
{"discover", (PyCFunction)UPnP_discover, METH_NOARGS,
|
||||
"discover UPnP IGD devices on the network"
|
||||
},
|
||||
{"selectigd", (PyCFunction)UPnP_selectigd, METH_NOARGS,
|
||||
"select a valid UPnP IGD among discovered devices"
|
||||
},
|
||||
{"totalbytesent", (PyCFunction)UPnP_totalbytesent, METH_NOARGS,
|
||||
"return the total number of bytes sent by UPnP IGD"
|
||||
},
|
||||
{"totalbytereceived", (PyCFunction)UPnP_totalbytereceived, METH_NOARGS,
|
||||
"return the total number of bytes received by UPnP IGD"
|
||||
},
|
||||
{"totalpacketsent", (PyCFunction)UPnP_totalpacketsent, METH_NOARGS,
|
||||
"return the total number of packets sent by UPnP IGD"
|
||||
},
|
||||
{"totalpacketreceived", (PyCFunction)UPnP_totalpacketreceived, METH_NOARGS,
|
||||
"return the total number of packets received by UPnP IGD"
|
||||
},
|
||||
{"statusinfo", (PyCFunction)UPnP_statusinfo, METH_NOARGS,
|
||||
"return status and uptime"
|
||||
},
|
||||
{"connectiontype", (PyCFunction)UPnP_connectiontype, METH_NOARGS,
|
||||
"return IGD WAN connection type"
|
||||
},
|
||||
{"externalipaddress", (PyCFunction)UPnP_externalipaddress, METH_NOARGS,
|
||||
"return external IP address"
|
||||
},
|
||||
{"addportmapping", (PyCFunction)UPnP_addportmapping, METH_VARARGS,
|
||||
"add a port mapping"
|
||||
},
|
||||
{"deleteportmapping", (PyCFunction)UPnP_deleteportmapping, METH_VARARGS,
|
||||
"delete a port mapping"
|
||||
},
|
||||
{"getportmappingnumberofentries", (PyCFunction)UPnP_getportmappingnumberofentries, METH_NOARGS,
|
||||
"-- non standard --"
|
||||
},
|
||||
{"getspecificportmapping", (PyCFunction)UPnP_getspecificportmapping, METH_VARARGS,
|
||||
"get details about a specific port mapping entry"
|
||||
},
|
||||
{"getgenericportmapping", (PyCFunction)UPnP_getgenericportmapping, METH_VARARGS,
|
||||
"get all details about the port mapping at index"
|
||||
},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyTypeObject UPnPType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"miniupnpc.UPnP", /*tp_name*/
|
||||
sizeof(UPnPObject), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)UPnPObject_dealloc,/*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"UPnP objects", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
UPnP_methods, /* tp_methods */
|
||||
UPnP_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0,/*(initproc)UPnP_init,*/ /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
#ifndef WIN32
|
||||
PyType_GenericNew,/*UPnP_new,*/ /* tp_new */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* module methods */
|
||||
static PyMethodDef miniupnpc_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
|
||||
#define PyMODINIT_FUNC void
|
||||
#endif
|
||||
PyMODINIT_FUNC
|
||||
initminiupnpc(void)
|
||||
{
|
||||
PyObject* m;
|
||||
|
||||
#ifdef WIN32
|
||||
UPnPType.tp_new = PyType_GenericNew;
|
||||
#endif
|
||||
if (PyType_Ready(&UPnPType) < 0)
|
||||
return;
|
||||
|
||||
m = Py_InitModule3("miniupnpc", miniupnpc_methods,
|
||||
"miniupnpc module.");
|
||||
|
||||
Py_INCREF(&UPnPType);
|
||||
PyModule_AddObject(m, "UPnP", (PyObject *)&UPnPType);
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
/* $Id: miniupnpcstrings.h.in,v 1.2 2009/10/30 09:18:18 nanard Exp $ */
|
||||
/* Project: miniupnp
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* Author: Thomas Bernard
|
||||
* Copyright (c) 2005-2009 Thomas Bernard
|
||||
* This software is subjects to the conditions detailed
|
||||
* in the LICENCE file provided within this distribution */
|
||||
#ifndef __MINIUPNPCSTRINGS_H__
|
||||
#define __MINIUPNPCSTRINGS_H__
|
||||
|
||||
#define OS_STRING "OS/version"
|
||||
#define MINIUPNPC_VERSION_STRING "1.4"
|
||||
|
||||
#endif
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
/* $Id: minixmlvalid.c,v 1.2 2006/11/30 11:31:55 nanard Exp $ */
|
||||
/* MiniUPnP Project
|
||||
* http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/
|
||||
* minixmlvalid.c :
|
||||
* validation program for the minixml parser
|
||||
*
|
||||
* (c) 2006 Thomas Bernard */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "minixml.h"
|
||||
|
||||
/* xml event structure */
|
||||
struct event {
|
||||
enum { ELTSTART, ELTEND, ATT, CHARDATA } type;
|
||||
const char * data;
|
||||
int len;
|
||||
};
|
||||
|
||||
struct eventlist {
|
||||
int n;
|
||||
struct event * events;
|
||||
};
|
||||
|
||||
/* compare 2 xml event lists
|
||||
* return 0 if the two lists are equals */
|
||||
int evtlistcmp(struct eventlist * a, struct eventlist * b)
|
||||
{
|
||||
int i;
|
||||
struct event * ae, * be;
|
||||
if(a->n != b->n)
|
||||
return 1;
|
||||
for(i=0; i<a->n; i++)
|
||||
{
|
||||
ae = a->events + i;
|
||||
be = b->events + i;
|
||||
if( (ae->type != be->type)
|
||||
||(ae->len != be->len)
|
||||
||memcmp(ae->data, be->data, ae->len))
|
||||
{
|
||||
printf("Found a difference : %d '%.*s' != %d '%.*s'\n",
|
||||
ae->type, ae->len, ae->data,
|
||||
be->type, be->len, be->data);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Test data */
|
||||
static const char xmldata[] =
|
||||
"<xmlroot>\n"
|
||||
" <elt1 att1=\"attvalue1\" att2=\"attvalue2\">"
|
||||
"character data"
|
||||
"</elt1> \n \t"
|
||||
"<elt1b/>"
|
||||
"<elt2a> \t<elt2b>chardata1</elt2b><elt2b>chardata2</elt2b></elt2a>"
|
||||
"</xmlroot>";
|
||||
|
||||
static const struct event evtref[] =
|
||||
{
|
||||
{ELTSTART, "xmlroot", 7},
|
||||
{ELTSTART, "elt1", 4},
|
||||
/* attributes */
|
||||
{CHARDATA, "character data", 14},
|
||||
{ELTEND, "elt1", 4},
|
||||
{ELTSTART, "elt1b", 5},
|
||||
{ELTSTART, "elt2a", 5},
|
||||
{ELTSTART, "elt2b", 5},
|
||||
{CHARDATA, "chardata1", 9},
|
||||
{ELTEND, "elt2b", 5},
|
||||
{ELTSTART, "elt2b", 5},
|
||||
{CHARDATA, "chardata2", 9},
|
||||
{ELTEND, "elt2b", 5},
|
||||
{ELTEND, "elt2a", 5},
|
||||
{ELTEND, "xmlroot", 7}
|
||||
};
|
||||
|
||||
void startelt(void * data, const char * p, int l)
|
||||
{
|
||||
struct eventlist * evtlist = data;
|
||||
struct event * evt;
|
||||
evt = evtlist->events + evtlist->n;
|
||||
/*printf("startelt : %.*s\n", l, p);*/
|
||||
evt->type = ELTSTART;
|
||||
evt->data = p;
|
||||
evt->len = l;
|
||||
evtlist->n++;
|
||||
}
|
||||
|
||||
void endelt(void * data, const char * p, int l)
|
||||
{
|
||||
struct eventlist * evtlist = data;
|
||||
struct event * evt;
|
||||
evt = evtlist->events + evtlist->n;
|
||||
/*printf("endelt : %.*s\n", l, p);*/
|
||||
evt->type = ELTEND;
|
||||
evt->data = p;
|
||||
evt->len = l;
|
||||
evtlist->n++;
|
||||
}
|
||||
|
||||
void chardata(void * data, const char * p, int l)
|
||||
{
|
||||
struct eventlist * evtlist = data;
|
||||
struct event * evt;
|
||||
evt = evtlist->events + evtlist->n;
|
||||
/*printf("chardata : '%.*s'\n", l, p);*/
|
||||
evt->type = CHARDATA;
|
||||
evt->data = p;
|
||||
evt->len = l;
|
||||
evtlist->n++;
|
||||
}
|
||||
|
||||
int testxmlparser(const char * xml, int size)
|
||||
{
|
||||
int r;
|
||||
struct eventlist evtlist;
|
||||
struct eventlist evtlistref;
|
||||
struct xmlparser parser;
|
||||
evtlist.n = 0;
|
||||
evtlist.events = malloc(sizeof(struct event)*100);
|
||||
memset(&parser, 0, sizeof(parser));
|
||||
parser.xmlstart = xml;
|
||||
parser.xmlsize = size;
|
||||
parser.data = &evtlist;
|
||||
parser.starteltfunc = startelt;
|
||||
parser.endeltfunc = endelt;
|
||||
parser.datafunc = chardata;
|
||||
parsexml(&parser);
|
||||
printf("%d events\n", evtlist.n);
|
||||
/* compare */
|
||||
evtlistref.n = sizeof(evtref)/sizeof(struct event);
|
||||
evtlistref.events = (struct event *)evtref;
|
||||
r = evtlistcmp(&evtlistref, &evtlist);
|
||||
free(evtlist.events);
|
||||
return r;
|
||||
}
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
int r;
|
||||
r = testxmlparser(xmldata, sizeof(xmldata)-1);
|
||||
if(r)
|
||||
printf("minixml validation test failed\n");
|
||||
return r;
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#! /usr/bin/python
|
||||
# MiniUPnP project
|
||||
# Author : Thomas Bernard
|
||||
# This Sample code is public domain.
|
||||
# website : http://miniupnp.tuxfamily.org/
|
||||
|
||||
# import the python miniupnpc module
|
||||
import miniupnpc
|
||||
import sys
|
||||
|
||||
# create the object
|
||||
u = miniupnpc.UPnP()
|
||||
print 'inital(default) values :'
|
||||
print ' discoverdelay', u.discoverdelay
|
||||
print ' lanaddr', u.lanaddr
|
||||
print ' multicastif', u.multicastif
|
||||
print ' minissdpdsocket', u.minissdpdsocket
|
||||
u.discoverdelay = 200;
|
||||
#u.minissdpdsocket = '../minissdpd/minissdpd.sock'
|
||||
# discovery process, it usualy takes several seconds (2 seconds or more)
|
||||
print 'Discovering... delay=%ums' % u.discoverdelay
|
||||
print u.discover(), 'device(s) detected'
|
||||
# select an igd
|
||||
try:
|
||||
u.selectigd()
|
||||
except Exception, e:
|
||||
print 'Exception :', e
|
||||
sys.exit(1)
|
||||
# display information about the IGD and the internet connection
|
||||
print 'local ip address :', u.lanaddr
|
||||
print 'external ip address :', u.externalipaddress()
|
||||
print u.statusinfo(), u.connectiontype()
|
||||
|
||||
#print u.addportmapping(64000, 'TCP',
|
||||
# '192.168.1.166', 63000, 'port mapping test', '')
|
||||
#print u.deleteportmapping(64000, 'TCP')
|
||||
|
||||
port = 0
|
||||
proto = 'UDP'
|
||||
# list the redirections :
|
||||
i = 0
|
||||
while True:
|
||||
p = u.getgenericportmapping(i)
|
||||
if p==None:
|
||||
break
|
||||
print i, p
|
||||
(port, proto, (ihost,iport), desc, c, d, e) = p
|
||||
#print port, desc
|
||||
i = i + 1
|
||||
|
||||
print u.getspecificportmapping(port, proto)
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#! /usr/bin/python
|
||||
# $Id: setup.py,v 1.5 2009/10/30 09:18:18 nanard Exp $
|
||||
# the MiniUPnP Project (c) 2007-2009 Thomas Bernard
|
||||
# http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/
|
||||
#
|
||||
# python script to build the miniupnpc module under unix
|
||||
#
|
||||
# replace libminiupnpc.a by libminiupnpc.so for shared library usage
|
||||
from distutils.core import setup, Extension
|
||||
setup(name="miniupnpc", version="1.4",
|
||||
ext_modules=[
|
||||
Extension(name="miniupnpc", sources=["miniupnpcmodule.c"],
|
||||
extra_objects=["libminiupnpc.a"])
|
||||
])
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#! /usr/bin/python
|
||||
# $Id: setupmingw32.py,v 1.3 2009/10/30 09:18:18 nanard Exp $
|
||||
# the MiniUPnP Project (c) 2007-2009 Thomas Bernard
|
||||
# http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/
|
||||
#
|
||||
# python script to build the miniupnpc module under unix
|
||||
#
|
||||
from distutils.core import setup, Extension
|
||||
setup(name="miniupnpc", version="1.4",
|
||||
ext_modules=[
|
||||
Extension(name="miniupnpc", sources=["miniupnpcmodule.c"],
|
||||
libraries=["ws2_32"],
|
||||
extra_objects=["libminiupnpc.a"])
|
||||
])
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/* $Id: testigddescparse.c,v 1.1 2008/04/23 11:53:45 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* http://miniupnp.free.fr/
|
||||
* Author : Thomas Bernard
|
||||
* Copyright (c) 2008 Thomas Bernard
|
||||
* This software is subject to the conditions detailed in the
|
||||
* LICENCE file provided in this distribution.
|
||||
* */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "igd_desc_parse.h"
|
||||
#include "minixml.h"
|
||||
|
||||
int test_igd_desc_parse(char * buffer, int len)
|
||||
{
|
||||
struct IGDdatas igd;
|
||||
struct xmlparser parser;
|
||||
memset(&igd, 0, sizeof(struct IGDdatas));
|
||||
memset(&parser, 0, sizeof(struct xmlparser));
|
||||
parser.xmlstart = buffer;
|
||||
parser.xmlsize = len;
|
||||
parser.data = &igd;
|
||||
parser.starteltfunc = IGDstartelt;
|
||||
parser.endeltfunc = IGDendelt;
|
||||
parser.datafunc = IGDdata;
|
||||
parsexml(&parser);
|
||||
printIGD(&igd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
FILE * f;
|
||||
char * buffer;
|
||||
int len;
|
||||
int r = 0;
|
||||
if(argc<2) {
|
||||
fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(argv[1], "r");
|
||||
if(!f) {
|
||||
fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
buffer = malloc(len);
|
||||
fread(buffer, 1, len, f);
|
||||
fclose(f);
|
||||
r = test_igd_desc_parse(buffer, len);
|
||||
free(buffer);
|
||||
return r;
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/* $Id: testminixml.c,v 1.6 2006/11/19 22:32:35 nanard Exp $
|
||||
* testminixml.c
|
||||
* test program for the "minixml" functions.
|
||||
* Author : Thomas Bernard.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "minixml.h"
|
||||
#include "igd_desc_parse.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define NO_BZERO
|
||||
#endif
|
||||
|
||||
#ifdef NO_BZERO
|
||||
#define bzero(p, n) memset(p, 0, n)
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void printeltname1(void * d, const char * name, int l)
|
||||
{
|
||||
int i;
|
||||
printf("element ");
|
||||
for(i=0;i<l;i++)
|
||||
putchar(name[i]);
|
||||
}
|
||||
void printeltname2(void * d, const char * name, int l)
|
||||
{
|
||||
int i;
|
||||
putchar('/');
|
||||
for(i=0;i<l;i++)
|
||||
putchar(name[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
void printdata(void *d, const char * data, int l)
|
||||
{
|
||||
int i;
|
||||
printf("data : ");
|
||||
for(i=0;i<l;i++)
|
||||
putchar(data[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
void burptest(const char * buffer, int bufsize)
|
||||
{
|
||||
struct IGDdatas data;
|
||||
struct xmlparser parser;
|
||||
/*objet IGDdatas */
|
||||
bzero(&data, sizeof(struct IGDdatas));
|
||||
/* objet xmlparser */
|
||||
parser.xmlstart = buffer;
|
||||
parser.xmlsize = bufsize;
|
||||
parser.data = &data;
|
||||
/*parser.starteltfunc = printeltname1;
|
||||
parser.endeltfunc = printeltname2;
|
||||
parser.datafunc = printdata; */
|
||||
parser.starteltfunc = IGDstartelt;
|
||||
parser.endeltfunc = IGDendelt;
|
||||
parser.datafunc = IGDdata;
|
||||
parsexml(&parser);
|
||||
printIGD(&data);
|
||||
}
|
||||
|
||||
/* ----- main ---- */
|
||||
#define XML_MAX_SIZE (8192)
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
FILE * f;
|
||||
char buffer[XML_MAX_SIZE];
|
||||
int bufsize;
|
||||
if(argc<2)
|
||||
{
|
||||
printf("usage:\t%s file.xml\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(argv[1], "r");
|
||||
if(!f)
|
||||
{
|
||||
printf("cannot open file %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
bufsize = (int)fread(buffer, 1, XML_MAX_SIZE, f);
|
||||
fclose(f);
|
||||
burptest(buffer, bufsize);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
#! /usr/bin/python
|
||||
# $Id: testupnpigd.py,v 1.4 2008/10/11 10:27:20 nanard Exp $
|
||||
# MiniUPnP project
|
||||
# Author : Thomas Bernard
|
||||
# This Sample code is public domain.
|
||||
# website : http://miniupnp.tuxfamily.org/
|
||||
|
||||
# import the python miniupnpc module
|
||||
import miniupnpc
|
||||
import socket
|
||||
import BaseHTTPServer
|
||||
|
||||
# function definition
|
||||
def list_redirections():
|
||||
i = 0
|
||||
while True:
|
||||
p = u.getgenericportmapping(i)
|
||||
if p==None:
|
||||
break
|
||||
print i, p
|
||||
i = i + 1
|
||||
|
||||
#define the handler class for HTTP connections
|
||||
class handler_class(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write("OK MON GARS")
|
||||
|
||||
# create the object
|
||||
u = miniupnpc.UPnP()
|
||||
#print 'inital(default) values :'
|
||||
#print ' discoverdelay', u.discoverdelay
|
||||
#print ' lanaddr', u.lanaddr
|
||||
#print ' multicastif', u.multicastif
|
||||
#print ' minissdpdsocket', u.minissdpdsocket
|
||||
u.discoverdelay = 200;
|
||||
|
||||
try:
|
||||
print 'Discovering... delay=%ums' % u.discoverdelay
|
||||
ndevices = u.discover()
|
||||
print ndevices, 'device(s) detected'
|
||||
|
||||
# select an igd
|
||||
u.selectigd()
|
||||
# display information about the IGD and the internet connection
|
||||
print 'local ip address :', u.lanaddr
|
||||
externalipaddress = u.externalipaddress()
|
||||
print 'external ip address :', externalipaddress
|
||||
print u.statusinfo(), u.connectiontype()
|
||||
|
||||
#instanciate a HTTPd object. The port is assigned by the system.
|
||||
httpd = BaseHTTPServer.HTTPServer((u.lanaddr, 0), handler_class)
|
||||
eport = httpd.server_port
|
||||
|
||||
# find a free port for the redirection
|
||||
r = u.getspecificportmapping(eport, 'TCP')
|
||||
while r != None and eport < 65536:
|
||||
eport = eport + 1
|
||||
r = u.getspecificportmapping(eport, 'TCP')
|
||||
|
||||
print 'trying to redirect %s port %u TCP => %s port %u TCP' % (externalipaddress, eport, u.lanaddr, httpd.server_port)
|
||||
|
||||
b = u.addportmapping(eport, 'TCP', u.lanaddr, httpd.server_port,
|
||||
'UPnP IGD Tester port %u' % eport, '')
|
||||
if b:
|
||||
print 'Success. Now waiting for some HTTP request on http://%s:%u' % (externalipaddress ,eport)
|
||||
try:
|
||||
httpd.handle_request()
|
||||
httpd.server_close()
|
||||
except KeyboardInterrupt, details:
|
||||
print "CTRL-C exception!", details
|
||||
b = u.deleteportmapping(eport, 'TCP')
|
||||
if b:
|
||||
print 'Successfully deleted port mapping'
|
||||
else:
|
||||
print 'Failed to remove port mapping'
|
||||
else:
|
||||
print 'Failed'
|
||||
|
||||
httpd.server_close()
|
||||
|
||||
except Exception, e:
|
||||
print 'Exception :', e
|
|
@ -1,44 +0,0 @@
|
|||
/* $Id: testupnpreplyparse.c,v 1.2 2008/02/21 13:05:27 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2007 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "upnpreplyparse.h"
|
||||
|
||||
void
|
||||
test_parsing(const char * buf, int len)
|
||||
{
|
||||
struct NameValueParserData pdata;
|
||||
ParseNameValue(buf, len, &pdata);
|
||||
ClearNameValueList(&pdata);
|
||||
}
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
FILE * f;
|
||||
char buffer[4096];
|
||||
int l;
|
||||
if(argc<2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(argv[1], "r");
|
||||
if(!f)
|
||||
{
|
||||
fprintf(stderr, "Error : can not open file %s\n", argv[1]);
|
||||
return 2;
|
||||
}
|
||||
l = fread(buffer, 1, sizeof(buffer)-1, f);
|
||||
fclose(f);
|
||||
buffer[l] = '\0';
|
||||
#ifdef DEBUG
|
||||
DisplayNameValueList(buffer, l);
|
||||
#endif
|
||||
test_parsing(buffer, l);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#! /bin/sh
|
||||
# $Id: updateminiupnpcstrings.sh,v 1.4 2009/07/29 08:34:01 nanard Exp $
|
||||
|
||||
FILE=miniupnpcstrings.h
|
||||
TEMPLATE_FILE=${FILE}.in
|
||||
|
||||
# detecting the OS name and version
|
||||
OS_NAME=`uname -s`
|
||||
OS_VERSION=`uname -r`
|
||||
if [ -f /etc/debian_version ]; then
|
||||
OS_NAME=Debian
|
||||
OS_VERSION=`cat /etc/debian_version`
|
||||
fi
|
||||
# use lsb_release (Linux Standard Base) when available
|
||||
LSB_RELEASE=`which lsb_release`
|
||||
if [ 0 -eq $? ]; then
|
||||
OS_NAME=`${LSB_RELEASE} -i -s`
|
||||
OS_VERSION=`${LSB_RELEASE} -r -s`
|
||||
case $OS_NAME in
|
||||
Debian)
|
||||
#OS_VERSION=`${LSB_RELEASE} -c -s`
|
||||
;;
|
||||
Ubuntu)
|
||||
#OS_VERSION=`${LSB_RELEASE} -c -s`
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo "Detected OS [$OS_NAME] version [$OS_VERSION]"
|
||||
|
||||
EXPR="s|OS_STRING \".*\"|OS_STRING \"${OS_NAME}/${OS_VERSION}\"|"
|
||||
#echo $EXPR
|
||||
#echo "Backuping $FILE to $FILE.bak."
|
||||
#cp $FILE $FILE.bak
|
||||
test -f ${FILE}.in
|
||||
echo "setting OS_STRING macro value to ${OS_NAME}/${OS_VERSION} in $FILE."
|
||||
sed -e "$EXPR" < $TEMPLATE_FILE > $FILE
|
||||
|
|
@ -1,378 +0,0 @@
|
|||
/* $Id: upnpc.c,v 1.67 2009/08/03 22:58:37 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* Author : Thomas Bernard
|
||||
* Copyright (c) 2005-2009 Thomas Bernard
|
||||
* This software is subject to the conditions detailed in the
|
||||
* LICENCE file provided in this distribution.
|
||||
* */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#include "miniwget.h"
|
||||
#include "miniupnpc.h"
|
||||
#include "upnpcommands.h"
|
||||
#include "upnperrors.h"
|
||||
|
||||
/* protofix() checks if protocol is "UDP" or "TCP"
|
||||
* returns NULL if not */
|
||||
const char * protofix(const char * proto)
|
||||
{
|
||||
static const char proto_tcp[4] = { 'T', 'C', 'P', 0};
|
||||
static const char proto_udp[4] = { 'U', 'D', 'P', 0};
|
||||
int i, b;
|
||||
for(i=0, b=1; i<4; i++)
|
||||
b = b && ( (proto[i] == proto_tcp[i])
|
||||
|| (proto[i] == (proto_tcp[i] | 32)) );
|
||||
if(b)
|
||||
return proto_tcp;
|
||||
for(i=0, b=1; i<4; i++)
|
||||
b = b && ( (proto[i] == proto_udp[i])
|
||||
|| (proto[i] == (proto_udp[i] | 32)) );
|
||||
if(b)
|
||||
return proto_udp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void DisplayInfos(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data)
|
||||
{
|
||||
char externalIPAddress[16];
|
||||
char connectionType[64];
|
||||
char status[64];
|
||||
char lastconnerr[64];
|
||||
unsigned int uptime;
|
||||
unsigned int brUp, brDown;
|
||||
int r;
|
||||
UPNP_GetConnectionTypeInfo(urls->controlURL,
|
||||
data->servicetype,
|
||||
connectionType);
|
||||
if(connectionType[0])
|
||||
printf("Connection Type : %s\n", connectionType);
|
||||
else
|
||||
printf("GetConnectionTypeInfo failed.\n");
|
||||
UPNP_GetStatusInfo(urls->controlURL, data->servicetype,
|
||||
status, &uptime, lastconnerr);
|
||||
printf("Status : %s, uptime=%u, LastConnectionError : %s\n",
|
||||
status, uptime, lastconnerr);
|
||||
UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->servicetype_CIF,
|
||||
&brDown, &brUp);
|
||||
printf("MaxBitRateDown : %u bps MaxBitRateUp %u bps\n", brDown, brUp);
|
||||
r = UPNP_GetExternalIPAddress(urls->controlURL,
|
||||
data->servicetype,
|
||||
externalIPAddress);
|
||||
if(r != UPNPCOMMAND_SUCCESS)
|
||||
printf("GetExternalIPAddress() returned %d\n", r);
|
||||
if(externalIPAddress[0])
|
||||
printf("ExternalIPAddress = %s\n", externalIPAddress);
|
||||
else
|
||||
printf("GetExternalIPAddress failed.\n");
|
||||
}
|
||||
|
||||
static void GetConnectionStatus(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data)
|
||||
{
|
||||
unsigned int bytessent, bytesreceived, packetsreceived, packetssent;
|
||||
DisplayInfos(urls, data);
|
||||
bytessent = UPNP_GetTotalBytesSent(urls->controlURL_CIF, data->servicetype_CIF);
|
||||
bytesreceived = UPNP_GetTotalBytesReceived(urls->controlURL_CIF, data->servicetype_CIF);
|
||||
packetssent = UPNP_GetTotalPacketsSent(urls->controlURL_CIF, data->servicetype_CIF);
|
||||
packetsreceived = UPNP_GetTotalPacketsReceived(urls->controlURL_CIF, data->servicetype_CIF);
|
||||
printf("Bytes: Sent: %8u\tRecv: %8u\n", bytessent, bytesreceived);
|
||||
printf("Packets: Sent: %8u\tRecv: %8u\n", packetssent, packetsreceived);
|
||||
}
|
||||
|
||||
static void ListRedirections(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data)
|
||||
{
|
||||
int r;
|
||||
int i = 0;
|
||||
char index[6];
|
||||
char intClient[16];
|
||||
char intPort[6];
|
||||
char extPort[6];
|
||||
char protocol[4];
|
||||
char desc[80];
|
||||
char enabled[6];
|
||||
char rHost[64];
|
||||
char duration[16];
|
||||
/*unsigned int num=0;
|
||||
UPNP_GetPortMappingNumberOfEntries(urls->controlURL, data->servicetype, &num);
|
||||
printf("PortMappingNumberOfEntries : %u\n", num);*/
|
||||
do {
|
||||
snprintf(index, 6, "%d", i);
|
||||
rHost[0] = '\0'; enabled[0] = '\0';
|
||||
duration[0] = '\0'; desc[0] = '\0';
|
||||
extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0';
|
||||
r = UPNP_GetGenericPortMappingEntry(urls->controlURL, data->servicetype,
|
||||
index,
|
||||
extPort, intClient, intPort,
|
||||
protocol, desc, enabled,
|
||||
rHost, duration);
|
||||
if(r==0)
|
||||
/*
|
||||
printf("%02d - %s %s->%s:%s\tenabled=%s leaseDuration=%s\n"
|
||||
" desc='%s' rHost='%s'\n",
|
||||
i, protocol, extPort, intClient, intPort,
|
||||
enabled, duration,
|
||||
desc, rHost);
|
||||
*/
|
||||
printf("%2d %s %5s->%s:%-5s '%s' '%s'\n",
|
||||
i, protocol, extPort, intClient, intPort,
|
||||
desc, rHost);
|
||||
else
|
||||
printf("GetGenericPortMappingEntry() returned %d (%s)\n",
|
||||
r, strupnperror(r));
|
||||
i++;
|
||||
} while(r==0);
|
||||
}
|
||||
|
||||
/* Test function
|
||||
* 1 - get connection type
|
||||
* 2 - get extenal ip address
|
||||
* 3 - Add port mapping
|
||||
* 4 - get this port mapping from the IGD */
|
||||
static void SetRedirectAndTest(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data,
|
||||
const char * iaddr,
|
||||
const char * iport,
|
||||
const char * eport,
|
||||
const char * proto)
|
||||
{
|
||||
char externalIPAddress[16];
|
||||
char intClient[16];
|
||||
char intPort[6];
|
||||
int r;
|
||||
|
||||
if(!iaddr || !iport || !eport || !proto)
|
||||
{
|
||||
fprintf(stderr, "Wrong arguments\n");
|
||||
return;
|
||||
}
|
||||
proto = protofix(proto);
|
||||
if(!proto)
|
||||
{
|
||||
fprintf(stderr, "invalid protocol\n");
|
||||
return;
|
||||
}
|
||||
|
||||
UPNP_GetExternalIPAddress(urls->controlURL,
|
||||
data->servicetype,
|
||||
externalIPAddress);
|
||||
if(externalIPAddress[0])
|
||||
printf("ExternalIPAddress = %s\n", externalIPAddress);
|
||||
else
|
||||
printf("GetExternalIPAddress failed.\n");
|
||||
|
||||
r = UPNP_AddPortMapping(urls->controlURL, data->servicetype,
|
||||
eport, iport, iaddr, 0, proto, 0);
|
||||
if(r!=UPNPCOMMAND_SUCCESS)
|
||||
printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
|
||||
eport, iport, iaddr, r, strupnperror(r));
|
||||
|
||||
r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
|
||||
data->servicetype,
|
||||
eport, proto,
|
||||
intClient, intPort);
|
||||
if(r!=UPNPCOMMAND_SUCCESS)
|
||||
printf("GetSpecificPortMappingEntry() failed with code %d (%s)\n",
|
||||
r, strupnperror(r));
|
||||
|
||||
if(intClient[0]) {
|
||||
printf("InternalIP:Port = %s:%s\n", intClient, intPort);
|
||||
printf("external %s:%s %s is redirected to internal %s:%s\n",
|
||||
externalIPAddress, eport, proto, intClient, intPort);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
RemoveRedirect(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data,
|
||||
const char * eport,
|
||||
const char * proto)
|
||||
{
|
||||
int r;
|
||||
if(!proto || !eport)
|
||||
{
|
||||
fprintf(stderr, "invalid arguments\n");
|
||||
return;
|
||||
}
|
||||
proto = protofix(proto);
|
||||
if(!proto)
|
||||
{
|
||||
fprintf(stderr, "protocol invalid\n");
|
||||
return;
|
||||
}
|
||||
r = UPNP_DeletePortMapping(urls->controlURL, data->servicetype, eport, proto, 0);
|
||||
printf("UPNP_DeletePortMapping() returned : %d\n", r);
|
||||
}
|
||||
|
||||
|
||||
/* sample upnp client program */
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
char command = 0;
|
||||
char ** commandargv = 0;
|
||||
int commandargc = 0;
|
||||
struct UPNPDev * devlist = 0;
|
||||
char lanaddr[16]; /* my ip address on the LAN */
|
||||
int i;
|
||||
const char * rootdescurl = 0;
|
||||
const char * multicastif = 0;
|
||||
const char * minissdpdpath = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
WSADATA wsaData;
|
||||
int nResult = WSAStartup(MAKEWORD(2,2), &wsaData);
|
||||
if(nResult != NO_ERROR)
|
||||
{
|
||||
fprintf(stderr, "WSAStartup() failed.\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
printf("upnpc : miniupnpc library test client. (c) 2006-2009 Thomas Bernard\n");
|
||||
printf("Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/\n"
|
||||
"for more information.\n");
|
||||
/* command line processing */
|
||||
for(i=1; i<argc; i++)
|
||||
{
|
||||
if(argv[i][0] == '-')
|
||||
{
|
||||
if(argv[i][1] == 'u')
|
||||
rootdescurl = argv[++i];
|
||||
else if(argv[i][1] == 'm')
|
||||
multicastif = argv[++i];
|
||||
else if(argv[i][1] == 'p')
|
||||
minissdpdpath = argv[++i];
|
||||
else
|
||||
{
|
||||
command = argv[i][1];
|
||||
i++;
|
||||
commandargv = argv + i;
|
||||
commandargc = argc - i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "option '%s' invalid\n", argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!command || (command == 'a' && commandargc<4)
|
||||
|| (command == 'd' && argc<2)
|
||||
|| (command == 'r' && argc<2))
|
||||
{
|
||||
fprintf(stderr, "Usage :\t%s [options] -a ip port external_port protocol\n\t\tAdd port redirection\n", argv[0]);
|
||||
fprintf(stderr, " \t%s [options] -d external_port protocol [port2 protocol2] [...]\n\t\tDelete port redirection\n", argv[0]);
|
||||
fprintf(stderr, " \t%s [options] -s\n\t\tGet Connection status\n", argv[0]);
|
||||
fprintf(stderr, " \t%s [options] -l\n\t\tList redirections\n", argv[0]);
|
||||
fprintf(stderr, " \t%s [options] -r port1 protocol1 [port2 protocol2] [...]\n\t\tAdd all redirections to the current host\n", argv[0]);
|
||||
fprintf(stderr, "\nprotocol is UDP or TCP\n");
|
||||
fprintf(stderr, "Options:\n");
|
||||
fprintf(stderr, " -u url : bypass discovery process by providing the XML root description url.\n");
|
||||
fprintf(stderr, " -m address : provide ip address of the interface to use for sending SSDP multicast packets.\n");
|
||||
fprintf(stderr, " -p path : use this path for MiniSSDPd socket.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( rootdescurl
|
||||
|| (devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0)))
|
||||
{
|
||||
struct UPNPDev * device;
|
||||
struct UPNPUrls urls;
|
||||
struct IGDdatas data;
|
||||
if(devlist)
|
||||
{
|
||||
printf("List of UPNP devices found on the network :\n");
|
||||
for(device = devlist; device; device = device->pNext)
|
||||
{
|
||||
printf(" desc: %s\n st: %s\n\n",
|
||||
device->descURL, device->st);
|
||||
}
|
||||
}
|
||||
i = 1;
|
||||
if( (rootdescurl && UPNP_GetIGDFromUrl(rootdescurl, &urls, &data, lanaddr, sizeof(lanaddr)))
|
||||
|| (i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr))))
|
||||
{
|
||||
switch(i) {
|
||||
case 1:
|
||||
printf("Found valid IGD : %s\n", urls.controlURL);
|
||||
break;
|
||||
case 2:
|
||||
printf("Found a (not connected?) IGD : %s\n", urls.controlURL);
|
||||
printf("Trying to continue anyway\n");
|
||||
break;
|
||||
case 3:
|
||||
printf("UPnP device found. Is it an IGD ? : %s\n", urls.controlURL);
|
||||
printf("Trying to continue anyway\n");
|
||||
break;
|
||||
default:
|
||||
printf("Found device (igd ?) : %s\n", urls.controlURL);
|
||||
printf("Trying to continue anyway\n");
|
||||
}
|
||||
printf("Local LAN ip address : %s\n", lanaddr);
|
||||
#if 0
|
||||
printf("getting \"%s\"\n", urls.ipcondescURL);
|
||||
descXML = miniwget(urls.ipcondescURL, &descXMLsize);
|
||||
if(descXML)
|
||||
{
|
||||
/*fwrite(descXML, 1, descXMLsize, stdout);*/
|
||||
free(descXML); descXML = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch(command)
|
||||
{
|
||||
case 'l':
|
||||
DisplayInfos(&urls, &data);
|
||||
ListRedirections(&urls, &data);
|
||||
break;
|
||||
case 'a':
|
||||
SetRedirectAndTest(&urls, &data,
|
||||
commandargv[0], commandargv[1],
|
||||
commandargv[2], commandargv[3]);
|
||||
break;
|
||||
case 'd':
|
||||
for(i=0; i<commandargc; i+=2)
|
||||
{
|
||||
RemoveRedirect(&urls, &data, commandargv[i], commandargv[i+1]);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
GetConnectionStatus(&urls, &data);
|
||||
break;
|
||||
case 'r':
|
||||
for(i=0; i<commandargc; i+=2)
|
||||
{
|
||||
/*printf("port %s protocol %s\n", argv[i], argv[i+1]);*/
|
||||
SetRedirectAndTest(&urls, &data,
|
||||
lanaddr, commandargv[i],
|
||||
commandargv[i], commandargv[i+1]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown switch -%c\n", command);
|
||||
}
|
||||
|
||||
FreeUPNPUrls(&urls);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "No valid UPNP Internet Gateway Device found.\n");
|
||||
}
|
||||
freeUPNPDevlist(devlist); devlist = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "No IGD UPnP Device found on the network !\n");
|
||||
}
|
||||
|
||||
/*puts("************* HOP ***************");*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue