Fix (some) Windows compiler warnings

This commit is contained in:
Joseph Henry
2020-04-20 23:50:21 -07:00
parent 925ee3a144
commit 894d3bf415
7 changed files with 28 additions and 22 deletions

View File

@@ -555,7 +555,7 @@ ZT_SOCKET_API int ZTCALL zts_core_running();
* @usage Call this after zts_start(), zts_startjoin() and/or zts_join()
* @return Number of networks joined by this node
*/
ZT_SOCKET_API int ZTCALL zts_get_num_joined_networks();
ZT_SOCKET_API size_t ZTCALL zts_get_num_joined_networks();
/**
* @brief Populates a structure with details for a given network
@@ -749,7 +749,7 @@ ZT_SOCKET_API int zts_get_peer_count();
* @usage Call this after zts_start() has succeeded
* @return
*/
ZT_SOCKET_API int zts_get_peers(struct zts_peer_details *pds, int *num);
ZT_SOCKET_API int zts_get_peers(struct zts_peer_details *pds, unsigned int *num);
/**
* @brief Return details of a given peer.

View File

@@ -298,8 +298,8 @@ void *_zts_run_callbacks(void *thread_id)
while (_run_callbacks || _callbackMsgQueue.size_approx() > 0)
{
struct zts_callback_msg *msg;
int sz = _callbackMsgQueue.size_approx();
for (int j = 0; j < sz; j++) {
size_t sz = _callbackMsgQueue.size_approx();
for (size_t j = 0; j < sz; j++) {
if (_callbackMsgQueue.try_dequeue(msg)) {
_process_callback_event(msg);
delete msg;
@@ -695,7 +695,6 @@ JNIEXPORT void JNICALL Java_com_zerotier_libzt_ZeroTier_restart(
int zts_free()
{
Mutex::Lock _l(_service_lock);
int retval = 0;
if (_freeHasBeenCalled) {
return ZTS_ERR_INVALID_OP;
}
@@ -735,6 +734,7 @@ int zts_get_6plane_addr(struct sockaddr_storage *addr, const uint64_t nwid, cons
InetAddress _6planeAddr = InetAddress::makeIpv66plane(nwid,nodeId);
struct sockaddr_in6 *in6 = (struct sockaddr_in6*)addr;
memcpy(in6->sin6_addr.s6_addr, _6planeAddr.rawIpData(), sizeof(struct in6_addr));
return ZTS_ERR_OK;
}
int zts_get_rfc4193_addr(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId)
@@ -745,6 +745,7 @@ int zts_get_rfc4193_addr(struct sockaddr_storage *addr, const uint64_t nwid, con
InetAddress _rfc4193Addr = InetAddress::makeIpv6rfc4193(nwid,nodeId);
struct sockaddr_in6 *in6 = (struct sockaddr_in6*)addr;
memcpy(in6->sin6_addr.s6_addr, _rfc4193Addr.rawIpData(), sizeof(struct in6_addr));
return ZTS_ERR_OK;
}
uint64_t zts_generate_adhoc_nwid_from_range(uint16_t startPortOfRange, uint16_t endPortOfRange)
@@ -774,7 +775,7 @@ JNIEXPORT jlong JNICALL Java_com_zerotier_libzt_ZeroTier_get_1peer_1count(
}
#endif
int zts_get_peers(struct zts_peer_details *pds, int *num)
int zts_get_peers(struct zts_peer_details *pds, unsigned int *num)
{
Mutex::Lock _l(_service_lock);
if (!pds || !num) {
@@ -792,7 +793,7 @@ int zts_get_peers(struct zts_peer_details *pds, int *num)
*num = pl->peerCount;
for(unsigned long i=0;i<pl->peerCount;++i) {
memcpy(&(pds[i]), &(pl->peers[i]), sizeof(struct zts_peer_details));
for (int j=0; j<pl->peers[i].pathCount; j++) {
for (unsigned int j=0; j<pl->peers[i].pathCount; j++) {
memcpy(&(pds[i].paths[j].address),
&(pl->peers[i].paths[j].address), sizeof(struct sockaddr_storage));
}
@@ -819,7 +820,7 @@ int zts_get_peer(struct zts_peer_details *pd, uint64_t peerId)
for(unsigned long i=0;i<pl->peerCount;++i) {
if (pl->peers[i].address == peerId) {
memcpy(pd, &(pl->peers[i]), sizeof(struct zts_peer_details));
for (int j=0; j<pl->peers[i].pathCount; j++) {
for (unsigned int j=0; j<pl->peers[i].pathCount; j++) {
memcpy(&(pd->paths[j].address),
&(pl->peers[i].paths[j].address), sizeof(struct sockaddr_storage));
}
@@ -838,10 +839,9 @@ int zts_get_peer(struct zts_peer_details *pd, uint64_t peerId)
// Networks //
//////////////////////////////////////////////////////////////////////////////
int zts_get_num_joined_networks()
size_t zts_get_num_joined_networks()
{
Mutex::Lock _l(_service_lock);
int retval = ZTS_ERR_OK;
if (!_zts_can_perform_service_operation()) {
return ZTS_ERR_SERVICE;
}

View File

@@ -439,11 +439,9 @@ public:
_lastRestart = clockShouldBe;
int64_t lastTapMulticastGroupCheck = 0;
int64_t lastBindRefresh = 0;
int64_t lastUpdateCheck = clockShouldBe;
int64_t lastMultipathModeUpdate = 0;
int64_t lastCleanedPeersDb = 0;
int64_t lastLocalInterfaceAddressCheck = (clockShouldBe - ZT_LOCAL_INTERFACE_CHECK_INTERVAL) + 15000; // do this in 15s to give portmapper time to configure and other things time to settle
int64_t lastLocalConfFileCheck = OSUtils::now();
for(;;) {
_run_m.lock();
if (!_run) {
@@ -891,12 +889,12 @@ public:
}
// Previously known peer, update status
else {
if (peerCache[pl->peers[i].address] == 0 && pl->peers[i].pathCount > 0) {
if ((peerCache[pl->peers[i].address] == false) && pl->peers[i].pathCount > 0) {
pd = new zts_peer_details;
memcpy(pd, &(pl->peers[i]), sizeof(struct zts_peer_details));
postEvent(ZTS_EVENT_PEER_P2P, (void*)pd);
}
if (peerCache[pl->peers[i].address] > 0 && pl->peers[i].pathCount == 0) {
if ((peerCache[pl->peers[i].address] == true) && pl->peers[i].pathCount == 0) {
pd = new zts_peer_details;
memcpy(pd, &(pl->peers[i]), sizeof(struct zts_peer_details));
postEvent(ZTS_EVENT_PEER_RELAY, (void*)pd);
@@ -909,7 +907,7 @@ public:
_node->freeQueryResult((void *)pl);
}
inline int networkCount()
inline size_t networkCount()
{
Mutex::Lock _l(_nets_m);
return _nets.size();
@@ -974,6 +972,9 @@ public:
OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "%.16llx.conf",dirname,(unsigned long long)id[0]);
secure = true;
}
else {
return;
}
break;
case ZT_STATE_OBJECT_PEER:
if (_peer_caching_enabled) {
@@ -1034,6 +1035,9 @@ public:
if (_network_caching_enabled) {
OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "networks.d" ZT_PATH_SEPARATOR_S "%.16llx.conf",_homePath.c_str(),(unsigned long long)id[0]);
}
else {
return -1;
}
break;
case ZT_STATE_OBJECT_PEER:
if (_peer_caching_enabled) {

View File

@@ -152,7 +152,7 @@ public:
*/
virtual void getRoutes(uint64_t nwid, void *routeArray, unsigned int *numRoutes) = 0;
virtual int networkCount() = 0;
virtual size_t networkCount() = 0;
virtual void leaveAll() = 0;
virtual void join(uint64_t nwid) = 0;
virtual void leave(uint64_t nwid) = 0;

