diff --git a/miniupnpc/listdevices.c b/miniupnpc/listdevices.c index 1965b60..b9d431e 100644 --- a/miniupnpc/listdevices.c +++ b/miniupnpc/listdevices.c @@ -1,7 +1,7 @@ /* $Id$ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2013 Thomas Bernard + * Copyright (c) 2013-2014 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. */ @@ -11,6 +11,7 @@ int main(int argc, char * * argv) { + const char * searched_device = NULL; const char * multicastif = 0; const char * minissdpdpath = 0; int ipv6 = 0; @@ -22,15 +23,32 @@ int main(int argc, char * * argv) for(i = 1; i < argc; i++) { if(strcmp(argv[i], "-6") == 0) ipv6 = 1; - else { + else if(strcmp(argv[i], "-d") == 0) { + if(++i >= argc) { + fprintf(stderr, "-d option needs one argument\n"); + return 1; + } + searched_device = argv[i]; + } else { printf("usage : %s [options]\n", argv[0]); + printf("options :\n"); printf(" -6 : use IPv6\n"); + printf(" -d : search only for this type of device\n"); + printf(" -h : this help\n"); return 1; } } - devlist = upnpDiscoverAll(2000, multicastif, minissdpdpath, - 0/*sameport*/, ipv6, &error); + if(searched_device) { + printf("searching UPnP device type %s\n", searched_device); + devlist = upnpDiscoverDevice(searched_device, + 2000, multicastif, minissdpdpath, + 0/*sameport*/, ipv6, &error); + } else { + printf("searching all UPnP devices\n"); + devlist = upnpDiscoverAll(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); diff --git a/miniupnpc/miniupnpc.c b/miniupnpc/miniupnpc.c index 80facc5..9c61be1 100644 --- a/miniupnpc/miniupnpc.c +++ b/miniupnpc/miniupnpc.c @@ -2,7 +2,7 @@ /* Project : miniupnp * Web : http://miniupnp.free.fr/ * Author : Thomas BERNARD - * copyright (c) 2005-2013 Thomas Bernard + * copyright (c) 2005-2014 Thomas Bernard * This software is subjet to the conditions detailed in the * provided LICENSE file. */ #define __EXTENSIONS__ 1 @@ -330,7 +330,7 @@ parseMSEARCHReply(const char * reply, int size, #define UPNP_MCAST_LL_ADDR "FF02::C" /* link-local */ #define UPNP_MCAST_SL_ADDR "FF05::C" /* site-local */ -/* upnpDiscover() : +/* upnpDiscoverDevices() : * return a chained list of all devices found or NULL if * no devices was found. * It is up to the caller to free the chained list @@ -705,6 +705,7 @@ error: return devlist; } +/* upnpDiscover() Discover IGD device */ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, const char * minissdpdsock, int sameport, @@ -728,6 +729,7 @@ upnpDiscover(int delay, const char * multicastif, ipv6, error); } +/* upnpDiscoverAll() Discover all UPnP devices */ LIBSPEC struct UPNPDev * upnpDiscoverAll(int delay, const char * multicastif, const char * minissdpdsock, int sameport, @@ -744,6 +746,22 @@ upnpDiscoverAll(int delay, const char * multicastif, ipv6, error); } +/* upnpDiscoverDevice() Discover a specific device */ +LIBSPEC struct UPNPDev * +upnpDiscoverDevice(const char * device, int delay, const char * multicastif, + const char * minissdpdsock, int sameport, + int ipv6, + int * error) +{ + const char * const deviceList[] = { + device, + 0 + }; + return upnpDiscoverDevices(deviceList, + delay, multicastif, minissdpdsock, sameport, + ipv6, error); +} + /* freeUPNPDevlist() should be used to * free the chained list returned by upnpDiscover() */ LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist) diff --git a/miniupnpc/miniupnpc.h b/miniupnpc/miniupnpc.h index 9cf48f4..c66d141 100644 --- a/miniupnpc/miniupnpc.h +++ b/miniupnpc/miniupnpc.h @@ -2,7 +2,7 @@ /* Project: miniupnp * http://miniupnp.free.fr/ * Author: Thomas Bernard - * Copyright (c) 2005-2012 Thomas Bernard + * Copyright (c) 2005-2014 Thomas Bernard * This software is subjects to the conditions detailed * in the LICENCE file provided within this distribution */ #ifndef MINIUPNPC_H_INCLUDED @@ -66,6 +66,19 @@ upnpDiscoverAll(int delay, const char * multicastif, int ipv6, int * error); +LIBSPEC struct UPNPDev * +upnpDiscoverDevice(const char * device, int delay, const char * multicastif, + const char * minissdpdsock, int sameport, + int ipv6, + int * error); + +LIBSPEC struct UPNPDev * +upnpDiscoverDevices(const char * const deviceTypes[], + int delay, const char * multicastif, + const char * minissdpdsock, int sameport, + int ipv6, + int * error); + /* freeUPNPDevlist() * free list returned by upnpDiscover() */ LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);