Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIN32 compatibility for setsockopt() in modbus-tcp.c #800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 20 additions & 4 deletions src/modbus-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ static int _modbus_tcp_set_ipv4_options(int s)
/* Set the TCP no delay flag */
/* SOL_TCP = IPPROTO_TCP */
option = 1;
rc = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &option, sizeof(int));
#ifdef _WIN32
rc = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char *)&option, sizeof(int));
#else
rc = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const void *)&option, sizeof(int));
#endif
if (rc == -1) {
return -1;
}
Expand Down Expand Up @@ -264,7 +268,11 @@ static int _modbus_tcp_set_ipv4_options(int s)
**/
/* Set the IP low delay option */
option = IPTOS_LOWDELAY;
rc = setsockopt(s, IPPROTO_IP, IP_TOS, &option, sizeof(int));
#ifdef _WIN32
rc = setsockopt(s, IPPROTO_IP, IP_TOS, (const char *)&option, sizeof(int));
#else
rc = setsockopt(s, IPPROTO_IP, IP_TOS, (const void *)&option, sizeof(int));
#endif
if (rc == -1) {
return -1;
}
Expand Down Expand Up @@ -563,7 +571,11 @@ int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
}

enable = 1;
if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) == -1) {
#ifdef _WIN32
if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, (const char *)&enable, sizeof(enable)) == -1) {
#else
if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, (const void *)&enable, sizeof(enable)) == -1) {
#endif
close(new_s);
return -1;
}
Expand Down Expand Up @@ -680,7 +692,11 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
continue;
} else {
int enable = 1;
rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
#ifdef _WIN32
rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&enable, sizeof(enable));
#else
rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const void *)&enable, sizeof(enable));
#endif
if (rc != 0) {
close(s);
if (ctx->debug) {
Expand Down