Compile as C++ for windows builds.

Compiling as C++ changes nothing semantically, but ensures that we don't
break C++ compatibility while also retaining C compatibility.

C++ compatibility is useful for tooling and additional diagnostics and
analyses.
This commit is contained in:
iphydf 2016-11-02 14:34:33 +00:00
parent e2d63e0497
commit 96c672aef5
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
14 changed files with 53 additions and 38 deletions

View File

@ -32,6 +32,7 @@ if(DEBUG)
check_c_compiler_flag("-g3" HAVE_G3) check_c_compiler_flag("-g3" HAVE_G3)
if(HAVE_G3) if(HAVE_G3)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
endif() endif()
endif() endif()
@ -56,6 +57,7 @@ if(ASAN)
check_c_compiler_flag("-fsanitize=address" HAVE_ASAN) check_c_compiler_flag("-fsanitize=address" HAVE_ASAN)
if(HAVE_ASAN) if(HAVE_ASAN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif() endif()
set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}") set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}")
endif() endif()

View File

@ -63,13 +63,14 @@ START_TEST(test_basic)
TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES); TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES);
ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES), ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES),
"Encrypt failed."); "Encrypt failed.");
ck_assert_msg(send(sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, "send Failed."); ck_assert_msg(send(sock, (const char *)handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
"send Failed.");
c_sleep(50); c_sleep(50);
do_TCP_server(tcp_s); do_TCP_server(tcp_s);
c_sleep(50); c_sleep(50);
do_TCP_server(tcp_s); do_TCP_server(tcp_s);
c_sleep(50); c_sleep(50);
ck_assert_msg(send(sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, 0) == 1, "send Failed."); ck_assert_msg(send(sock, (const char *)(handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1)), 1, 0) == 1, "send Failed.");
c_sleep(50); c_sleep(50);
do_TCP_server(tcp_s); do_TCP_server(tcp_s);
c_sleep(50); c_sleep(50);
@ -77,7 +78,7 @@ START_TEST(test_basic)
c_sleep(50); c_sleep(50);
uint8_t response[TCP_SERVER_HANDSHAKE_SIZE]; uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE]; uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE];
ck_assert_msg(recv(sock, response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed."); ck_assert_msg(recv(sock, (char *)response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed.");
ret = decrypt_data(self_public_key, f_secret_key, response, response + crypto_box_NONCEBYTES, ret = decrypt_data(self_public_key, f_secret_key, response, response + crypto_box_NONCEBYTES,
TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain); TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain);
ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed."); ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed.");
@ -97,8 +98,8 @@ START_TEST(test_basic)
uint32_t i; uint32_t i;
for (i = 0; i < sizeof(r_req); ++i) { for (i = 0; i < sizeof(r_req); ++i) {
ck_assert_msg(send(sock, r_req + i, 1, 0) == 1, "send Failed."); ck_assert_msg(send(sock, (const char *)(r_req + i), 1, 0) == 1, "send Failed.");
//ck_assert_msg(send(sock, r_req, sizeof(r_req), 0) == sizeof(r_req), "send Failed."); //ck_assert_msg(send(sock, (const char *)r_req, sizeof(r_req), 0) == sizeof(r_req), "send Failed.");
do_TCP_server(tcp_s); do_TCP_server(tcp_s);
c_sleep(50); c_sleep(50);
} }
@ -106,7 +107,7 @@ START_TEST(test_basic)
do_TCP_server(tcp_s); do_TCP_server(tcp_s);
c_sleep(50); c_sleep(50);
uint8_t packet_resp[4096]; uint8_t packet_resp[4096];
int recv_data_len = recv(sock, packet_resp, 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, 0); int recv_data_len = recv(sock, (char *)packet_resp, 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, 0);
ck_assert_msg(recv_data_len == 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, ck_assert_msg(recv_data_len == 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES,
"recv Failed. %u", recv_data_len); "recv Failed. %u", recv_data_len);
memcpy(&size, packet_resp, 2); memcpy(&size, packet_resp, 2);
@ -158,15 +159,16 @@ static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s)
TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES); TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES);
ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES), ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES),
"Encrypt failed."); "Encrypt failed.");
ck_assert_msg(send(sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, "send Failed."); ck_assert_msg(send(sock, (const char *)handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
"send Failed.");
do_TCP_server(tcp_s); do_TCP_server(tcp_s);
c_sleep(50); c_sleep(50);
ck_assert_msg(send(sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, 0) == 1, "send Failed."); ck_assert_msg(send(sock, (const char *)(handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1)), 1, 0) == 1, "send Failed.");
c_sleep(50); c_sleep(50);
do_TCP_server(tcp_s); do_TCP_server(tcp_s);
uint8_t response[TCP_SERVER_HANDSHAKE_SIZE]; uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE]; uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE];
ck_assert_msg(recv(sock, response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed."); ck_assert_msg(recv(sock, (char *)response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed.");
ret = decrypt_data(tcp_server_public_key(tcp_s), f_secret_key, response, response + crypto_box_NONCEBYTES, ret = decrypt_data(tcp_server_public_key(tcp_s), f_secret_key, response, response + crypto_box_NONCEBYTES,
TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain); TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain);
ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed."); ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed.");
@ -196,13 +198,13 @@ static int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *
increment_nonce(con->sent_nonce); increment_nonce(con->sent_nonce);
ck_assert_msg(send(con->sock, packet, sizeof(packet), 0) == sizeof(packet), "send failed"); ck_assert_msg(send(con->sock, (const char *)packet, sizeof(packet), 0) == sizeof(packet), "send failed");
return 0; return 0;
} }
static int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t length) static int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t length)
{ {
int len = recv(con->sock, data, length, 0); int len = recv(con->sock, (char *)data, length, 0);
ck_assert_msg(len == length, "wrong len %i\n", len); ck_assert_msg(len == length, "wrong len %i\n", len);
len = decrypt_data_symmetric(con->shared_key, con->recv_nonce, data + 2, length - 2, data); len = decrypt_data_symmetric(con->shared_key, con->recv_nonce, data + 2, length - 2, data);
ck_assert_msg(len != -1, "Decrypt failed"); ck_assert_msg(len != -1, "Decrypt failed");

View File

@ -6,10 +6,10 @@
#endif #endif
#include <check.h> #include <check.h>
#include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <inttypes.h>
#include "../toxcore/tox.h" #include "../toxcore/tox.h"
#include "../toxcore/util.h" #include "../toxcore/util.h"

View File

@ -8,6 +8,7 @@
#include <check.h> #include <check.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include "../toxcore/tox.h" #include "../toxcore/tox.h"
#include "../toxcore/util.h" #include "../toxcore/util.h"

View File

@ -8,6 +8,7 @@
#include <check.h> #include <check.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include "../toxcore/tox.h" #include "../toxcore/tox.h"
#include "../toxcore/util.h" #include "../toxcore/util.h"

View File

@ -7,6 +7,7 @@
#include <check.h> #include <check.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include "../toxcore/tox.h" #include "../toxcore/tox.h"
#include "../toxcore/util.h" #include "../toxcore/util.h"

View File

@ -17,6 +17,7 @@
#include <check.h> #include <check.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include "../toxcore/tox.h" #include "../toxcore/tox.h"
#include "../toxcore/util.h" #include "../toxcore/util.h"

View File

@ -4,7 +4,12 @@ option(COMPILE_AS_CXX "Compile all C code as C++ code" OFF)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
function(set_source_language) if(COMPILE_AS_CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_LIMIT_MACROS=1")
endif()
macro(set_source_language)
if(COMPILE_AS_CXX) if(COMPILE_AS_CXX)
foreach(srcfile ${ARGN}) foreach(srcfile ${ARGN})
get_filename_component(srcext ${srcfile} EXT) get_filename_component(srcext ${srcfile} EXT)
@ -13,10 +18,11 @@ function(set_source_language)
endif() endif()
endforeach() endforeach()
endif() endif()
endfunction() endmacro()
function(add_c_executable exec) function(add_c_executable exec)
set_source_language(${ARGN}) set_source_language(${ARGN})
add_executable(${exec} ${ARGN}) add_executable(${exec} ${ARGN})
endfunction() endfunction()
@ -26,6 +32,7 @@ function(pkg_use_module mod)
link_directories(${${mod}_LIBRARY_DIRS}) link_directories(${${mod}_LIBRARY_DIRS})
include_directories(${${mod}_INCLUDE_DIRS}) include_directories(${${mod}_INCLUDE_DIRS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}")
endif() endif()
endfunction() endfunction()

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
CMAKE=$ARCH-w64-mingw32.shared-cmake CMAKE=$ARCH-w64-mingw32.shared-cmake
CMAKE_EXTRA_FLAGS="-DBOOTSTRAP_DAEMON=OFF" CMAKE_EXTRA_FLAGS="-DBOOTSTRAP_DAEMON=OFF -DCOMPILE_AS_CXX=ON"
NPROC=`nproc` NPROC=`nproc`
CURDIR=/work CURDIR=/work

View File

@ -98,12 +98,12 @@ int main(int argc, char *argv[])
uint8_t id = rand(); uint8_t id = rand();
uint32_t p_len = create_packet(packet, string, strlen((char *)string), id); uint32_t p_len = create_packet(packet, string, strlen((char *)string), id);
if (sendto(sock, (char *) packet, p_len, 0, (struct sockaddr *)&target, addrsize) != p_len) { if (sendto(sock, (char *)packet, p_len, 0, (struct sockaddr *)&target, addrsize) != p_len) {
return -1; return -1;
} }
uint8_t buffer[512] = {0}; uint8_t buffer[512] = {0};
int r_len = recv(sock, buffer, sizeof(buffer), 0); int r_len = recv(sock, (char *)buffer, sizeof(buffer), 0);
if (r_len < (int)p_len) { if (r_len < (int)p_len) {
return -1; return -1;

View File

@ -50,7 +50,7 @@ static void fetch_broadcast_info(uint16_t port)
{ {
broadcast_count = 0; broadcast_count = 0;
IP_ADAPTER_INFO *pAdapterInfo = malloc(sizeof(IP_ADAPTER_INFO)); IP_ADAPTER_INFO *pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO); unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO);
if (pAdapterInfo == NULL) { if (pAdapterInfo == NULL) {
@ -59,7 +59,7 @@ static void fetch_broadcast_info(uint16_t port)
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
free(pAdapterInfo); free(pAdapterInfo);
pAdapterInfo = malloc(ulOutBufLen); pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen);
if (pAdapterInfo == NULL) { if (pAdapterInfo == NULL) {
return; return;

View File

@ -272,7 +272,7 @@ static int send_pending_data_nonpriority(TCP_Client_Connection *con)
} }
uint16_t left = con->last_packet_length - con->last_packet_sent; uint16_t left = con->last_packet_length - con->last_packet_sent;
int len = send(con->sock, con->last_packet + con->last_packet_sent, left, MSG_NOSIGNAL); int len = send(con->sock, (const char *)(con->last_packet + con->last_packet_sent), left, MSG_NOSIGNAL);
if (len <= 0) { if (len <= 0) {
return -1; return -1;
@ -302,7 +302,7 @@ static int send_pending_data(TCP_Client_Connection *con)
while (p) { while (p) {
uint16_t left = p->size - p->sent; uint16_t left = p->size - p->sent;
int len = send(con->sock, p->data + p->sent, left, MSG_NOSIGNAL); int len = send(con->sock, (const char *)(p->data + p->sent), left, MSG_NOSIGNAL);
if (len != left) { if (len != left) {
if (len > 0) { if (len > 0) {
@ -397,7 +397,7 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const
} }
if (priority) { if (priority) {
len = sendpriority ? send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL) : 0; len = sendpriority ? send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL) : 0;
if (len <= 0) { if (len <= 0) {
len = 0; len = 0;
@ -412,7 +412,7 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const
return add_priority(con, packet, sizeof(packet), len); return add_priority(con, packet, sizeof(packet), len);
} }
len = send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL); len = send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL);
if (len <= 0) { if (len <= 0) {
return 0; return 0;

View File

@ -251,7 +251,7 @@ uint16_t read_TCP_length(sock_t sock)
if (count >= sizeof(uint16_t)) { if (count >= sizeof(uint16_t)) {
uint16_t length; uint16_t length;
int len = recv(sock, (uint8_t *)&length, sizeof(uint16_t), MSG_NOSIGNAL); int len = recv(sock, (char *)&length, sizeof(uint16_t), MSG_NOSIGNAL);
if (len != sizeof(uint16_t)) { if (len != sizeof(uint16_t)) {
fprintf(stderr, "FAIL recv packet\n"); fprintf(stderr, "FAIL recv packet\n");
@ -280,7 +280,7 @@ int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length)
unsigned int count = TCP_socket_data_recv_buffer(sock); unsigned int count = TCP_socket_data_recv_buffer(sock);
if (count >= length) { if (count >= length) {
int len = recv(sock, data, length, MSG_NOSIGNAL); int len = recv(sock, (char *)data, length, MSG_NOSIGNAL);
if (len != length) { if (len != length) {
fprintf(stderr, "FAIL recv packet\n"); fprintf(stderr, "FAIL recv packet\n");
@ -348,7 +348,7 @@ static int send_pending_data_nonpriority(TCP_Secure_Connection *con)
} }
uint16_t left = con->last_packet_length - con->last_packet_sent; uint16_t left = con->last_packet_length - con->last_packet_sent;
int len = send(con->sock, con->last_packet + con->last_packet_sent, left, MSG_NOSIGNAL); int len = send(con->sock, (const char *)(con->last_packet + con->last_packet_sent), left, MSG_NOSIGNAL);
if (len <= 0) { if (len <= 0) {
return -1; return -1;
@ -378,7 +378,7 @@ static int send_pending_data(TCP_Secure_Connection *con)
while (p) { while (p) {
uint16_t left = p->size - p->sent; uint16_t left = p->size - p->sent;
int len = send(con->sock, p->data + p->sent, left, MSG_NOSIGNAL); int len = send(con->sock, (const char *)(p->data + p->sent), left, MSG_NOSIGNAL);
if (len != left) { if (len != left) {
if (len > 0) { if (len > 0) {
@ -462,7 +462,7 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const
} }
if (priority) { if (priority) {
len = sendpriority ? send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL) : 0; len = sendpriority ? send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL) : 0;
if (len <= 0) { if (len <= 0) {
len = 0; len = 0;
@ -477,7 +477,7 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const
return add_priority(con, packet, sizeof(packet), len); return add_priority(con, packet, sizeof(packet), len);
} }
len = send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL); len = send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL);
if (len <= 0) { if (len <= 0) {
return 0; return 0;
@ -574,7 +574,7 @@ static int handle_TCP_handshake(TCP_Secure_Connection *con, const uint8_t *data,
return -1; return -1;
} }
if (TCP_SERVER_HANDSHAKE_SIZE != send(con->sock, response, TCP_SERVER_HANDSHAKE_SIZE, MSG_NOSIGNAL)) { if (TCP_SERVER_HANDSHAKE_SIZE != send(con->sock, (const char *)response, TCP_SERVER_HANDSHAKE_SIZE, MSG_NOSIGNAL)) {
return -1; return -1;
} }

View File

@ -170,7 +170,7 @@ int set_socket_nosigpipe(sock_t sock)
{ {
#if defined(__MACH__) #if defined(__MACH__)
int set = 1; int set = 1;
return (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)) == 0); return (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (const char *)&set, sizeof(int)) == 0);
#else #else
return 1; return 1;
#endif #endif
@ -184,7 +184,7 @@ int set_socket_nosigpipe(sock_t sock)
int set_socket_reuseaddr(sock_t sock) int set_socket_reuseaddr(sock_t sock)
{ {
int set = 1; int set = 1;
return (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&set, sizeof(set)) == 0); return (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&set, sizeof(set)) == 0);
} }
/* Set socket to dual (IPv4 + IPv6 socket) /* Set socket to dual (IPv4 + IPv6 socket)
@ -196,14 +196,14 @@ int set_socket_dualstack(sock_t sock)
{ {
int ipv6only = 0; int ipv6only = 0;
socklen_t optsize = sizeof(ipv6only); socklen_t optsize = sizeof(ipv6only);
int res = getsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&ipv6only, &optsize); int res = getsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, &optsize);
if ((res == 0) && (ipv6only == 0)) { if ((res == 0) && (ipv6only == 0)) {
return 1; return 1;
} }
ipv6only = 0; ipv6only = 0;
return (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&ipv6only, sizeof(ipv6only)) == 0); return (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&ipv6only, sizeof(ipv6only)) == 0);
} }
@ -588,12 +588,12 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
/* Functions to increase the size of the send and receive UDP buffers. /* Functions to increase the size of the send and receive UDP buffers.
*/ */
int n = 1024 * 1024 * 2; int n = 1024 * 1024 * 2;
setsockopt(temp->sock, SOL_SOCKET, SO_RCVBUF, (char *)&n, sizeof(n)); setsockopt(temp->sock, SOL_SOCKET, SO_RCVBUF, (const char *)&n, sizeof(n));
setsockopt(temp->sock, SOL_SOCKET, SO_SNDBUF, (char *)&n, sizeof(n)); setsockopt(temp->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&n, sizeof(n));
/* Enable broadcast on socket */ /* Enable broadcast on socket */
int broadcast = 1; int broadcast = 1;
setsockopt(temp->sock, SOL_SOCKET, SO_BROADCAST, (char *)&broadcast, sizeof(broadcast)); setsockopt(temp->sock, SOL_SOCKET, SO_BROADCAST, (const char *)&broadcast, sizeof(broadcast));
/* iOS UDP sockets are weird and apparently can SIGPIPE */ /* iOS UDP sockets are weird and apparently can SIGPIPE */
if (!set_socket_nosigpipe(temp->sock)) { if (!set_socket_nosigpipe(temp->sock)) {
@ -659,7 +659,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
mreq.ipv6mr_multiaddr.s6_addr[ 1] = 0x02; mreq.ipv6mr_multiaddr.s6_addr[ 1] = 0x02;
mreq.ipv6mr_multiaddr.s6_addr[15] = 0x01; mreq.ipv6mr_multiaddr.s6_addr[15] = 0x01;
mreq.ipv6mr_interface = 0; mreq.ipv6mr_interface = 0;
int res = setsockopt(temp->sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq)); int res = setsockopt(temp->sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (const char *)&mreq, sizeof(mreq));
LOGGER_DEBUG(log, res < 0 ? "Failed to activate local multicast membership. (%u, %s)" : LOGGER_DEBUG(log, res < 0 ? "Failed to activate local multicast membership. (%u, %s)" :
"Local multicast group FF02::1 joined successfully", errno, strerror(errno)); "Local multicast group FF02::1 joined successfully", errno, strerror(errno));