2015-05-22 10:25:51 +00:00
|
|
|
/* $Id: listdevices.c,v 1.3 2015/05/22 10:14:04 nanard Exp $ */
|
2013-02-16 09:25:10 +00:00
|
|
|
/* Project : miniupnp
|
|
|
|
* Author : Thomas Bernard
|
2014-01-31 13:59:21 +00:00
|
|
|
* Copyright (c) 2013-2014 Thomas Bernard
|
2013-02-16 09:25:10 +00:00
|
|
|
* This software is subject to the conditions detailed in the
|
|
|
|
* LICENCE file provided in this distribution. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2013-02-20 16:04:53 +00:00
|
|
|
#include <string.h>
|
2013-02-16 09:25:10 +00:00
|
|
|
#include "miniupnpc.h"
|
|
|
|
|
|
|
|
int main(int argc, char * * argv)
|
|
|
|
{
|
2014-01-31 13:59:21 +00:00
|
|
|
const char * searched_device = NULL;
|
2013-02-16 09:25:10 +00:00
|
|
|
const char * multicastif = 0;
|
|
|
|
const char * minissdpdpath = 0;
|
|
|
|
int ipv6 = 0;
|
|
|
|
int error = 0;
|
|
|
|
struct UPNPDev * devlist = 0;
|
|
|
|
struct UPNPDev * dev;
|
2013-02-20 16:04:53 +00:00
|
|
|
int i;
|
2013-02-16 09:25:10 +00:00
|
|
|
|
2013-02-20 16:04:53 +00:00
|
|
|
for(i = 1; i < argc; i++) {
|
|
|
|
if(strcmp(argv[i], "-6") == 0)
|
|
|
|
ipv6 = 1;
|
2014-01-31 13:59:21 +00:00
|
|
|
else if(strcmp(argv[i], "-d") == 0) {
|
|
|
|
if(++i >= argc) {
|
|
|
|
fprintf(stderr, "-d option needs one argument\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
searched_device = argv[i];
|
2014-11-17 09:54:09 +00:00
|
|
|
} else if(strcmp(argv[i], "-m") == 0) {
|
|
|
|
if(++i >= argc) {
|
|
|
|
fprintf(stderr, "-m option needs one argument\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
multicastif = argv[i];
|
2014-01-31 13:59:21 +00:00
|
|
|
} else {
|
2013-02-20 16:04:53 +00:00
|
|
|
printf("usage : %s [options]\n", argv[0]);
|
2014-01-31 13:59:21 +00:00
|
|
|
printf("options :\n");
|
2013-02-20 16:04:53 +00:00
|
|
|
printf(" -6 : use IPv6\n");
|
2014-01-31 13:59:21 +00:00
|
|
|
printf(" -d <device string> : search only for this type of device\n");
|
2014-11-17 09:54:09 +00:00
|
|
|
printf(" -m address/ifname : network interface to use for multicast\n");
|
2014-01-31 13:59:21 +00:00
|
|
|
printf(" -h : this help\n");
|
2013-02-20 16:04:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 13:59:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2013-02-16 09:25:10 +00:00
|
|
|
if(devlist) {
|
|
|
|
for(dev = devlist; dev != NULL; dev = dev->pNext) {
|
2014-04-14 16:11:01 +00:00
|
|
|
printf("%-48s\t%s\n", dev->st, dev->descURL);
|
2013-02-16 09:25:10 +00:00
|
|
|
}
|
|
|
|
freeUPNPDevlist(devlist);
|
|
|
|
} else {
|
|
|
|
printf("no device found.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|