parent
bd83aa90c5
commit
7f3fbccbeb
|
@ -1,12 +1,13 @@
|
|||
/* $Id: testminissdpd.c,v 1.7 2012/05/02 10:28:25 nanard Exp $ */
|
||||
/* $Id: testminissdpd.c,v 1.8 2014/02/28 18:38:21 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* Author : Thomas BERNARD
|
||||
* copyright (c) 2005-2007 Thomas Bernard
|
||||
* copyright (c) 2005-2014 Thomas Bernard
|
||||
* This software is subjet to the conditions detailed in the
|
||||
* provided LICENCE file. */
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -21,6 +22,8 @@ void printresponse(const unsigned char * resp, int n)
|
|||
int i, l;
|
||||
unsigned int nresp;
|
||||
const unsigned char * p;
|
||||
if(n == 0)
|
||||
return;
|
||||
for(i=0; i<n; i++)
|
||||
printf("%02x ", resp[i]);
|
||||
printf("\n");
|
||||
|
@ -45,6 +48,23 @@ void printresponse(const unsigned char * resp, int n)
|
|||
#define SENDCOMMAND(command, size) write(s, command, size); \
|
||||
printf("Command written type=%u\n", (unsigned)command[0]);
|
||||
|
||||
int connect_unix_socket(const char * sockpath)
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_un addr;
|
||||
|
||||
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
|
||||
if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
|
||||
fprintf(stderr, "connecting to %s\n", addr.sun_path);
|
||||
perror("connect");
|
||||
exit(1);
|
||||
}
|
||||
printf("Connected.\n");
|
||||
return s;
|
||||
}
|
||||
|
||||
/* test program for minissdpd */
|
||||
int
|
||||
main(int argc, char * * argv)
|
||||
|
@ -52,7 +72,9 @@ main(int argc, char * * argv)
|
|||
char command1[] = "\x01\x00urn:schemas-upnp-org:device:InternetGatewayDevice";
|
||||
char command2[] = "\x02\x00uuid:fc4ec57e-b051-11db-88f8-0060085db3f6::upnp:rootdevice";
|
||||
char command3[] = { 0x03, 0x00 };
|
||||
struct sockaddr_un addr;
|
||||
char command4[] = "\x04\x00test:test:test";
|
||||
char bad_command[] = { 0xff, 0xff };
|
||||
char overflow[] = { 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
int s;
|
||||
int i;
|
||||
unsigned char buf[2048];
|
||||
|
@ -65,30 +87,51 @@ main(int argc, char * * argv)
|
|||
}
|
||||
command1[1] = sizeof(command1) - 3;
|
||||
command2[1] = sizeof(command2) - 3;
|
||||
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
|
||||
if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
|
||||
fprintf(stderr, "connecting to %s\n", addr.sun_path);
|
||||
perror("connect");
|
||||
return 1;
|
||||
}
|
||||
printf("Connected.\n");
|
||||
command4[1] = sizeof(command4) - 3;
|
||||
s = connect_unix_socket(sockpath);
|
||||
|
||||
SENDCOMMAND(command1, sizeof(command1) - 1);
|
||||
n = read(s, buf, sizeof(buf));
|
||||
printf("Response received %d bytes\n", (int)n);
|
||||
printresponse(buf, n);
|
||||
if(n == 0) {
|
||||
close(s);
|
||||
s = connect_unix_socket(sockpath);
|
||||
}
|
||||
|
||||
SENDCOMMAND(command2, sizeof(command2) - 1);
|
||||
n = read(s, buf, sizeof(buf));
|
||||
printf("Response received %d bytes\n", (int)n);
|
||||
printresponse(buf, n);
|
||||
if(n == 0) {
|
||||
close(s);
|
||||
s = connect_unix_socket(sockpath);
|
||||
}
|
||||
|
||||
SENDCOMMAND(command3, sizeof(command3));
|
||||
n = read(s, buf, sizeof(buf));
|
||||
printf("Response received %d bytes\n", (int)n);
|
||||
printresponse(buf, n);
|
||||
if(n == 0) {
|
||||
close(s);
|
||||
s = connect_unix_socket(sockpath);
|
||||
}
|
||||
|
||||
SENDCOMMAND(command4, sizeof(command4));
|
||||
|
||||
SENDCOMMAND(bad_command, sizeof(bad_command));
|
||||
n = read(s, buf, sizeof(buf));
|
||||
printf("Response received %d bytes\n", (int)n);
|
||||
printresponse(buf, n);
|
||||
if(n == 0) {
|
||||
close(s);
|
||||
s = connect_unix_socket(sockpath);
|
||||
}
|
||||
|
||||
SENDCOMMAND(overflow, sizeof(overflow));
|
||||
n = read(s, buf, sizeof(buf));
|
||||
printf("Response received %d bytes\n", (int)n);
|
||||
printresponse(buf, n);
|
||||
|
||||
close(s);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue