33//
44
55#include < system_error>
6+
7+ #ifdef __linux__
68#include < sys/socket.h>
79#include < netinet/in.h>
810#include < arpa/inet.h>
11+ #elif defined _WIN32
12+ #include < winsock2.h>
13+ #include < ws2tcpip.h>
14+ #include < time.h>
15+ #endif
16+
917#include < unistd.h>
1018#include < fcntl.h>
1119
1220#include " utils/Logger.h"
1321#include " TCPSocket.h"
1422
23+ #if !(defined __linux__) && !(defined SHUT_RDWR)
24+ #define SHUT_RDWR SD_BOTH
25+ #endif
26+
1527
1628namespace eipScanner {
1729 namespace sockets {
@@ -30,6 +42,7 @@ namespace eipScanner {
3042 }
3143
3244 // Set non-blocking
45+ #ifdef __linux__
3346 auto arg = fcntl (_sockedFd, F_GETFL, NULL );
3447 if (arg < 0 ) {
3548 throw std::system_error (errno, std::generic_category ());
@@ -39,6 +52,7 @@ namespace eipScanner {
3952 if (fcntl (_sockedFd, F_SETFL, arg) < 0 ) {
4053 throw std::system_error (errno, std::generic_category ());
4154 }
55+ #endif
4256
4357 Logger (LogLevel::DEBUG) << " Opened socket fd=" << _sockedFd;
4458
@@ -61,7 +75,7 @@ namespace eipScanner {
6175 // Socket selected for write
6276 int err;
6377 socklen_t lon = sizeof (int );
64- if (getsockopt (_sockedFd, SOL_SOCKET, SO_ERROR, (void *) (&err), &lon) < 0 ) {
78+ if (getsockopt (_sockedFd, SOL_SOCKET, SO_ERROR, (char *) (&err), &lon) < 0 ) {
6579 throw std::system_error (errno, std::generic_category ());
6680 }
6781 // Check the value returned...
@@ -77,6 +91,8 @@ namespace eipScanner {
7791 throw std::system_error (errno, std::generic_category ());
7892 }
7993 }
94+
95+ #ifdef __linux__
8096 // Set to blocking mode again...
8197 if ((arg = fcntl (_sockedFd, F_GETFL, NULL )) < 0 ) {
8298 throw std::system_error (errno, std::generic_category ());
@@ -85,6 +101,7 @@ namespace eipScanner {
85101 if (fcntl (_sockedFd, F_SETFL, arg) < 0 ) {
86102 throw std::system_error (errno, std::generic_category ());
87103 }
104+ #endif
88105 }
89106
90107
@@ -102,7 +119,7 @@ namespace eipScanner {
102119 void TCPSocket::Send (const std::vector<uint8_t > &data) const {
103120 Logger (LogLevel::TRACE) << " Send " << data.size () << " bytes from TCP socket #" << _sockedFd << " ." ;
104121
105- int count = send (_sockedFd, data.data (), data.size (), 0 );
122+ int count = send (_sockedFd, ( char *) data.data (), data.size (), 0 );
106123 if (count < data.size ()) {
107124 throw std::system_error (errno, std::generic_category ());
108125 }
@@ -113,7 +130,7 @@ namespace eipScanner {
113130
114131 int count = 0 ;
115132 while (size > count) {
116- auto len = recv (_sockedFd, recvBuffer.data () + count, size - count, 0 );
133+ auto len = recv (_sockedFd, ( char *)( recvBuffer.data () + count) , size - count, 0 );
117134 count += len;
118135 if (len < 0 ) {
119136 throw std::system_error (errno, std::generic_category ());
@@ -132,4 +149,4 @@ namespace eipScanner {
132149 return recvBuffer;
133150 }
134151 }
135- }
152+ }
0 commit comments