diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index b0f460f..beabf39 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -7,7 +7,7 @@ else() endif() -cmake_minimum_required( VERSION 2.8.3 ) +cmake_minimum_required( VERSION 3.5 ) project( CIPster ) @@ -112,7 +112,8 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) # enable clock_gettime: add_definitions( -D_POSIX_C_SOURCE=199309L ) endif() - +elseif (MSVC) + add_definitions( -D_CRT_SECURE_NO_WARNINGS ) endif() add_subdirectory( src ) diff --git a/source/src/byte_bufs.h b/source/src/byte_bufs.h index deb1c05..e9903b2 100644 --- a/source/src/byte_bufs.h +++ b/source/src/byte_bufs.h @@ -6,6 +6,7 @@ #ifndef BYTE_BUFS_H_ #define BYTE_BUFS_H_ +#include // for uint8_t, uint16_t, uint32_t, uint64_t #include #include // for the convenience of clients of these classes, which throw @@ -33,7 +34,7 @@ class ByteBuf uint8_t* data() const { return start; } uint8_t* end() const { return limit; } - ssize_t size() const { return limit - start; } // ssize_t is signed + uint16_t size() const { return limit - start; } // uint16_t is signed protected: uint8_t* start; @@ -72,7 +73,7 @@ class BufWriter /// Return the unused size of the buffer, the remaining capacity which is empty. /// A negative value would indicate an overrun, but that also indicates a bug in /// in this class because protections are everywhere to prevent overruns. - ssize_t capacity() const { return limit - start; } + uint16_t capacity() const { return limit - start; } /// Advance the start of the buffer by the specified number of bytes and trim /// the capacity(). @@ -174,7 +175,7 @@ class BufReader /// in the buffer. /// A negative value would indicate an overrun, but that also indicates a bug in /// in this class because protections are everywhere to prevent overruns. - ssize_t size() const { return limit - start; } + uint16_t size() const { return limit - start; } /// Advance the start of the buffer by the specified number of bytes and trim /// the size(). diff --git a/source/src/cip/cipassembly.cc b/source/src/cip/cipassembly.cc index d9755d8..43843c5 100644 --- a/source/src/cip/cipassembly.cc +++ b/source/src/cip/cipassembly.cc @@ -29,7 +29,7 @@ EipStatus AssemblyInstance::RecvData( CipConn* aConn, BufReader aBuffer ) (!aConn->ConsumingNCP().IsFixed() && SizeBytes() < aBuffer.size()) ) { CIPSTER_TRACE_ERR( - "%s: wrong data amount: %zd bytes arrived for assembly id: %d\n", + "%s: wrong data amount: %d bytes arrived for assembly id: %d\n", __func__, aBuffer.size(), Id() ); return kEipStatusError; } diff --git a/source/src/cip/cipconnection.cc b/source/src/cip/cipconnection.cc index a814303..d9456c7 100644 --- a/source/src/cip/cipconnection.cc +++ b/source/src/cip/cipconnection.cc @@ -1231,7 +1231,11 @@ void CipConn::GeneralConfiguration( ConnectionData* aConnData, ConnInstanceType // "expected_packet_rate x connection_timeout_multiplier". Initial value // is called a "pre-consumption" timeout value. if( RxTimeoutUSecs() ) +#ifdef _MSC_VER + SetInactivityWatchDogTimerUSecs(max(RxTimeoutUSecs(), 10000000u)); +#else SetInactivityWatchDogTimerUSecs( std::max( RxTimeoutUSecs(), 10000000u ) ); +#endif else { // this is not an erro diff --git a/source/src/cip/cipconnectionmanager.cc b/source/src/cip/cipconnectionmanager.cc index 5ab75c7..dd6e20b 100644 --- a/source/src/cip/cipconnectionmanager.cc +++ b/source/src/cip/cipconnectionmanager.cc @@ -81,7 +81,7 @@ EipStatus CipConnMgrClass::RecvConnectedData( UdpSocket* aSocket, if( cpfd.DataType() == kCpfIdConnectedDataItem ) { CIPSTER_TRACE_INFO( - "%s[%d]@%u CID:0x%08x len:%-3zd src:%s:%d seq:%d\n", + "%s[%d]@%u CID:0x%08x len:%-3d src:%s:%d seq:%d\n", __func__, aSocket->h(), CurrentUSecs32(), cpfd.AddrConnId(), aCommand.size(), diff --git a/source/src/cip/cipepath.h b/source/src/cip/cipepath.h index 0422249..7ab53f0 100644 --- a/source/src/cip/cipepath.h +++ b/source/src/cip/cipepath.h @@ -128,6 +128,11 @@ class CipAppPath : public SegmentGroup tag[0] = 0; } + CipAppPath(const CipAppPath &rhs) + { + *this = rhs; + } + CipAppPath( int aClassId, int aInstanceId, int aAttributeId = 0 ) { tag[0] = 0; diff --git a/source/src/cip/cipmessagerouter.h b/source/src/cip/cipmessagerouter.h index 7158b97..7c19617 100644 --- a/source/src/cip/cipmessagerouter.h +++ b/source/src/cip/cipmessagerouter.h @@ -171,7 +171,7 @@ class CipMessageRouterResponse : public Serializeable CIPSTER_TRACE_INFO( " additional_status[%d]:0x%x\n", i, additional_status[i] ); } - CIPSTER_TRACE_INFO( " msg len:%zd\n", Reader().size() ); + CIPSTER_TRACE_INFO( " msg len:%d\n", Reader().size() ); } /// Return a BufReader holding the received Serialize()d CIP reply minus diff --git a/source/src/enet_encap/encap.cc b/source/src/enet_encap/encap.cc index 59823bd..ec84e62 100644 --- a/source/src/enet_encap/encap.cc +++ b/source/src/enet_encap/encap.cc @@ -416,8 +416,11 @@ static int disposeOfLargePacket( int aSocket, unsigned aCount ) while( aCount ) { // toss in chunks. +#ifdef _MSC_VER + int readz = min(aCount, unsigned(sizeof chunk)); +#else int readz = std::min( aCount, unsigned( sizeof chunk ) ); - +#endif int num_read = Encapsulation::EnsuredTcpRecv( aSocket, chunk, readz ); if( num_read != readz ) diff --git a/source/src/enet_encap/networkhandler.cc b/source/src/enet_encap/networkhandler.cc index 0e85263..0583e79 100644 --- a/source/src/enet_encap/networkhandler.cc +++ b/source/src/enet_encap/networkhandler.cc @@ -660,7 +660,11 @@ EipStatus NetworkHandlerInitialize() } { - SockAddr address( kEIP_Reserved_Port, INADDR_BROADCAST ); +#if defined(_WIN32) + SockAddr address(kEIP_Reserved_Port, INADDR_ANY); +#else + SockAddr address( kEIP_Reserved_Port, INADDR_BROADCAST); +#endif if( bind( s_sockets.udp_global_broadcast_listener, address, SADDRZ ) ) { @@ -671,6 +675,7 @@ EipStatus NetworkHandlerInitialize() } } +#if !defined(_WIN32) //-------------------------------------------- // create a new UDP socket s_sockets.udp_local_broadcast_listener = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); @@ -703,6 +708,7 @@ EipStatus NetworkHandlerInitialize() goto error; } } +#endif //--------------------------------------------------- // create a new UDP socket @@ -748,7 +754,7 @@ EipStatus NetworkHandlerInitialize() // add the listener socket to the master set master_set_add( "TCP", s_sockets.tcp_listener ); master_set_add( "UDP", s_sockets.udp_unicast_listener ); - master_set_add( "UDP", s_sockets.udp_local_broadcast_listener ); + if (s_sockets.udp_local_broadcast_listener != -1) master_set_add( "UDP", s_sockets.udp_local_broadcast_listener ); master_set_add( "UDP", s_sockets.udp_global_broadcast_listener ); CIPSTER_TRACE_INFO( "%s:\n" @@ -776,7 +782,7 @@ EipStatus NetworkHandlerInitialize() } -EipStatus NetworkHandlerProcessOnce() +EipStatus NetworkHandlerProcessOnce(int timeoutInSeconds) { read_set = master_set; @@ -785,7 +791,7 @@ EipStatus NetworkHandlerProcessOnce() // On Linux, select() modifies timeout to reflect the amount of time // not slept; most other implementations do not do this. // Consider timeout to be undefined after select() returns. - tv.tv_sec = 0; + tv.tv_sec = timeoutInSeconds; tv.tv_usec = 0; int ready_count = select( highest_socket_handle + 1, &read_set, 0, 0, &tv ); diff --git a/source/src/enet_encap/networkhandler.h b/source/src/enet_encap/networkhandler.h index 0e17c90..197b26f 100644 --- a/source/src/enet_encap/networkhandler.h +++ b/source/src/enet_encap/networkhandler.h @@ -19,7 +19,7 @@ */ EipStatus NetworkHandlerInitialize(); -EipStatus NetworkHandlerProcessOnce(); +EipStatus NetworkHandlerProcessOnce(int timeoutInSeconds = 0); EipStatus NetworkHandlerFinish(); diff --git a/source/src/enet_encap/sockaddr.cc b/source/src/enet_encap/sockaddr.cc index a1e0701..7070075 100644 --- a/source/src/enet_encap/sockaddr.cc +++ b/source/src/enet_encap/sockaddr.cc @@ -4,6 +4,7 @@ * ******************************************************************************/ +#include #include "sockaddr.h" #if defined(__linux__) || defined(__APPLE__)