3
3
//
4
4
5
5
#include < system_error>
6
+
7
+ #ifdef __linux__
6
8
#include < sys/socket.h>
7
9
#include < netinet/in.h>
8
10
#include < arpa/inet.h>
11
+ #elif defined _WIN32
12
+ #include < winsock2.h>
13
+ #include < ws2tcpip.h>
14
+ #include < time.h>
15
+ #endif
16
+
9
17
#include < unistd.h>
10
18
#include < fcntl.h>
11
19
12
20
#include " utils/Logger.h"
13
21
#include " TCPSocket.h"
14
22
23
+ #if !(defined __linux__) && !(defined SHUT_RDWR)
24
+ #define SHUT_RDWR SD_BOTH
25
+ #endif
26
+
15
27
16
28
namespace eipScanner {
17
29
namespace sockets {
@@ -30,6 +42,7 @@ namespace eipScanner {
30
42
}
31
43
32
44
// Set non-blocking
45
+ #ifdef __linux__
33
46
auto arg = fcntl (_sockedFd, F_GETFL, NULL );
34
47
if (arg < 0 ) {
35
48
throw std::system_error (errno, std::generic_category ());
@@ -39,6 +52,7 @@ namespace eipScanner {
39
52
if (fcntl (_sockedFd, F_SETFL, arg) < 0 ) {
40
53
throw std::system_error (errno, std::generic_category ());
41
54
}
55
+ #endif
42
56
43
57
Logger (LogLevel::DEBUG) << " Opened socket fd=" << _sockedFd;
44
58
@@ -61,7 +75,7 @@ namespace eipScanner {
61
75
// Socket selected for write
62
76
int err;
63
77
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 ) {
65
79
throw std::system_error (errno, std::generic_category ());
66
80
}
67
81
// Check the value returned...
@@ -77,6 +91,8 @@ namespace eipScanner {
77
91
throw std::system_error (errno, std::generic_category ());
78
92
}
79
93
}
94
+
95
+ #ifdef __linux__
80
96
// Set to blocking mode again...
81
97
if ((arg = fcntl (_sockedFd, F_GETFL, NULL )) < 0 ) {
82
98
throw std::system_error (errno, std::generic_category ());
@@ -85,6 +101,7 @@ namespace eipScanner {
85
101
if (fcntl (_sockedFd, F_SETFL, arg) < 0 ) {
86
102
throw std::system_error (errno, std::generic_category ());
87
103
}
104
+ #endif
88
105
}
89
106
90
107
@@ -102,7 +119,7 @@ namespace eipScanner {
102
119
void TCPSocket::Send (const std::vector<uint8_t > &data) const {
103
120
Logger (LogLevel::TRACE) << " Send " << data.size () << " bytes from TCP socket #" << _sockedFd << " ." ;
104
121
105
- int count = send (_sockedFd, data.data (), data.size (), 0 );
122
+ int count = send (_sockedFd, ( char *) data.data (), data.size (), 0 );
106
123
if (count < data.size ()) {
107
124
throw std::system_error (errno, std::generic_category ());
108
125
}
@@ -113,7 +130,7 @@ namespace eipScanner {
113
130
114
131
int count = 0 ;
115
132
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 );
117
134
count += len;
118
135
if (len < 0 ) {
119
136
throw std::system_error (errno, std::generic_category ());
@@ -132,4 +149,4 @@ namespace eipScanner {
132
149
return recvBuffer;
133
150
}
134
151
}
135
- }
152
+ }
0 commit comments