minissdpd: added command 0 (version)

This commit is contained in:
Thomas Bernard 2015-08-06 15:20:30 +02:00
parent 1c84e560ac
commit aefeada189
6 changed files with 64 additions and 12 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.41 2015/07/21 15:39:36 nanard Exp $
$Id: Changelog.txt,v 1.42 2015/08/06 13:16:58 nanard Exp $
2015/08/06:
added command 0 (version)
2015/07/21:
set multicast TTL to 2 by default and configurable

View File

@ -24,6 +24,7 @@ close unix socket connection.
* Request format :
1st byte : request type
0 - version
1 - type
2 - USN (unique id)
3 - everything
@ -33,6 +34,12 @@ one additional byte should be read, etc. (see codelength.h)
n bytes = string
Response format :
request type 0 (version) :
n bytes string length
n bytes = version string
request type 1 / 2 / 3 :
1st byte : number of services/devices
For each service/device :
URL :

View File

@ -6,6 +6,7 @@ fermeture de la connexion.
format de requete :
1 octet : type de la requete
0 - version
1 - type
2 - USN (id unique)
3 - tout

View File

@ -1,12 +1,14 @@
/* $Id: config.h,v 1.6 2012/09/27 15:40:29 nanard Exp $ */
/* $Id: config.h,v 1.9 2015/08/06 13:16:58 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2011 Thomas Bernard
* (c) 2006-2015 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#ifndef CONFIG_H_INCLUDED
#define CONFIG_H_INCLUDED
#define MINISSDPD_VERSION "1.3"
/* use BSD daemon() ? */
#define USE_DAEMON

View File

@ -1,4 +1,4 @@
/* $Id: minissdpd.c,v 1.48 2015/07/21 15:39:36 nanard Exp $ */
/* $Id: minissdpd.c,v 1.49 2015/08/06 13:16:58 nanard Exp $ */
/* MiniUPnP project
* (c) 2007-2015 Thomas Bernard
* website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -27,8 +27,10 @@
/* unix sockets */
#include <sys/un.h>
/* for getpwnam() and getgrnam() */
#if 0
#include <pwd.h>
#include <grp.h>
#endif
#include "getifaddr.h"
#include "upnputils.h"
@ -727,7 +729,7 @@ void processRequest(struct reqelem * req)
int type;
struct device * d = devlist;
unsigned char rbuf[RESPONSE_BUFFER_SIZE];
unsigned char * rp = rbuf+1;
unsigned char * rp;
unsigned char nrep = 0;
time_t t;
struct service * newserv = NULL;
@ -749,19 +751,31 @@ void processRequest(struct reqelem * req)
p = buf + 1;
DECODELENGTH_CHECKLIMIT(l, p, buf + n);
if(p+l > buf+n) {
syslog(LOG_WARNING, "bad request (length encoding)");
syslog(LOG_WARNING, "bad request (length encoding l=%u n=%u)",
l, (unsigned)n);
goto error;
}
if(l == 0 && type != 3) {
if(l == 0 && type != 3 && type != 0) {
syslog(LOG_WARNING, "bad request (length=0)");
goto error;
}
syslog(LOG_INFO, "(s=%d) request type=%d str='%.*s'",
req->socket, type, l, p);
switch(type) {
case 0: /* version */
rp = rbuf;
CODELENGTH((sizeof(MINISSDPD_VERSION) - 1), rp);
memcpy(rp, MINISSDPD_VERSION, sizeof(MINISSDPD_VERSION) - 1);
rp += (sizeof(MINISSDPD_VERSION) - 1);
if(write_or_buffer(req, rbuf, rp - rbuf) < 0) {
syslog(LOG_ERR, "(s=%d) write: %m", req->socket);
goto error;
}
break;
case 1: /* request by type */
case 2: /* request by USN (unique id) */
case 3: /* everything */
rp = rbuf+1;
while(d && (nrep < 255)) {
if(d->t < t) {
syslog(LOG_INFO, "outdated device");

View File

@ -1,4 +1,4 @@
/* $Id: testminissdpd.c,v 1.11 2015/05/27 20:03:21 nanard Exp $ */
/* $Id: testminissdpd.c,v 1.12 2015/08/06 13:16:59 nanard Exp $ */
/* Project : miniupnp
* website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* Author : Thomas BERNARD
@ -18,6 +18,19 @@
do { n = (n << 7) | (*p & 0x7f); } \
while(*(p++)&0x80);
void printversion(const unsigned char * resp, int n)
{
int l;
const unsigned char * p;
p = resp;
DECODELENGTH(l, p);
if(resp + n < p + l) {
printf("get version error\n");
}
printf("MiniSSDPd version : %.*s\n", l, p);
}
void printresponse(const unsigned char * resp, int n)
{
int i, l;
@ -97,6 +110,7 @@ int connect_unix_socket(const char * sockpath)
int
main(int argc, char * * argv)
{
char command0[] = { 0x00, 0x00 };
char command1[] = "\x01\x00urn:schemas-upnp-org:device:InternetGatewayDevice";
char command2[] = "\x02\x00uuid:fc4ec57e-b051-11db-88f8-0060085db3f6::upnp:rootdevice";
char command3[] = { 0x03, 0x00 };
@ -126,6 +140,17 @@ main(int argc, char * * argv)
command4[1] = sizeof(command4) - 3;
s = connect_unix_socket(sockpath);
n = SENDCOMMAND(command0, sizeof(command0));
n = read(s, buf, sizeof(buf));
printf("Response received %d bytes\n", (int)n);
if(n > 0) {
printversion(buf, n);
} else {
printf("Command 0 (get version) not supported\n");
close(s);
s = connect_unix_socket(sockpath);
}
n = SENDCOMMAND(command1, sizeof(command1) - 1);
n = read(s, buf, sizeof(buf));
printf("Response received %d bytes\n", (int)n);