Reputation: 745
I'm working in openWRT linux environment, and trying to enable UPnP on my LAN network, while monitoring the connected devices at any given point.
For that, I've enabled miniupnpd in the system, as well as minissdpd.
I have written the following function, for investigation of minissdpd in attempt to understand which devices are currently connected (based on minissdpd code owner example) :
static int query_connectedDevices(void)
{
struct sockaddr_un addr;
int s, nRet = 0;
const char * minissdpdsocketpath = "/var/run/minissdpd.sock";
unsigned char buffer[2048];
unsigned char * p;
const char * device = "urn:schemas-upnp-org:device:InternetGatewayDevice:1";
int device_len = (int)strlen(device);
/*Open communication socket with minissdpd process*/
s = socket(AF_UNIX, SOCK_STREAM, 0);
if(s < 0) {
return -1;
}
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, minissdpdsocketpath, sizeof(addr.sun_path));
if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
return -1;
}
buffer[0] = 1; /* request type 1 : request devices/services by type */
p = buffer + 1;
CODELENGTH(device_len, p);
memcpy(p, device, device_len);
p += device_len;
nRet = write(s, buffer, p - buffer);
if (nRet < 0) {
goto query_exit;
}
memset(buffer, 0x0, sizeof(buffer));
nRet = read(s, buffer, sizeof(buffer));
if (nRet < 0) {
goto query_exit;
}
nRet = 0;
query_exit:
close (s);
return nRet;
}
My problem is that I always receive back the value '1' from minissdpd, no matter how many devices are actually connected to UPnP network.
Taken from minissdpd page -
For these three request types, the responses is as following :
The first byte (n) is the number of devices/services in the response For each service/device, three Strings : Location (url), service type (ST: in M-SEARCH replies) and USN (unique id).
**Edit -
I've tried to trigger all 3 supported request types, these are the responses, note that empty read back ="" means no data was read back:
Buffer value = 3urn:schemas-upnp-org:device:InternetGatewayDevice:1
Buffer value read back = return value = 1
Buffer value = 3urn:schemas-upnp-org:device:InternetGatewayDevice:1
Buffer value read back = return value = 1
Buffer value = 3urn:schemas-upnp-org:device:InternetGatewayDevice:1
Buffer value read back = $http://192.168.1.1:5000/rootDesc.xml/urn:schemas- upnp-org:service:Layer3Forwarding:1Zuuid:27f10a12-a448-434f-9b33- 966bcf662cc3::urn:schemas-upnp- org:service:Layer3Forwarding:1$http://192.168.1.1:5000/rootDesc.xml.urn:schemas- upnp-org:service:WANIPConnection:1Yuuid:27f10a12-a448-434f-9b33- 966bcf662cc3::urn:schemas-upnp- org:service:WANIPConnection:1$http://192.168.1.1:5000/rootDesc.xmlupnp:rootdevic e:uuid:27f10a12-a448-434f-9b33-966bcf662cc3::upnp:rootdevice return value = 463
Am I doing something wrong?
Thanks!
Upvotes: 2
Views: 356
Reputation: 96
What do you mean by "enable UPnP on my LAN" ?
miniupnpd is a IGD implementation, it has nothing to do with UPnP AV for example.
To discover all UPnP devices present on your LAN, you can use the listdevice tool provided with miniupnpc.
minissdpd monitors available UPnP devices on the network. It is used by libminiupnpc if available to get device list.
It is OK that it returns only 1 device when requested devices with type urn:schemas-upnp-org:device:InternetGatewayDevice:1 (IGD).
I guess there is only one UPnP IGD on your LAN : the router.
What do you mean by "no matter how many clients are actually connected to UPnP network.". There is no such thing as "client" in UPnP official terminology. There are UPnP Devices on the network, and Control Points
Upvotes: 1