1/* $Id: listdevices.c,v 1.2 2014/11/17 09:50:56 nanard Exp $ */ 2/* Project : miniupnp 3 * Author : Thomas Bernard 4 * Copyright (c) 2013-2014 Thomas Bernard 5 * This software is subject to the conditions detailed in the 6 * LICENCE file provided in this distribution. */ 7 8#include <stdio.h> 9#include <string.h> 10#include "miniupnpc.h" 11 12int main(int argc, char * * argv) 13{ 14 const char * searched_device = NULL; 15 const char * multicastif = 0; 16 const char * minissdpdpath = 0; 17 int ipv6 = 0; 18 int error = 0; 19 struct UPNPDev * devlist = 0; 20 struct UPNPDev * dev; 21 int i; 22 23 for(i = 1; i < argc; i++) { 24 if(strcmp(argv[i], "-6") == 0) 25 ipv6 = 1; 26 else if(strcmp(argv[i], "-d") == 0) { 27 if(++i >= argc) { 28 fprintf(stderr, "-d option needs one argument\n"); 29 return 1; 30 } 31 searched_device = argv[i]; 32 } else if(strcmp(argv[i], "-m") == 0) { 33 if(++i >= argc) { 34 fprintf(stderr, "-m option needs one argument\n"); 35 return 1; 36 } 37 multicastif = argv[i]; 38 } else { 39 printf("usage : %s [options]\n", argv[0]); 40 printf("options :\n"); 41 printf(" -6 : use IPv6\n"); 42 printf(" -d <device string> : search only for this type of device\n"); 43 printf(" -m address/ifname : network interface to use for multicast\n"); 44 printf(" -h : this help\n"); 45 return 1; 46 } 47 } 48 49 if(searched_device) { 50 printf("searching UPnP device type %s\n", searched_device); 51 devlist = upnpDiscoverDevice(searched_device, 52 2000, multicastif, minissdpdpath, 53 0/*sameport*/, ipv6, &error); 54 } else { 55 printf("searching all UPnP devices\n"); 56 devlist = upnpDiscoverAll(2000, multicastif, minissdpdpath, 57 0/*sameport*/, ipv6, &error); 58 } 59 if(devlist) { 60 for(dev = devlist; dev != NULL; dev = dev->pNext) { 61 printf("%-48s\t%s\n", dev->st, dev->descURL); 62 } 63 freeUPNPDevlist(devlist); 64 } else { 65 printf("no device found.\n"); 66 } 67 68 return 0; 69} 70 71