- updated win32 files / project to properly compile UPNP
This commit is contained in:
parent
628be74fb8
commit
443096d0db
|
@ -503,6 +503,14 @@
|
|||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\minisoap.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\minissdpc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\miniupnpc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\miniwget.c"
|
||||
>
|
||||
|
@ -511,10 +519,6 @@
|
|||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\minixml.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\minixmlvalid.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\common\platform_common.cpp"
|
||||
>
|
||||
|
@ -527,20 +531,12 @@
|
|||
RelativePath="..\..\source\shared_lib\sources\platform\posix\socket.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\testminixml.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\testupnpreplyparse.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\sdl\thread.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\upnpc.c"
|
||||
RelativePath="..\..\source\shared_lib\sources\platform\miniupnpc\upnpcommands.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <io.h>
|
||||
// Warzone additions
|
||||
#include "lib/framework/types.h"
|
||||
|
||||
typedef short int int16_t;
|
||||
typedef unsigned short int uint16_t;
|
||||
|
||||
typedef SSIZE_T ssize_t;
|
||||
// end WZ
|
||||
/* Hack */
|
||||
|
|
|
@ -1,149 +0,0 @@
|
|||
/* $Id: minixmlvalid.c,v 1.2 2006/11/30 11:31:55 nanard Exp $ */
|
||||
/* MiniUPnP Project
|
||||
* http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/
|
||||
* minixmlvalid.c :
|
||||
* validation program for the minixml parser
|
||||
*
|
||||
* (c) 2006 Thomas Bernard */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "minixml.h"
|
||||
|
||||
/* xml event structure */
|
||||
struct event {
|
||||
enum { ELTSTART, ELTEND, ATT, CHARDATA } type;
|
||||
const char * data;
|
||||
int len;
|
||||
};
|
||||
|
||||
struct eventlist {
|
||||
int n;
|
||||
struct event * events;
|
||||
};
|
||||
|
||||
/* compare 2 xml event lists
|
||||
* return 0 if the two lists are equals */
|
||||
int evtlistcmp(struct eventlist * a, struct eventlist * b)
|
||||
{
|
||||
int i;
|
||||
struct event * ae, * be;
|
||||
if(a->n != b->n)
|
||||
return 1;
|
||||
for(i=0; i<a->n; i++)
|
||||
{
|
||||
ae = a->events + i;
|
||||
be = b->events + i;
|
||||
if( (ae->type != be->type)
|
||||
||(ae->len != be->len)
|
||||
||memcmp(ae->data, be->data, ae->len))
|
||||
{
|
||||
printf("Found a difference : %d '%.*s' != %d '%.*s'\n",
|
||||
ae->type, ae->len, ae->data,
|
||||
be->type, be->len, be->data);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Test data */
|
||||
static const char xmldata[] =
|
||||
"<xmlroot>\n"
|
||||
" <elt1 att1=\"attvalue1\" att2=\"attvalue2\">"
|
||||
"character data"
|
||||
"</elt1> \n \t"
|
||||
"<elt1b/>"
|
||||
"<elt2a> \t<elt2b>chardata1</elt2b><elt2b>chardata2</elt2b></elt2a>"
|
||||
"</xmlroot>";
|
||||
|
||||
static const struct event evtref[] =
|
||||
{
|
||||
{ELTSTART, "xmlroot", 7},
|
||||
{ELTSTART, "elt1", 4},
|
||||
/* attributes */
|
||||
{CHARDATA, "character data", 14},
|
||||
{ELTEND, "elt1", 4},
|
||||
{ELTSTART, "elt1b", 5},
|
||||
{ELTSTART, "elt2a", 5},
|
||||
{ELTSTART, "elt2b", 5},
|
||||
{CHARDATA, "chardata1", 9},
|
||||
{ELTEND, "elt2b", 5},
|
||||
{ELTSTART, "elt2b", 5},
|
||||
{CHARDATA, "chardata2", 9},
|
||||
{ELTEND, "elt2b", 5},
|
||||
{ELTEND, "elt2a", 5},
|
||||
{ELTEND, "xmlroot", 7}
|
||||
};
|
||||
|
||||
void startelt(void * data, const char * p, int l)
|
||||
{
|
||||
struct eventlist * evtlist = data;
|
||||
struct event * evt;
|
||||
evt = evtlist->events + evtlist->n;
|
||||
/*printf("startelt : %.*s\n", l, p);*/
|
||||
evt->type = ELTSTART;
|
||||
evt->data = p;
|
||||
evt->len = l;
|
||||
evtlist->n++;
|
||||
}
|
||||
|
||||
void endelt(void * data, const char * p, int l)
|
||||
{
|
||||
struct eventlist * evtlist = data;
|
||||
struct event * evt;
|
||||
evt = evtlist->events + evtlist->n;
|
||||
/*printf("endelt : %.*s\n", l, p);*/
|
||||
evt->type = ELTEND;
|
||||
evt->data = p;
|
||||
evt->len = l;
|
||||
evtlist->n++;
|
||||
}
|
||||
|
||||
void chardata(void * data, const char * p, int l)
|
||||
{
|
||||
struct eventlist * evtlist = data;
|
||||
struct event * evt;
|
||||
evt = evtlist->events + evtlist->n;
|
||||
/*printf("chardata : '%.*s'\n", l, p);*/
|
||||
evt->type = CHARDATA;
|
||||
evt->data = p;
|
||||
evt->len = l;
|
||||
evtlist->n++;
|
||||
}
|
||||
|
||||
int testxmlparser(const char * xml, int size)
|
||||
{
|
||||
int r;
|
||||
struct eventlist evtlist;
|
||||
struct eventlist evtlistref;
|
||||
struct xmlparser parser;
|
||||
evtlist.n = 0;
|
||||
evtlist.events = malloc(sizeof(struct event)*100);
|
||||
memset(&parser, 0, sizeof(parser));
|
||||
parser.xmlstart = xml;
|
||||
parser.xmlsize = size;
|
||||
parser.data = &evtlist;
|
||||
parser.starteltfunc = startelt;
|
||||
parser.endeltfunc = endelt;
|
||||
parser.datafunc = chardata;
|
||||
parsexml(&parser);
|
||||
printf("%d events\n", evtlist.n);
|
||||
/* compare */
|
||||
evtlistref.n = sizeof(evtref)/sizeof(struct event);
|
||||
evtlistref.events = (struct event *)evtref;
|
||||
r = evtlistcmp(&evtlistref, &evtlist);
|
||||
free(evtlist.events);
|
||||
return r;
|
||||
}
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
int r;
|
||||
r = testxmlparser(xmldata, sizeof(xmldata)-1);
|
||||
if(r)
|
||||
printf("minixml validation test failed\n");
|
||||
return r;
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/* $Id: testigddescparse.c,v 1.1 2008/04/23 11:53:45 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* http://miniupnp.free.fr/
|
||||
* Author : Thomas Bernard
|
||||
* Copyright (c) 2008 Thomas Bernard
|
||||
* This software is subject to the conditions detailed in the
|
||||
* LICENCE file provided in this distribution.
|
||||
* */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "igd_desc_parse.h"
|
||||
#include "minixml.h"
|
||||
|
||||
int test_igd_desc_parse(char * buffer, int len)
|
||||
{
|
||||
struct IGDdatas igd;
|
||||
struct xmlparser parser;
|
||||
memset(&igd, 0, sizeof(struct IGDdatas));
|
||||
memset(&parser, 0, sizeof(struct xmlparser));
|
||||
parser.xmlstart = buffer;
|
||||
parser.xmlsize = len;
|
||||
parser.data = &igd;
|
||||
parser.starteltfunc = IGDstartelt;
|
||||
parser.endeltfunc = IGDendelt;
|
||||
parser.datafunc = IGDdata;
|
||||
parsexml(&parser);
|
||||
printIGD(&igd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
FILE * f;
|
||||
char * buffer;
|
||||
int len;
|
||||
int r = 0;
|
||||
if(argc<2) {
|
||||
fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(argv[1], "r");
|
||||
if(!f) {
|
||||
fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
buffer = malloc(len);
|
||||
size_t ret = fread(buffer, 1, len, f);
|
||||
fclose(f);
|
||||
r = test_igd_desc_parse(buffer, len);
|
||||
free(buffer);
|
||||
return r;
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/* $Id: testminixml.c,v 1.6 2006/11/19 22:32:35 nanard Exp $
|
||||
* testminixml.c
|
||||
* test program for the "minixml" functions.
|
||||
* Author : Thomas Bernard.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "minixml.h"
|
||||
#include "igd_desc_parse.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define NO_BZERO
|
||||
#endif
|
||||
|
||||
#ifdef NO_BZERO
|
||||
#define bzero(p, n) memset(p, 0, n)
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void printeltname1(void * d, const char * name, int l)
|
||||
{
|
||||
int i;
|
||||
printf("element ");
|
||||
for(i=0;i<l;i++)
|
||||
putchar(name[i]);
|
||||
}
|
||||
void printeltname2(void * d, const char * name, int l)
|
||||
{
|
||||
int i;
|
||||
putchar('/');
|
||||
for(i=0;i<l;i++)
|
||||
putchar(name[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
void printdata(void *d, const char * data, int l)
|
||||
{
|
||||
int i;
|
||||
printf("data : ");
|
||||
for(i=0;i<l;i++)
|
||||
putchar(data[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
void burptest(const char * buffer, int bufsize)
|
||||
{
|
||||
struct IGDdatas data;
|
||||
struct xmlparser parser;
|
||||
/*objet IGDdatas */
|
||||
bzero(&data, sizeof(struct IGDdatas));
|
||||
/* objet xmlparser */
|
||||
parser.xmlstart = buffer;
|
||||
parser.xmlsize = bufsize;
|
||||
parser.data = &data;
|
||||
/*parser.starteltfunc = printeltname1;
|
||||
parser.endeltfunc = printeltname2;
|
||||
parser.datafunc = printdata; */
|
||||
parser.starteltfunc = IGDstartelt;
|
||||
parser.endeltfunc = IGDendelt;
|
||||
parser.datafunc = IGDdata;
|
||||
parsexml(&parser);
|
||||
printIGD(&data);
|
||||
}
|
||||
|
||||
/* ----- main ---- */
|
||||
#define XML_MAX_SIZE (8192)
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
FILE * f;
|
||||
char buffer[XML_MAX_SIZE];
|
||||
int bufsize;
|
||||
if(argc<2)
|
||||
{
|
||||
printf("usage:\t%s file.xml\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(argv[1], "r");
|
||||
if(!f)
|
||||
{
|
||||
printf("cannot open file %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
bufsize = (int)fread(buffer, 1, XML_MAX_SIZE, f);
|
||||
fclose(f);
|
||||
burptest(buffer, bufsize);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/* $Id: testupnpreplyparse.c,v 1.2 2008/02/21 13:05:27 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2007 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "upnpreplyparse.h"
|
||||
|
||||
void
|
||||
test_parsing(const char * buf, int len)
|
||||
{
|
||||
struct NameValueParserData pdata;
|
||||
ParseNameValue(buf, len, &pdata);
|
||||
ClearNameValueList(&pdata);
|
||||
}
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
FILE * f;
|
||||
char buffer[4096];
|
||||
int l;
|
||||
if(argc<2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(argv[1], "r");
|
||||
if(!f)
|
||||
{
|
||||
fprintf(stderr, "Error : can not open file %s\n", argv[1]);
|
||||
return 2;
|
||||
}
|
||||
l = fread(buffer, 1, sizeof(buffer)-1, f);
|
||||
fclose(f);
|
||||
buffer[l] = '\0';
|
||||
#ifdef DEBUG
|
||||
DisplayNameValueList(buffer, l);
|
||||
#endif
|
||||
test_parsing(buffer, l);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,378 +0,0 @@
|
|||
/* $Id: upnpc.c,v 1.67 2009/08/03 22:58:37 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* Author : Thomas Bernard
|
||||
* Copyright (c) 2005-2009 Thomas Bernard
|
||||
* This software is subject to the conditions detailed in the
|
||||
* LICENCE file provided in this distribution.
|
||||
* */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#include "miniwget.h"
|
||||
#include "miniupnpc.h"
|
||||
#include "upnpcommands.h"
|
||||
#include "upnperrors.h"
|
||||
|
||||
/* protofix() checks if protocol is "UDP" or "TCP"
|
||||
* returns NULL if not */
|
||||
const char * protofix(const char * proto)
|
||||
{
|
||||
static const char proto_tcp[4] = { 'T', 'C', 'P', 0};
|
||||
static const char proto_udp[4] = { 'U', 'D', 'P', 0};
|
||||
int i, b;
|
||||
for(i=0, b=1; i<4; i++)
|
||||
b = b && ( (proto[i] == proto_tcp[i])
|
||||
|| (proto[i] == (proto_tcp[i] | 32)) );
|
||||
if(b)
|
||||
return proto_tcp;
|
||||
for(i=0, b=1; i<4; i++)
|
||||
b = b && ( (proto[i] == proto_udp[i])
|
||||
|| (proto[i] == (proto_udp[i] | 32)) );
|
||||
if(b)
|
||||
return proto_udp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void DisplayInfos(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data)
|
||||
{
|
||||
char externalIPAddress[16];
|
||||
char connectionType[64];
|
||||
char status[64];
|
||||
char lastconnerr[64];
|
||||
unsigned int uptime;
|
||||
unsigned int brUp, brDown;
|
||||
int r;
|
||||
UPNP_GetConnectionTypeInfo(urls->controlURL,
|
||||
data->servicetype,
|
||||
connectionType);
|
||||
if(connectionType[0])
|
||||
printf("Connection Type : %s\n", connectionType);
|
||||
else
|
||||
printf("GetConnectionTypeInfo failed.\n");
|
||||
UPNP_GetStatusInfo(urls->controlURL, data->servicetype,
|
||||
status, &uptime, lastconnerr);
|
||||
printf("Status : %s, uptime=%u, LastConnectionError : %s\n",
|
||||
status, uptime, lastconnerr);
|
||||
UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->servicetype_CIF,
|
||||
&brDown, &brUp);
|
||||
printf("MaxBitRateDown : %u bps MaxBitRateUp %u bps\n", brDown, brUp);
|
||||
r = UPNP_GetExternalIPAddress(urls->controlURL,
|
||||
data->servicetype,
|
||||
externalIPAddress);
|
||||
if(r != UPNPCOMMAND_SUCCESS)
|
||||
printf("GetExternalIPAddress() returned %d\n", r);
|
||||
if(externalIPAddress[0])
|
||||
printf("ExternalIPAddress = %s\n", externalIPAddress);
|
||||
else
|
||||
printf("GetExternalIPAddress failed.\n");
|
||||
}
|
||||
|
||||
static void GetConnectionStatus(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data)
|
||||
{
|
||||
unsigned int bytessent, bytesreceived, packetsreceived, packetssent;
|
||||
DisplayInfos(urls, data);
|
||||
bytessent = UPNP_GetTotalBytesSent(urls->controlURL_CIF, data->servicetype_CIF);
|
||||
bytesreceived = UPNP_GetTotalBytesReceived(urls->controlURL_CIF, data->servicetype_CIF);
|
||||
packetssent = UPNP_GetTotalPacketsSent(urls->controlURL_CIF, data->servicetype_CIF);
|
||||
packetsreceived = UPNP_GetTotalPacketsReceived(urls->controlURL_CIF, data->servicetype_CIF);
|
||||
printf("Bytes: Sent: %8u\tRecv: %8u\n", bytessent, bytesreceived);
|
||||
printf("Packets: Sent: %8u\tRecv: %8u\n", packetssent, packetsreceived);
|
||||
}
|
||||
|
||||
static void ListRedirections(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data)
|
||||
{
|
||||
int r;
|
||||
int i = 0;
|
||||
char index[6];
|
||||
char intClient[16];
|
||||
char intPort[6];
|
||||
char extPort[6];
|
||||
char protocol[4];
|
||||
char desc[80];
|
||||
char enabled[6];
|
||||
char rHost[64];
|
||||
char duration[16];
|
||||
/*unsigned int num=0;
|
||||
UPNP_GetPortMappingNumberOfEntries(urls->controlURL, data->servicetype, &num);
|
||||
printf("PortMappingNumberOfEntries : %u\n", num);*/
|
||||
do {
|
||||
snprintf(index, 6, "%d", i);
|
||||
rHost[0] = '\0'; enabled[0] = '\0';
|
||||
duration[0] = '\0'; desc[0] = '\0';
|
||||
extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0';
|
||||
r = UPNP_GetGenericPortMappingEntry(urls->controlURL, data->servicetype,
|
||||
index,
|
||||
extPort, intClient, intPort,
|
||||
protocol, desc, enabled,
|
||||
rHost, duration);
|
||||
if(r==0)
|
||||
/*
|
||||
printf("%02d - %s %s->%s:%s\tenabled=%s leaseDuration=%s\n"
|
||||
" desc='%s' rHost='%s'\n",
|
||||
i, protocol, extPort, intClient, intPort,
|
||||
enabled, duration,
|
||||
desc, rHost);
|
||||
*/
|
||||
printf("%2d %s %5s->%s:%-5s '%s' '%s'\n",
|
||||
i, protocol, extPort, intClient, intPort,
|
||||
desc, rHost);
|
||||
else
|
||||
printf("GetGenericPortMappingEntry() returned %d (%s)\n",
|
||||
r, strupnperror(r));
|
||||
i++;
|
||||
} while(r==0);
|
||||
}
|
||||
|
||||
/* Test function
|
||||
* 1 - get connection type
|
||||
* 2 - get extenal ip address
|
||||
* 3 - Add port mapping
|
||||
* 4 - get this port mapping from the IGD */
|
||||
static void SetRedirectAndTest(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data,
|
||||
const char * iaddr,
|
||||
const char * iport,
|
||||
const char * eport,
|
||||
const char * proto)
|
||||
{
|
||||
char externalIPAddress[16];
|
||||
char intClient[16];
|
||||
char intPort[6];
|
||||
int r;
|
||||
|
||||
if(!iaddr || !iport || !eport || !proto)
|
||||
{
|
||||
fprintf(stderr, "Wrong arguments\n");
|
||||
return;
|
||||
}
|
||||
proto = protofix(proto);
|
||||
if(!proto)
|
||||
{
|
||||
fprintf(stderr, "invalid protocol\n");
|
||||
return;
|
||||
}
|
||||
|
||||
UPNP_GetExternalIPAddress(urls->controlURL,
|
||||
data->servicetype,
|
||||
externalIPAddress);
|
||||
if(externalIPAddress[0])
|
||||
printf("ExternalIPAddress = %s\n", externalIPAddress);
|
||||
else
|
||||
printf("GetExternalIPAddress failed.\n");
|
||||
|
||||
r = UPNP_AddPortMapping(urls->controlURL, data->servicetype,
|
||||
eport, iport, iaddr, 0, proto, 0);
|
||||
if(r!=UPNPCOMMAND_SUCCESS)
|
||||
printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
|
||||
eport, iport, iaddr, r, strupnperror(r));
|
||||
|
||||
r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
|
||||
data->servicetype,
|
||||
eport, proto,
|
||||
intClient, intPort);
|
||||
if(r!=UPNPCOMMAND_SUCCESS)
|
||||
printf("GetSpecificPortMappingEntry() failed with code %d (%s)\n",
|
||||
r, strupnperror(r));
|
||||
|
||||
if(intClient[0]) {
|
||||
printf("InternalIP:Port = %s:%s\n", intClient, intPort);
|
||||
printf("external %s:%s %s is redirected to internal %s:%s\n",
|
||||
externalIPAddress, eport, proto, intClient, intPort);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
RemoveRedirect(struct UPNPUrls * urls,
|
||||
struct IGDdatas * data,
|
||||
const char * eport,
|
||||
const char * proto)
|
||||
{
|
||||
int r;
|
||||
if(!proto || !eport)
|
||||
{
|
||||
fprintf(stderr, "invalid arguments\n");
|
||||
return;
|
||||
}
|
||||
proto = protofix(proto);
|
||||
if(!proto)
|
||||
{
|
||||
fprintf(stderr, "protocol invalid\n");
|
||||
return;
|
||||
}
|
||||
r = UPNP_DeletePortMapping(urls->controlURL, data->servicetype, eport, proto, 0);
|
||||
printf("UPNP_DeletePortMapping() returned : %d\n", r);
|
||||
}
|
||||
|
||||
|
||||
/* sample upnp client program */
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
char command = 0;
|
||||
char ** commandargv = 0;
|
||||
int commandargc = 0;
|
||||
struct UPNPDev * devlist = 0;
|
||||
char lanaddr[16]; /* my ip address on the LAN */
|
||||
int i;
|
||||
const char * rootdescurl = 0;
|
||||
const char * multicastif = 0;
|
||||
const char * minissdpdpath = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
WSADATA wsaData;
|
||||
int nResult = WSAStartup(MAKEWORD(2,2), &wsaData);
|
||||
if(nResult != NO_ERROR)
|
||||
{
|
||||
fprintf(stderr, "WSAStartup() failed.\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
printf("upnpc : miniupnpc library test client. (c) 2006-2009 Thomas Bernard\n");
|
||||
printf("Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/\n"
|
||||
"for more information.\n");
|
||||
/* command line processing */
|
||||
for(i=1; i<argc; i++)
|
||||
{
|
||||
if(argv[i][0] == '-')
|
||||
{
|
||||
if(argv[i][1] == 'u')
|
||||
rootdescurl = argv[++i];
|
||||
else if(argv[i][1] == 'm')
|
||||
multicastif = argv[++i];
|
||||
else if(argv[i][1] == 'p')
|
||||
minissdpdpath = argv[++i];
|
||||
else
|
||||
{
|
||||
command = argv[i][1];
|
||||
i++;
|
||||
commandargv = argv + i;
|
||||
commandargc = argc - i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "option '%s' invalid\n", argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!command || (command == 'a' && commandargc<4)
|
||||
|| (command == 'd' && argc<2)
|
||||
|| (command == 'r' && argc<2))
|
||||
{
|
||||
fprintf(stderr, "Usage :\t%s [options] -a ip port external_port protocol\n\t\tAdd port redirection\n", argv[0]);
|
||||
fprintf(stderr, " \t%s [options] -d external_port protocol [port2 protocol2] [...]\n\t\tDelete port redirection\n", argv[0]);
|
||||
fprintf(stderr, " \t%s [options] -s\n\t\tGet Connection status\n", argv[0]);
|
||||
fprintf(stderr, " \t%s [options] -l\n\t\tList redirections\n", argv[0]);
|
||||
fprintf(stderr, " \t%s [options] -r port1 protocol1 [port2 protocol2] [...]\n\t\tAdd all redirections to the current host\n", argv[0]);
|
||||
fprintf(stderr, "\nprotocol is UDP or TCP\n");
|
||||
fprintf(stderr, "Options:\n");
|
||||
fprintf(stderr, " -u url : bypass discovery process by providing the XML root description url.\n");
|
||||
fprintf(stderr, " -m address : provide ip address of the interface to use for sending SSDP multicast packets.\n");
|
||||
fprintf(stderr, " -p path : use this path for MiniSSDPd socket.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( rootdescurl
|
||||
|| (devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0)))
|
||||
{
|
||||
struct UPNPDev * device;
|
||||
struct UPNPUrls urls;
|
||||
struct IGDdatas data;
|
||||
if(devlist)
|
||||
{
|
||||
printf("List of UPNP devices found on the network :\n");
|
||||
for(device = devlist; device; device = device->pNext)
|
||||
{
|
||||
printf(" desc: %s\n st: %s\n\n",
|
||||
device->descURL, device->st);
|
||||
}
|
||||
}
|
||||
i = 1;
|
||||
if( (rootdescurl && UPNP_GetIGDFromUrl(rootdescurl, &urls, &data, lanaddr, sizeof(lanaddr)))
|
||||
|| (i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr))))
|
||||
{
|
||||
switch(i) {
|
||||
case 1:
|
||||
printf("Found valid IGD : %s\n", urls.controlURL);
|
||||
break;
|
||||
case 2:
|
||||
printf("Found a (not connected?) IGD : %s\n", urls.controlURL);
|
||||
printf("Trying to continue anyway\n");
|
||||
break;
|
||||
case 3:
|
||||
printf("UPnP device found. Is it an IGD ? : %s\n", urls.controlURL);
|
||||
printf("Trying to continue anyway\n");
|
||||
break;
|
||||
default:
|
||||
printf("Found device (igd ?) : %s\n", urls.controlURL);
|
||||
printf("Trying to continue anyway\n");
|
||||
}
|
||||
printf("Local LAN ip address : %s\n", lanaddr);
|
||||
#if 0
|
||||
printf("getting \"%s\"\n", urls.ipcondescURL);
|
||||
descXML = miniwget(urls.ipcondescURL, &descXMLsize);
|
||||
if(descXML)
|
||||
{
|
||||
/*fwrite(descXML, 1, descXMLsize, stdout);*/
|
||||
free(descXML); descXML = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch(command)
|
||||
{
|
||||
case 'l':
|
||||
DisplayInfos(&urls, &data);
|
||||
ListRedirections(&urls, &data);
|
||||
break;
|
||||
case 'a':
|
||||
SetRedirectAndTest(&urls, &data,
|
||||
commandargv[0], commandargv[1],
|
||||
commandargv[2], commandargv[3]);
|
||||
break;
|
||||
case 'd':
|
||||
for(i=0; i<commandargc; i+=2)
|
||||
{
|
||||
RemoveRedirect(&urls, &data, commandargv[i], commandargv[i+1]);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
GetConnectionStatus(&urls, &data);
|
||||
break;
|
||||
case 'r':
|
||||
for(i=0; i<commandargc; i+=2)
|
||||
{
|
||||
/*printf("port %s protocol %s\n", argv[i], argv[i+1]);*/
|
||||
SetRedirectAndTest(&urls, &data,
|
||||
lanaddr, commandargv[i],
|
||||
commandargv[i], commandargv[i+1]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown switch -%c\n", command);
|
||||
}
|
||||
|
||||
FreeUPNPUrls(&urls);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "No valid UPNP Internet Gateway Device found.\n");
|
||||
}
|
||||
freeUPNPDevlist(devlist); devlist = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "No IGD UPnP Device found on the network !\n");
|
||||
}
|
||||
|
||||
/*puts("************* HOP ***************");*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue