Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/CMakeLists.txt

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ else()
endif()


cmake_minimum_required( VERSION 2.8.3 )
cmake_minimum_required( VERSION 3.5 )


project( CIPster )
Expand Down Expand Up @@ -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 )
7 changes: 4 additions & 3 deletions source/src/byte_bufs.h

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef BYTE_BUFS_H_
#define BYTE_BUFS_H_

#include <cstdint> // for uint8_t, uint16_t, uint32_t, uint64_t
#include <string>
#include <stdexcept> // for the convenience of clients of these classes, which throw

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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().
Expand Down
2 changes: 1 addition & 1 deletion source/src/cip/cipassembly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions source/src/cip/cipconnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/src/cip/cipconnectionmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 5 additions & 0 deletions source/src/cip/cipepath.h

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/src/cip/cipmessagerouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion source/src/enet_encap/encap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
14 changes: 10 additions & 4 deletions source/src/enet_encap/networkhandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
{
Expand All @@ -671,6 +675,7 @@ EipStatus NetworkHandlerInitialize()
}
}

#if !defined(_WIN32)
//-----<udp_local_broadcast_listener>---------------------------------------
// create a new UDP socket
s_sockets.udp_local_broadcast_listener = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
Expand Down Expand Up @@ -703,6 +708,7 @@ EipStatus NetworkHandlerInitialize()
goto error;
}
}
#endif

//-----<udp_unicast_listener>----------------------------------------------
// create a new UDP socket
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -776,7 +782,7 @@ EipStatus NetworkHandlerInitialize()
}


EipStatus NetworkHandlerProcessOnce()
EipStatus NetworkHandlerProcessOnce(int timeoutInSeconds)
{
read_set = master_set;

Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion source/src/enet_encap/networkhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
EipStatus NetworkHandlerInitialize();

EipStatus NetworkHandlerProcessOnce();
EipStatus NetworkHandlerProcessOnce(int timeoutInSeconds = 0);

EipStatus NetworkHandlerFinish();

Expand Down
1 change: 1 addition & 0 deletions source/src/enet_encap/sockaddr.cc

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
******************************************************************************/

#include <cstdint>
#include "sockaddr.h"

#if defined(__linux__) || defined(__APPLE__)
Expand Down