-/* $Id: natpmp.c,v 1.4 2007/12/02 00:12:47 nanard Exp $ */
+/* $Id: natpmp.c,v 1.6 2008/04/28 02:58:34 nanard Exp $ */
/* libnatpmp
- * Copyright (c) 2007, Thomas BERNARD <miniupnp@free.fr>
+ * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr>
+ * http://miniupnp.free.fr/libnatpmp.html
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
-#include <errno.h>
#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <time.h>
#include <sys/time.h>
+#ifdef WIN32
+#include <winsock2.h>
+#include <Ws2tcpip.h>
+#include <io.h>
+#else
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
+#endif
#include "natpmp.h"
#include "getgateway.h"
return n;
}
+#ifdef ENABLE_STRNATPMPERR
+const char * strnatpmperr(int r)
+{
+ const char * s;
+ switch(r) {
+ case NATPMP_ERR_INVALIDARGS:
+ s = "invalid arguments";
+ break;
+ case NATPMP_ERR_SOCKETERROR:
+ s = "socket() failed";
+ break;
+ case NATPMP_ERR_CANNOTGETGATEWAY:
+ s = "cannot get default gateway ip address";
+ break;
+ case NATPMP_ERR_CLOSEERR:
+ s = "close() failed";
+ break;
+ case NATPMP_ERR_RECVFROM:
+ s = "recvfrom() failed";
+ break;
+ case NATPMP_ERR_NOPENDINGREQ:
+ s = "no pending request";
+ break;
+ case NATPMP_ERR_NOGATEWAYSUPPORT:
+ s = "the gateway does not support nat-pmp";
+ break;
+ case NATPMP_ERR_CONNECTERR:
+ s = "connect() failed";
+ break;
+ case NATPMP_ERR_WRONGPACKETSOURCE:
+ s = "packet not received from the default gateway";
+ break;
+ case NATPMP_ERR_SENDERR:
+ s = "send() failed";
+ break;
+ case NATPMP_ERR_FCNTLERROR:
+ s = "fcntl() failed";
+ break;
+ case NATPMP_ERR_GETTIMEOFDAYERR:
+ s = "gettimeofday() failed";
+ break;
+ case NATPMP_ERR_UNSUPPORTEDVERSION:
+ s = "unsupported nat-pmp version error from server";
+ break;
+ case NATPMP_ERR_UNSUPPORTEDOPCODE:
+ s = "unsupported nat-pmp opcode error from server";
+ break;
+ case NATPMP_ERR_UNDEFINEDERROR:
+ s = "undefined nat-pmp server error";
+ break;
+ case NATPMP_ERR_NOTAUTHORIZED:
+ s = "not authorized";
+ break;
+ case NATPMP_ERR_NETWORKFAILURE:
+ s = "network failure";
+ break;
+ case NATPMP_ERR_OUTOFRESOURCES:
+ s = "nat-pmp server out of resources";
+ break;
+ default:
+ s = "Unknown libnatpmp error";
+ }
+ return s;
+}
+#endif
+
-/* $Id: igd_desc_parse.c,v 1.7 2006/11/19 22:32:33 nanard Exp $ */
+/* $Id: igd_desc_parse.c,v 1.8 2008/04/23 11:51:06 nanard Exp $ */
/* Project : miniupnp
* http://miniupnp.free.fr/
* Author : Thomas Bernard
- * Copyright (c) 2005 Thomas Bernard
+ * Copyright (c) 2005-2008 Thomas Bernard
* This software is subject to the conditions detailed in the
* LICENCE file provided in this distribution.
* */
#include <stdio.h>
#include <string.h>
+/* TODO : rewrite this code so it correctly handle descriptions with
+ * both WANIPConnection and/or WANPPPConnection */
+
/* Start element handler :
* update nesting level counter and copy element name */
void IGDstartelt(void * d, const char * name, int l)
memcpy( datas->cureltname, name, l);
datas->cureltname[l] = '\0';
datas->level++;
+ if( (l==7) && !memcmp(name, "service", l) ) {
+ datas->controlurl_tmp[0] = '\0';
+ datas->eventsuburl_tmp[0] = '\0';
+ datas->scpdurl_tmp[0] = '\0';
+ datas->servicetype_tmp[0] = '\0';
+ }
}
/* End element handler :
/*printf("endelt %2d %.*s\n", datas->level, l, name);*/
if( (l==7) && !memcmp(name, "service", l) )
{
- /*datas->state++; */
/*
if( datas->state < 1
&& !strcmp(datas->servicetype,
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
datas->state ++;
*/
- if(0==strcmp(datas->servicetype_CIF,
- "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
- datas->state = 2;
- if(0==strcmp(datas->servicetype,
- "urn:schemas-upnp-org:service:WANIPConnection:1") )
- datas->state = 3;
-/* if(0==strcmp(datas->servicetype,
- "urn:schemas-upnp-org:service:WANPPPConnection:1") )
- datas->state = 4; */
+ if(0==strcmp(datas->servicetype_tmp,
+ "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) {
+ memcpy(datas->controlurl_CIF, datas->controlurl_tmp, MINIUPNPC_URL_MAXSIZE);
+ memcpy(datas->eventsuburl_CIF, datas->eventsuburl_tmp, MINIUPNPC_URL_MAXSIZE);
+ memcpy(datas->scpdurl_CIF, datas->scpdurl_tmp, MINIUPNPC_URL_MAXSIZE);
+ memcpy(datas->servicetype_CIF, datas->servicetype_tmp, MINIUPNPC_URL_MAXSIZE);
+ } else if(0==strcmp(datas->servicetype_tmp,
+ "urn:schemas-upnp-org:service:WANIPConnection:1")
+ || 0==strcmp(datas->servicetype_tmp,
+ "urn:schemas-upnp-org:service:WANPPPConnection:1") ) {
+ memcpy(datas->controlurl, datas->controlurl_tmp, MINIUPNPC_URL_MAXSIZE);
+ memcpy(datas->eventsuburl, datas->eventsuburl_tmp, MINIUPNPC_URL_MAXSIZE);
+ memcpy(datas->scpdurl, datas->scpdurl_tmp, MINIUPNPC_URL_MAXSIZE);
+ memcpy(datas->servicetype, datas->servicetype_tmp, MINIUPNPC_URL_MAXSIZE);
+ }
}
}
datas->level, datas->cureltname, l, data); */
if( !strcmp(datas->cureltname, "URLBase") )
dstmember = datas->urlbase;
- else if(datas->state<=1)
- {
- if( !strcmp(datas->cureltname, "serviceType") )
- dstmember = datas->servicetype_CIF;
- else if( !strcmp(datas->cureltname, "controlURL") )
- dstmember = datas->controlurl_CIF;
- else if( !strcmp(datas->cureltname, "eventSubURL") )
- dstmember = datas->eventsuburl_CIF;
- else if( !strcmp(datas->cureltname, "SCPDURL") )
- dstmember = datas->scpdurl_CIF;
- else if( !strcmp(datas->cureltname, "deviceType") )
- dstmember = datas->devicetype_CIF;
- }
- else if(datas->state==2)
- {
- if( !strcmp(datas->cureltname, "serviceType") )
- dstmember = datas->servicetype;
- else if( !strcmp(datas->cureltname, "controlURL") )
- dstmember = datas->controlurl;
- else if( !strcmp(datas->cureltname, "eventSubURL") )
- dstmember = datas->eventsuburl;
- else if( !strcmp(datas->cureltname, "SCPDURL") )
- dstmember = datas->scpdurl;
- else if( !strcmp(datas->cureltname, "deviceType") )
- dstmember = datas->devicetype;
- }
+ else if( !strcmp(datas->cureltname, "serviceType") )
+ dstmember = datas->servicetype_tmp;
+ else if( !strcmp(datas->cureltname, "controlURL") )
+ dstmember = datas->controlurl_tmp;
+ else if( !strcmp(datas->cureltname, "eventSubURL") )
+ dstmember = datas->eventsuburl_tmp;
+ else if( !strcmp(datas->cureltname, "SCPDURL") )
+ dstmember = datas->scpdurl_tmp;
+/* else if( !strcmp(datas->cureltname, "deviceType") )
+ dstmember = datas->devicetype_tmp;*/
if(dstmember)
{
if(l>=MINIUPNPC_URL_MAXSIZE)
{
printf("urlbase = %s\n", d->urlbase);
printf("WAN Device (Common interface config) :\n");
- printf(" deviceType = %s\n", d->devicetype_CIF);
+ /*printf(" deviceType = %s\n", d->devicetype_CIF);*/
printf(" serviceType = %s\n", d->servicetype_CIF);
printf(" controlURL = %s\n", d->controlurl_CIF);
printf(" eventSubURL = %s\n", d->eventsuburl_CIF);
printf(" SCPDURL = %s\n", d->scpdurl_CIF);
- printf("WAN Connection Device :\n");
- printf(" deviceType = %s\n", d->devicetype);
+ printf("WAN Connection Device (IP or PPP Connection):\n");
+ /*printf(" deviceType = %s\n", d->devicetype);*/
printf(" servicetype = %s\n", d->servicetype);
printf(" controlURL = %s\n", d->controlurl);
printf(" eventSubURL = %s\n", d->eventsuburl);
-/* $Id: igd_desc_parse.h,v 1.5 2007/04/11 15:21:09 nanard Exp $ */
+/* $Id: igd_desc_parse.h,v 1.6 2008/04/23 11:51:07 nanard Exp $ */
/* Project : miniupnp
* http://miniupnp.free.fr/
* Author : Thomas Bernard
- * Copyright (c) 2005 Thomas Bernard
+ * Copyright (c) 2005-2008 Thomas Bernard
* This software is subject to the conditions detailed in the
* LICENCE file provided in this distribution.
* */
char cureltname[MINIUPNPC_URL_MAXSIZE];
char urlbase[MINIUPNPC_URL_MAXSIZE];
int level;
- int state;
+ /*int state;*/
+ /* "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" */
char controlurl_CIF[MINIUPNPC_URL_MAXSIZE];
char eventsuburl_CIF[MINIUPNPC_URL_MAXSIZE];
char scpdurl_CIF[MINIUPNPC_URL_MAXSIZE];
char servicetype_CIF[MINIUPNPC_URL_MAXSIZE];
- char devicetype_CIF[MINIUPNPC_URL_MAXSIZE];
+ /*char devicetype_CIF[MINIUPNPC_URL_MAXSIZE];*/
+ /* "urn:schemas-upnp-org:service:WANIPConnection:1"
+ * "urn:schemas-upnp-org:service:WANPPPConnection:1" */
char controlurl[MINIUPNPC_URL_MAXSIZE];
char eventsuburl[MINIUPNPC_URL_MAXSIZE];
char scpdurl[MINIUPNPC_URL_MAXSIZE];
char servicetype[MINIUPNPC_URL_MAXSIZE];
- char devicetype[MINIUPNPC_URL_MAXSIZE];
+ /*char devicetype[MINIUPNPC_URL_MAXSIZE];*/
+ /* tmp */
+ char controlurl_tmp[MINIUPNPC_URL_MAXSIZE];
+ char eventsuburl_tmp[MINIUPNPC_URL_MAXSIZE];
+ char scpdurl_tmp[MINIUPNPC_URL_MAXSIZE];
+ char servicetype_tmp[MINIUPNPC_URL_MAXSIZE];
+ /*char devicetype_tmp[MINIUPNPC_URL_MAXSIZE];*/
};
void IGDstartelt(void *, const char *, int);