Skip to content

Commit

Permalink
sync with mozilla version
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Tatrai committed Jan 29, 2014
1 parent 3dd47e9 commit 9732fb4
Show file tree
Hide file tree
Showing 42 changed files with 3,082 additions and 2,969 deletions.
345 changes: 177 additions & 168 deletions libpcp/include/pcp.h

Large diffs are not rendered by default.

45 changes: 22 additions & 23 deletions libpcp/src/default_config.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/*
* Copyright (c) 2013 by Cisco Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. 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.
*
* 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.
*
Copyright (c) 2014 by Cisco Systems, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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.
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.
*/

#ifndef DEFAULT_CONFIG_H_
Expand Down
82 changes: 38 additions & 44 deletions libpcp/src/net/findsaddr-udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include "findsaddr.h"
#include "unp.h"


/*
* Return the source address for the given destination address.
*
Expand All @@ -69,97 +68,92 @@
#define INVALID_SOCKET -1
#endif

const char *
findsaddr(register const struct sockaddr_in *to,
struct in6_addr *from)
const char *findsaddr(register const struct sockaddr_in *to,
struct in6_addr *from)
{
const char *errstr;
struct sockaddr_in cto, cfrom;
SOCKET s;
socklen_t len;

s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == INVALID_SOCKET) //LCOV_EXCL_START
s=socket(AF_INET, SOCK_DGRAM, 0);
if (s == INVALID_SOCKET)
return ("failed to open DGRAM socket for src addr selection.");
//LCOV_EXCL_STOP
errstr = NULL;
len = sizeof(struct sockaddr_in);
errstr=NULL;
len=sizeof(struct sockaddr_in);
memcpy(&cto, to, len);
cto.sin_port = htons(65535); /* Dummy port for connect(2). */
cto.sin_port=htons(65535); /* Dummy port for connect(2). */
if (connect(s, (struct sockaddr *)&cto, len) == -1) {
errstr = "failed to connect to peer for src addr selection."; //LCOV_EXCL_START
errstr="failed to connect to peer for src addr selection.";
goto err;
}//LCOV_EXCL_STOP
}

if (getsockname(s, (struct sockaddr *)&cfrom, &len) == -1) {
errstr = "failed to get socket name for src addr selection."; //LCOV_EXCL_START
errstr="failed to get socket name for src addr selection.";
goto err;
} //LCOV_EXCL_STOP
}

if (len != sizeof(struct sockaddr_in) || cfrom.sin_family != AF_INET) {//LCOV_EXCL_START
errstr = "unexpected address family in src addr selection.";
if (len != sizeof(struct sockaddr_in) || cfrom.sin_family != AF_INET) {
errstr="unexpected address family in src addr selection.";
goto err;
}//LCOV_EXCL_STOP
}

((uint32_t*)from)[0]=0;
((uint32_t*)from)[1]=0;
((uint32_t*)from)[2]=htonl(0xffff);
((uint32_t*)from)[3]=cfrom.sin_addr.s_addr;
((uint32_t *)from)[0]=0;
((uint32_t *)from)[1]=0;
((uint32_t *)from)[2]=htonl(0xffff);
((uint32_t *)from)[3]=cfrom.sin_addr.s_addr;

err:
(void) CLOSE(s);
(void)CLOSE(s);

/* No error (string) to return. */
return (errstr);
}

const char *
findsaddr6(register const struct sockaddr_in6 *to,
register struct in6_addr *from)
const char *findsaddr6(register const struct sockaddr_in6 *to,
register struct in6_addr *from)
{
const char *errstr;
struct sockaddr_in6 cto, cfrom;
SOCKET s;
socklen_t len;
uint32_t sock_flg=0;

if(IN6_IS_ADDR_LOOPBACK(&to->sin6_addr)) {
if (IN6_IS_ADDR_LOOPBACK(&to->sin6_addr)) {
memcpy(from, &to->sin6_addr, sizeof(struct in6_addr));
return NULL;
}

s = socket(AF_INET6, SOCK_DGRAM, 0);
if (s == INVALID_SOCKET) //LCOV_EXCL_START
s=socket(AF_INET6, SOCK_DGRAM, 0);
if (s == INVALID_SOCKET)
return ("failed to open DGRAM socket for src addr selection.");
//LCOV_EXCL_STOP

errstr = NULL;
errstr=NULL;

//Enable Dual-stack socket for Vista and higher
if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&sock_flg,
sizeof(sock_flg))==-1) {
errstr = "setsockopt failed to set dual stack mode."; //LCOV_EXCL_START
if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&sock_flg,
sizeof(sock_flg)) == -1) {
errstr="setsockopt failed to set dual stack mode.";
goto err;
} //LCOV_EXCL_STOP
}

len = sizeof(struct sockaddr_in6);
len=sizeof(struct sockaddr_in6);
memcpy(&cto, to, len);
cto.sin6_port = htons(65535); /* Dummy port for connect(2). */
cto.sin6_port=htons(65535); /* Dummy port for connect(2). */
if (connect(s, (struct sockaddr *)&cto, len) == -1) {
errstr = "failed to connect to peer for src addr selection."; //LCOV_EXCL_START
errstr="failed to connect to peer for src addr selection.";
goto err;
} //LCOV_EXCL_STOP
}

if (getsockname(s, (struct sockaddr *)&cfrom, &len) == -1) {
errstr = "failed to get socket name for src addr selection."; //LCOV_EXCL_START
errstr="failed to get socket name for src addr selection.";
goto err;
} //LCOV_EXCL_STOP

}

if (len != sizeof(struct sockaddr_in6) || cfrom.sin6_family != AF_INET6) {//LCOV_EXCL_START
errstr = "unexpected address family in src addr selection.";
if (len != sizeof(struct sockaddr_in6) || cfrom.sin6_family != AF_INET6) {
errstr="unexpected address family in src addr selection.";
goto err;
} //LCOV_EXCL_STOP
}

memcpy(from->s6_addr, cfrom.sin6_addr.s6_addr, sizeof(struct in6_addr));

Expand Down
57 changes: 26 additions & 31 deletions libpcp/src/net/findsaddr.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
/*
* Copyright (c) 2013 by Cisco Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. 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.
*
* 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.
*/
Copyright (c) 2014 by Cisco Systems, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
#ifndef FINDSADDR_UDP_H_
#define FINDSADDR_UDP_H_
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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.
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.
*/

const char *
findsaddr(register const struct sockaddr_in *to,
struct in6_addr *from);
#ifndef FINDSADDR_UDP_H_
#define FINDSADDR_UDP_H_

const char *
findsaddr6(register const struct sockaddr_in6 *to,
register struct in6_addr *from);
const char *findsaddr(register const struct sockaddr_in *to,
struct in6_addr *from);

const char *findsaddr6(register const struct sockaddr_in6 *to,
register struct in6_addr *from);

#endif //FINDSADDR_UDP_H_
Loading

0 comments on commit 9732fb4

Please sign in to comment.