improve printresponse() to consume all buffer bytes
This commit is contained in:
parent
02e64e9f85
commit
eea61f81c3
|
@ -1,5 +1,6 @@
|
||||||
/* $Id: $ */
|
/* $Id: $ */
|
||||||
/* Project : miniupnp
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
||||||
|
* Project : miniupnp
|
||||||
* website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* Author : Thomas BERNARD
|
* Author : Thomas BERNARD
|
||||||
* copyright (c) 2005-2016 Thomas Bernard
|
* copyright (c) 2005-2016 Thomas Bernard
|
||||||
|
@ -36,48 +37,50 @@ void printresponse(const unsigned char * resp, int n)
|
||||||
putchar((resp[l] >= ' ' && resp[l] < 128) ? resp[l] : '.');
|
putchar((resp[l] >= ' ' && resp[l] < 128) ? resp[l] : '.');
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
/* now parse and display all devices of response */
|
for(p = resp; p < resp + n; ) {
|
||||||
nresp = resp[0]; /* 1st byte : number of devices in response */
|
/* now parse and display all devices of response */
|
||||||
if(nresp == 0xff) {
|
nresp = p[0]; /* 1st byte : number of devices in response */
|
||||||
/* notification */
|
if(nresp == 0xff) {
|
||||||
notif_type = resp[1];
|
/* notification */
|
||||||
nresp = resp[2];
|
notif_type = p[1];
|
||||||
printf("Notification : ");
|
nresp = p[2];
|
||||||
switch(notif_type) {
|
printf("Notification : ");
|
||||||
case NOTIF_NEW: printf("new\n"); break;
|
switch(notif_type) {
|
||||||
case NOTIF_UPDATE: printf("update\n"); break;
|
case NOTIF_NEW: printf("new\n"); break;
|
||||||
case NOTIF_REMOVE: printf("remove\n"); break;
|
case NOTIF_UPDATE: printf("update\n"); break;
|
||||||
default: printf("**UNKNOWN**\n");
|
case NOTIF_REMOVE: printf("remove\n"); break;
|
||||||
|
default: printf("**UNKNOWN**\n");
|
||||||
|
}
|
||||||
|
p += 3;
|
||||||
|
} else {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
for(i = 0; i < (int)nresp; i++) {
|
||||||
|
if(p >= resp + n)
|
||||||
|
goto error;
|
||||||
|
/*l = *(p++);*/
|
||||||
|
DECODELENGTH(l, p);
|
||||||
|
if(p + l > resp + n)
|
||||||
|
goto error;
|
||||||
|
printf("%d - %.*s\n", i, l, p); /* URL */
|
||||||
|
p += l;
|
||||||
|
if(p >= resp + n)
|
||||||
|
goto error;
|
||||||
|
/*l = *(p++);*/
|
||||||
|
DECODELENGTH(l, p);
|
||||||
|
if(p + l > resp + n)
|
||||||
|
goto error;
|
||||||
|
printf(" %.*s\n", l, p); /* ST */
|
||||||
|
p += l;
|
||||||
|
if(p >= resp + n)
|
||||||
|
goto error;
|
||||||
|
/*l = *(p++);*/
|
||||||
|
DECODELENGTH(l, p);
|
||||||
|
if(p + l > resp + n)
|
||||||
|
goto error;
|
||||||
|
printf(" %.*s\n", l, p); /* USN */
|
||||||
|
p += l;
|
||||||
}
|
}
|
||||||
p = resp + 3;
|
|
||||||
} else {
|
|
||||||
p = resp + 1;
|
|
||||||
}
|
|
||||||
for(i = 0; i < (int)nresp; i++) {
|
|
||||||
if(p >= resp + n)
|
|
||||||
goto error;
|
|
||||||
/*l = *(p++);*/
|
|
||||||
DECODELENGTH(l, p);
|
|
||||||
if(p + l > resp + n)
|
|
||||||
goto error;
|
|
||||||
printf("%d - %.*s\n", i, l, p); /* URL */
|
|
||||||
p += l;
|
|
||||||
if(p >= resp + n)
|
|
||||||
goto error;
|
|
||||||
/*l = *(p++);*/
|
|
||||||
DECODELENGTH(l, p);
|
|
||||||
if(p + l > resp + n)
|
|
||||||
goto error;
|
|
||||||
printf(" %.*s\n", l, p); /* ST */
|
|
||||||
p += l;
|
|
||||||
if(p >= resp + n)
|
|
||||||
goto error;
|
|
||||||
/*l = *(p++);*/
|
|
||||||
DECODELENGTH(l, p);
|
|
||||||
if(p + l > resp + n)
|
|
||||||
goto error;
|
|
||||||
printf(" %.*s\n", l, p); /* USN */
|
|
||||||
p += l;
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
error:
|
error:
|
||||||
|
|
Loading…
Reference in New Issue