miniupnpc.c: added upnpDiscoverDevice()
This commit is contained in:
parent
66bd0cce2d
commit
bf3a91ba83
|
@ -1,7 +1,7 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/* Project : miniupnp
|
/* Project : miniupnp
|
||||||
* Author : Thomas Bernard
|
* Author : Thomas Bernard
|
||||||
* Copyright (c) 2013 Thomas Bernard
|
* Copyright (c) 2013-2014 Thomas Bernard
|
||||||
* This software is subject to the conditions detailed in the
|
* This software is subject to the conditions detailed in the
|
||||||
* LICENCE file provided in this distribution. */
|
* LICENCE file provided in this distribution. */
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
int main(int argc, char * * argv)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
|
const char * searched_device = NULL;
|
||||||
const char * multicastif = 0;
|
const char * multicastif = 0;
|
||||||
const char * minissdpdpath = 0;
|
const char * minissdpdpath = 0;
|
||||||
int ipv6 = 0;
|
int ipv6 = 0;
|
||||||
|
@ -22,15 +23,32 @@ int main(int argc, char * * argv)
|
||||||
for(i = 1; i < argc; i++) {
|
for(i = 1; i < argc; i++) {
|
||||||
if(strcmp(argv[i], "-6") == 0)
|
if(strcmp(argv[i], "-6") == 0)
|
||||||
ipv6 = 1;
|
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("usage : %s [options]\n", argv[0]);
|
||||||
|
printf("options :\n");
|
||||||
printf(" -6 : use IPv6\n");
|
printf(" -6 : use IPv6\n");
|
||||||
|
printf(" -d <device string> : search only for this type of device\n");
|
||||||
|
printf(" -h : this help\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
devlist = upnpDiscoverAll(2000, multicastif, minissdpdpath,
|
if(searched_device) {
|
||||||
0/*sameport*/, ipv6, &error);
|
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) {
|
if(devlist) {
|
||||||
for(dev = devlist; dev != NULL; dev = dev->pNext) {
|
for(dev = devlist; dev != NULL; dev = dev->pNext) {
|
||||||
printf("%s\t%s\n", dev->st, dev->descURL);
|
printf("%s\t%s\n", dev->st, dev->descURL);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/* Project : miniupnp
|
/* Project : miniupnp
|
||||||
* Web : http://miniupnp.free.fr/
|
* Web : http://miniupnp.free.fr/
|
||||||
* Author : Thomas BERNARD
|
* 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
|
* This software is subjet to the conditions detailed in the
|
||||||
* provided LICENSE file. */
|
* provided LICENSE file. */
|
||||||
#define __EXTENSIONS__ 1
|
#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_LL_ADDR "FF02::C" /* link-local */
|
||||||
#define UPNP_MCAST_SL_ADDR "FF05::C" /* site-local */
|
#define UPNP_MCAST_SL_ADDR "FF05::C" /* site-local */
|
||||||
|
|
||||||
/* upnpDiscover() :
|
/* upnpDiscoverDevices() :
|
||||||
* return a chained list of all devices found or NULL if
|
* return a chained list of all devices found or NULL if
|
||||||
* no devices was found.
|
* no devices was found.
|
||||||
* It is up to the caller to free the chained list
|
* It is up to the caller to free the chained list
|
||||||
|
@ -705,6 +705,7 @@ error:
|
||||||
return devlist;
|
return devlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* upnpDiscover() Discover IGD device */
|
||||||
LIBSPEC struct UPNPDev *
|
LIBSPEC struct UPNPDev *
|
||||||
upnpDiscover(int delay, const char * multicastif,
|
upnpDiscover(int delay, const char * multicastif,
|
||||||
const char * minissdpdsock, int sameport,
|
const char * minissdpdsock, int sameport,
|
||||||
|
@ -728,6 +729,7 @@ upnpDiscover(int delay, const char * multicastif,
|
||||||
ipv6, error);
|
ipv6, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* upnpDiscoverAll() Discover all UPnP devices */
|
||||||
LIBSPEC struct UPNPDev *
|
LIBSPEC struct UPNPDev *
|
||||||
upnpDiscoverAll(int delay, const char * multicastif,
|
upnpDiscoverAll(int delay, const char * multicastif,
|
||||||
const char * minissdpdsock, int sameport,
|
const char * minissdpdsock, int sameport,
|
||||||
|
@ -744,6 +746,22 @@ upnpDiscoverAll(int delay, const char * multicastif,
|
||||||
ipv6, error);
|
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
|
/* freeUPNPDevlist() should be used to
|
||||||
* free the chained list returned by upnpDiscover() */
|
* free the chained list returned by upnpDiscover() */
|
||||||
LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist)
|
LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/* Project: miniupnp
|
/* Project: miniupnp
|
||||||
* http://miniupnp.free.fr/
|
* http://miniupnp.free.fr/
|
||||||
* Author: Thomas Bernard
|
* Author: Thomas Bernard
|
||||||
* Copyright (c) 2005-2012 Thomas Bernard
|
* Copyright (c) 2005-2014 Thomas Bernard
|
||||||
* This software is subjects to the conditions detailed
|
* This software is subjects to the conditions detailed
|
||||||
* in the LICENCE file provided within this distribution */
|
* in the LICENCE file provided within this distribution */
|
||||||
#ifndef MINIUPNPC_H_INCLUDED
|
#ifndef MINIUPNPC_H_INCLUDED
|
||||||
|
@ -66,6 +66,19 @@ upnpDiscoverAll(int delay, const char * multicastif,
|
||||||
int ipv6,
|
int ipv6,
|
||||||
int * error);
|
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()
|
/* freeUPNPDevlist()
|
||||||
* free list returned by upnpDiscover() */
|
* free list returned by upnpDiscover() */
|
||||||
LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);
|
LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);
|
||||||
|
|
Loading…
Reference in New Issue