summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/LibNATPMP/src/libnatpmp/natpmp.c')
-rw-r--r--3rdParty/LibNATPMP/src/libnatpmp/natpmp.c69
1 files changed, 49 insertions, 20 deletions
diff --git a/3rdParty/LibNATPMP/src/libnatpmp/natpmp.c b/3rdParty/LibNATPMP/src/libnatpmp/natpmp.c
index 53869c3..a09f217 100644
--- a/3rdParty/LibNATPMP/src/libnatpmp/natpmp.c
+++ b/3rdParty/LibNATPMP/src/libnatpmp/natpmp.c
@@ -1,19 +1,31 @@
-/* $Id: natpmp.c,v 1.13 2011/01/03 17:31:03 nanard Exp $ */
+/* $Id: natpmp.c,v 1.18 2013/11/26 08:47:36 nanard Exp $ */
/* libnatpmp
- * Copyright (c) 2007-2011, 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
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * 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. */
+Copyright (c) 2007-2013, Thomas BERNARD
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+*/
#ifdef __linux__
#define _BSD_SOURCE 1
#endif
@@ -30,6 +42,7 @@
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ECONNREFUSED WSAECONNREFUSED
#include "wingettimeofday.h"
+#define gettimeofday natpmp_gettimeofday
#else
#include <errno.h>
#include <unistd.h>
@@ -40,13 +53,14 @@
#endif
#include "natpmp.h"
#include "getgateway.h"
+#include <stdio.h>
LIBSPEC int initnatpmp(natpmp_t * p, int forcegw, in_addr_t forcedgw)
{
#ifdef WIN32
u_long ioctlArg = 1;
#else
- int flags;
+ int flags;
#endif
struct sockaddr_in addr;
if(!p)
@@ -71,7 +85,7 @@ LIBSPEC int initnatpmp(natpmp_t * p, int forcegw, in_addr_t forcedgw)
if(getdefaultgateway(&(p->gateway)) < 0)
return NATPMP_ERR_CANNOTGETGATEWAY;
}
-
+
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(NATPMP_PORT);
@@ -164,9 +178,20 @@ LIBSPEC int sendnewportmappingrequest(natpmp_t * p, int protocol,
p->pending_request[1] = protocol;
p->pending_request[2] = 0;
p->pending_request[3] = 0;
- *((uint16_t *)(p->pending_request + 4)) = htons(privateport);
- *((uint16_t *)(p->pending_request + 6)) = htons(publicport);
- *((uint32_t *)(p->pending_request + 8)) = htonl(lifetime);
+ /* break strict-aliasing rules :
+ *((uint16_t *)(p->pending_request + 4)) = htons(privateport); */
+ p->pending_request[4] = (privateport >> 8) & 0xff;
+ p->pending_request[5] = privateport & 0xff;
+ /* break stric-aliasing rules :
+ *((uint16_t *)(p->pending_request + 6)) = htons(publicport); */
+ p->pending_request[6] = (publicport >> 8) & 0xff;
+ p->pending_request[7] = publicport & 0xff;
+ /* break stric-aliasing rules :
+ *((uint32_t *)(p->pending_request + 8)) = htonl(lifetime); */
+ p->pending_request[8] = (lifetime >> 24) & 0xff;
+ p->pending_request[9] = (lifetime >> 16) & 0xff;
+ p->pending_request[10] = (lifetime >> 8) & 0xff;
+ p->pending_request[11] = lifetime & 0xff;
p->pending_request_len = 12;
return sendnatpmprequest(p);
}
@@ -182,7 +207,11 @@ LIBSPEC int readnatpmpresponse(natpmp_t * p, natpmpresp_t * response)
n = recvfrom(p->s, buf, sizeof(buf), 0,
(struct sockaddr *)&addr, &addrlen);
if(n<0)
+#ifdef WIN32
+ switch(WSAGetLastError()) {
+#else
switch(errno) {
+#endif
/*case EAGAIN:*/
case EWOULDBLOCK:
n = NATPMP_TRYAGAIN;