View File

@@ -156,7 +156,7 @@ bool VirtualTap::addIp(const InetAddress &ip)
return false;
}
if (std::find(_ips.begin(),_ips.end(),ip) == _ips.end()) {
lwip_init_interface((void*)this, this->_mac, ip);
lwip_init_interface((void*)this, ip);
// TODO: Add ZTS_EVENT_ADDR_NEW ?
_ips.push_back(ip);
// Send callback message

View File

@@ -36,7 +36,10 @@
#include "lwip/ip_addr.h"
#include "lwip/nd6.h"
#include "lwip/netifapi.h"
#ifdef LWIP_STATS
#include "lwip/stats.h"
#endif
#include "VirtualTap.hpp"
#include "lwipDriver.hpp"
@@ -143,7 +146,7 @@ void lwip_driver_init()
#if defined(_WIN32)
sys_init(); // Required for win32 init of critical sections
#endif
void *st = (void*)sys_thread_new(ZTS_LWIP_DRIVER_THREAD_NAME, main_lwip_driver_loop,
sys_thread_new(ZTS_LWIP_DRIVER_THREAD_NAME, main_lwip_driver_loop,
NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
}
@@ -255,7 +258,7 @@ void lwip_eth_rx(VirtualTap *tap, const MAC &from, const MAC &to, unsigned int e
*/
}
p = pbuf_alloc(PBUF_RAW, len+sizeof(struct eth_hdr), PBUF_RAM);
p = pbuf_alloc(PBUF_RAW, (uint16_t)len+sizeof(struct eth_hdr), PBUF_RAM);
if (!p) {
DEBUG_ERROR("dropped packet: unable to allocate memory for pbuf");
return;
@@ -461,7 +464,7 @@ static err_t netif_init6(struct netif *n)
return ERR_OK;
}
void lwip_init_interface(void *tapref, const MAC &mac, const InetAddress &ip)
void lwip_init_interface(void *tapref, const InetAddress &ip)
{
char ipbuf[INET6_ADDRSTRLEN];
char macbuf[ZTS_MAC_ADDRSTRLEN];

View File

@@ -138,11 +138,10 @@ static void netif_link_callback(struct netif *netif);
*
* @param
* @param tapref Reference to VirtualTap that will be responsible for sending and receiving data
* @param mac Virtual hardware address for this ZeroTier VirtualTap interface
* @param ip Virtual IP address for this ZeroTier VirtualTap interface
* @return
*/
void lwip_init_interface(void *tapref, const MAC &mac, const InetAddress &ip);
void lwip_init_interface(void *tapref, const InetAddress &ip);
/**
* @brief Called from the stack, outbound ethernet frames from the network stack enter the ZeroTier virtual wire here.