From d06140277bd22e8486d0fad7bc2ec79e32e80f2b Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 16 Feb 2013 10:25:10 +0100 Subject: [PATCH] Adding listdevice program --- miniupnpc/.gitignore | 1 + miniupnpc/Makefile | 8 ++++++-- miniupnpc/listdevices.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 miniupnpc/listdevices.c diff --git a/miniupnpc/.gitignore b/miniupnpc/.gitignore index 7ad3b62..87ab018 100644 --- a/miniupnpc/.gitignore +++ b/miniupnpc/.gitignore @@ -20,3 +20,4 @@ _jnaerator.* out.errors.txt jnaerator-*.jar miniupnpc.h.bak +listdevices diff --git a/miniupnpc/Makefile b/miniupnpc/Makefile index 3d919b1..6d6a28d 100644 --- a/miniupnpc/Makefile +++ b/miniupnpc/Makefile @@ -54,7 +54,8 @@ 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 testminiwget.c \ - connecthostport.c portlistingparse.c receivedata.c + connecthostport.c portlistingparse.c receivedata.c \ + listdevices.c LIBOBJS = miniwget.o minixml.o igd_desc_parse.o minisoap.o \ miniupnpc.o upnpreplyparse.o upnpcommands.o upnperrors.o \ @@ -89,7 +90,7 @@ ifeq ($(JARSUFFIX), win32) endif endif -EXECUTABLES = upnpc-static +EXECUTABLES = upnpc-static listdevices EXECUTABLES_ADDTESTS = testminixml minixmlvalid testupnpreplyparse \ testigddescparse testminiwget @@ -226,6 +227,9 @@ upnpc-static: upnpc.o $(LIBRARY) $(LDLIBS) upnpc-shared: upnpc.o $(SHAREDLIBRARY) $(LDLIBS) $(CC) $(LDFLAGS) -o $@ $^ +listdevices: listdevices.o $(LIBRARY) $(LDLIBS) + $(CC) $(LDFLAGS) -o $@ $^ + testminixml: $(TESTMINIXMLOBJS) testminiwget: $(TESTMINIWGETOBJS) diff --git a/miniupnpc/listdevices.c b/miniupnpc/listdevices.c new file mode 100644 index 0000000..6a3057b --- /dev/null +++ b/miniupnpc/listdevices.c @@ -0,0 +1,33 @@ +/* $Id$ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2013 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. */ + +#include +#include "miniupnpc.h" + +int main(int argc, char * * argv) +{ + const char * multicastif = 0; + const char * minissdpdpath = 0; + int ipv6 = 0; + int error = 0; + struct UPNPDev * devlist = 0; + struct UPNPDev * dev; + + devlist = upnpDiscover(2000, multicastif, minissdpdpath, + 0/*sameport*/, ipv6, &error); + if(devlist) { + for(dev = devlist; dev != NULL; dev = dev->pNext) { + printf("%s\t%s\n", dev->st, dev->descURL); + } + freeUPNPDevlist(devlist); + } else { + printf("no device found.\n"); + } + + return 0; +} +