2018-01-15 16:47:22 +00:00
|
|
|
/* $Id: testminissdp.c,v 1.3 2018/01/15 16:46:48 nanard Exp $ */
|
2017-12-12 09:08:44 +00:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
* MiniUPnP project
|
|
|
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
2018-01-15 16:47:22 +00:00
|
|
|
* (c) 2017-2018 Thomas Bernard
|
2017-12-12 09:08:44 +00:00
|
|
|
* This software is subject to the conditions detailed
|
|
|
|
* in the LICENCE file provided within the distribution */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <sys/queue.h>
|
2018-01-15 16:47:22 +00:00
|
|
|
#include <sys/socket.h>
|
2017-12-12 09:08:44 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "minissdp.h"
|
|
|
|
#include "upnpglobalvars.h"
|
|
|
|
|
2018-01-15 16:47:22 +00:00
|
|
|
void test(const char * buffer, size_t n)
|
2017-12-12 09:08:44 +00:00
|
|
|
{
|
|
|
|
int s = 0;
|
|
|
|
struct sockaddr_in dummy_sender;
|
|
|
|
|
|
|
|
memset(&dummy_sender, 0, sizeof(dummy_sender));
|
|
|
|
dummy_sender.sin_family = AF_INET;
|
|
|
|
|
|
|
|
ProcessSSDPData(s, buffer, n,
|
|
|
|
(struct sockaddr *)&dummy_sender, 0,
|
|
|
|
#ifdef ENABLE_HTTPS
|
|
|
|
80, 443
|
|
|
|
#else
|
|
|
|
80
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char * * argv)
|
|
|
|
{
|
|
|
|
FILE * f = NULL;
|
|
|
|
char buffer[1500];
|
2018-01-15 16:47:22 +00:00
|
|
|
size_t n = 0;
|
2017-12-12 09:08:44 +00:00
|
|
|
struct lan_addr_s * lan_addr;
|
|
|
|
|
|
|
|
if((argc > 1) && ((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0))) {
|
|
|
|
fprintf(stderr, "Usage:\t%s [file]\nIf no file is specified, the program is reading the standard input.\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
openlog("testminissdp", LOG_CONS|LOG_PERROR, LOG_USER);
|
|
|
|
|
|
|
|
/* populate lan_addrs */
|
|
|
|
LIST_INIT(&lan_addrs);
|
|
|
|
lan_addr = (struct lan_addr_s *) malloc(sizeof(struct lan_addr_s));
|
|
|
|
memset(lan_addr, 0, sizeof(struct lan_addr_s));
|
|
|
|
LIST_INSERT_HEAD(&lan_addrs, lan_addr, list);
|
|
|
|
|
|
|
|
if(argc > 1) {
|
|
|
|
f = fopen(argv[1], "rb");
|
|
|
|
if(f == NULL) {
|
|
|
|
syslog(LOG_ERR, "error opening file %s", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 16:47:22 +00:00
|
|
|
n = fread(buffer, 1, sizeof(buffer), f ? f : stdin);
|
2017-12-12 09:08:44 +00:00
|
|
|
if(n <= 0) {
|
|
|
|
syslog(LOG_ERR, "error reading");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
test(buffer, n);
|
|
|
|
|
|
|
|
if(f) fclose(f);
|
|
|
|
/* free memory */
|
|
|
|
while(lan_addrs.lh_first != NULL)
|
|
|
|
{
|
|
|
|
lan_addr = lan_addrs.lh_first;
|
|
|
|
LIST_REMOVE(lan_addrs.lh_first, list);
|
|
|
|
free(lan_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|