From 96c672aef59ac785f3d351698311bb358820cc3c Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 2 Nov 2016 14:34:33 +0000 Subject: 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. --- toxcore/LAN_discovery.c | 4 ++-- toxcore/TCP_client.c | 8 ++++---- toxcore/TCP_server.c | 14 +++++++------- toxcore/network.c | 16 ++++++++-------- 4 files changed, 21 insertions(+), 21 deletions(-) (limited to 'toxcore') diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index d2bfb4e1..48e0e7bb 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -50,7 +50,7 @@ static void fetch_broadcast_info(uint16_t port) { 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); if (pAdapterInfo == NULL) { @@ -59,7 +59,7 @@ static void fetch_broadcast_info(uint16_t port) if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { free(pAdapterInfo); - pAdapterInfo = malloc(ulOutBufLen); + pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen); if (pAdapterInfo == NULL) { return; diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index ba8aeabe..caa1b73d 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -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; - 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) { return -1; @@ -302,7 +302,7 @@ static int send_pending_data(TCP_Client_Connection *con) while (p) { 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 > 0) { @@ -397,7 +397,7 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const } 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) { 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); } - len = send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL); + len = send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL); if (len <= 0) { return 0; diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 5a5a55be..4b355a62 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -251,7 +251,7 @@ uint16_t read_TCP_length(sock_t sock) if (count >= sizeof(uint16_t)) { 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)) { 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); if (count >= length) { - int len = recv(sock, data, length, MSG_NOSIGNAL); + int len = recv(sock, (char *)data, length, MSG_NOSIGNAL); if (len != length) { 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; - 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) { return -1; @@ -378,7 +378,7 @@ static int send_pending_data(TCP_Secure_Connection *con) while (p) { 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 > 0) { @@ -462,7 +462,7 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const } 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) { 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); } - len = send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL); + len = send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL); if (len <= 0) { return 0; @@ -574,7 +574,7 @@ static int handle_TCP_handshake(TCP_Secure_Connection *con, const uint8_t *data, 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; } diff --git a/toxcore/network.c b/toxcore/network.c index 386f8c16..31e8fd8b 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -170,7 +170,7 @@ int set_socket_nosigpipe(sock_t sock) { #if defined(__MACH__) 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 return 1; #endif @@ -184,7 +184,7 @@ int set_socket_nosigpipe(sock_t sock) int set_socket_reuseaddr(sock_t sock) { 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) @@ -196,14 +196,14 @@ int set_socket_dualstack(sock_t sock) { int ipv6only = 0; 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)) { return 1; } 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. */ int n = 1024 * 1024 * 2; - setsockopt(temp->sock, SOL_SOCKET, SO_RCVBUF, (char *)&n, sizeof(n)); - setsockopt(temp->sock, SOL_SOCKET, SO_SNDBUF, (char *)&n, sizeof(n)); + setsockopt(temp->sock, SOL_SOCKET, SO_RCVBUF, (const char *)&n, sizeof(n)); + setsockopt(temp->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&n, sizeof(n)); /* Enable broadcast on socket */ 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 */ 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[15] = 0x01; 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)" : "Local multicast group FF02::1 joined successfully", errno, strerror(errno)); -- cgit v1.2.3