@@ -236,7 +236,11 @@ static int _modbus_tcp_set_ipv4_options(int s)
236236 /* Set the TCP no delay flag */
237237 /* SOL_TCP = IPPROTO_TCP */
238238 option = 1 ;
239- rc = setsockopt (s , IPPROTO_TCP , TCP_NODELAY , & option , sizeof (int ));
239+ #ifdef _WIN32
240+ rc = setsockopt (s , IPPROTO_TCP , TCP_NODELAY , (const char * )& option , sizeof (int ));
241+ #else
242+ rc = setsockopt (s , IPPROTO_TCP , TCP_NODELAY , (const void * )& option , sizeof (int ));
243+ #endif
240244 if (rc == -1 ) {
241245 return -1 ;
242246 }
@@ -264,7 +268,11 @@ static int _modbus_tcp_set_ipv4_options(int s)
264268 **/
265269 /* Set the IP low delay option */
266270 option = IPTOS_LOWDELAY ;
267- rc = setsockopt (s , IPPROTO_IP , IP_TOS , & option , sizeof (int ));
271+ #ifdef _WIN32
272+ rc = setsockopt (s , IPPROTO_IP , IP_TOS , (const char * )& option , sizeof (int ));
273+ #else
274+ rc = setsockopt (s , IPPROTO_IP , IP_TOS , (const void * )& option , sizeof (int ));
275+ #endif
268276 if (rc == -1 ) {
269277 return -1 ;
270278 }
@@ -598,7 +606,11 @@ int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
598606 }
599607
600608 enable = 1 ;
601- if (setsockopt (new_s , SOL_SOCKET , SO_REUSEADDR , & enable , sizeof (enable )) == -1 ) {
609+ #ifdef _WIN32
610+ if (setsockopt (new_s , SOL_SOCKET , SO_REUSEADDR , (const char * )& enable , sizeof (enable )) == -1 ) {
611+ #else
612+ if (setsockopt (new_s , SOL_SOCKET , SO_REUSEADDR , (const void * )& enable , sizeof (enable )) == -1 ) {
613+ #endif
602614 close (new_s );
603615 return -1 ;
604616 }
@@ -717,7 +729,11 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
717729 continue ;
718730 } else {
719731 int enable = 1 ;
720- rc = setsockopt (s , SOL_SOCKET , SO_REUSEADDR , & enable , sizeof (enable ));
732+ #ifdef _WIN32
733+ rc = setsockopt (s , SOL_SOCKET , SO_REUSEADDR , (const char * )& enable , sizeof (enable ));
734+ #else
735+ rc = setsockopt (s , SOL_SOCKET , SO_REUSEADDR , (const void * )& enable , sizeof (enable ));
736+ #endif
721737 if (rc != 0 ) {
722738 close (s );
723739 if (ctx -> debug ) {
0 commit comments