stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.44k stars 1.75k forks source link

TCP socket bind fails on MACOS #536

Open vvillatora opened 4 years ago

vvillatora commented 4 years ago

Hi all.

I found a crash using your library on MACOS with the error "Illegal Instruction : 4" when attempting to launch the random-test-server file. This problem is due to the fail of the bind system function when the sockaddr_in is not formatted following the apple standard

After some search on the Internet and some debugging with XCODE I modified the modbus_tcp_listen function in modbus-tcp.c file. patch.txt

Please note that my code does not impact the original one when used on other platforms.

Please refer to the patch in attachment to this email that solves the issue.

Kind Regards.

Virgilio eng. Villatora