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

Conversation

desteemy
Copy link

UNIX systems <sys/socket.h> require const void *, while Windows <winsock2.h> const char *. Previous version without type casting did not build on Windows, resulting in:

CC modbus-tcp.lo
modbus-tcp.c: In function '_modbus_tcp_set_ipv4_options':
modbus-tcp.c:239:50: error: passing argument 4 of 'setsockopt' from incompatible pointer type [-Wincompatible-pointer-types]
239 | rc = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &option, sizeof(int));
| ^~~~~~~
| |
| int *
In file included from modbus-tcp.c:31:
C:/msys64/mingw64/include/winsock2.h:1035:88: note: expected 'const char *' but argument is of type 'int *'
1035 | WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
| ~~~~~~~~~~~~^~~~~~
modbus-tcp.c: In function 'modbus_tcp_listen':
modbus-tcp.c:566:53: error: passing argument 4 of 'setsockopt' from incompatible pointer type [-Wincompatible-pointer-types]
566 | if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) == -1) {
| ^~~~~~~
| |
| int *
C:/msys64/mingw64/include/winsock2.h:1035:88: note: expected 'const char *' but argument is of type 'int *'
1035 | WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
| ~~~~~~~~~~~~^~~~~~
modbus-tcp.c: In function 'modbus_tcp_pi_listen':
modbus-tcp.c:683:58: error: passing argument 4 of 'setsockopt' from incompatible pointer type [-Wincompatible-pointer-types]
683 | rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
| ^~~~~~~
| |
| int *
C:/msys64/mingw64/include/winsock2.h:1035:88: note: expected 'const char *' but argument is of type 'int *'
1035 | WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
| ~~~~~~~~~~~~^~~~~~
make[2]: *** [Makefile:486: modbus-tcp.lo] Error 1
make[1]: *** [Makefile:505: all-recursive] Error 1
make: *** [Makefile:391: all] Error 2

#721

UNIX systems <sys/socket.h> require const void *, while Windows <winsock2.h> const char *. Previous version without type casting did not build on Windows.
Copy link

cla-bot bot commented Mar 18, 2025

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

@desteemy
Copy link
Author

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

I have just sent it. Waiting for verification. My guess is that this is not the best option to verify that the person who sends the form is actually the person who commits the code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant