stephane / libmodbus

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

tcp_new requires a node address, _listen method doesn't want it #32

Closed karlp closed 10 years ago

karlp commented 12 years ago

In modbus_new_tcp_pi(), (I haven't looked at the regular version), the following code is used to set up the hostname of the remote server: https://github.com/stephane/libmodbus/blob/master/src/modbus-tcp.c#L701

ret_size = strlcpy(ctx_tcp_pi->node, node, dest_size);

Then in modbus_tcp_pi_listen there is a check no the node element being 0, which then properly sets up the socket to listen on NULL, for any address. https://github.com/stephane/libmodbus/blob/master/src/modbus-tcp.c#L435

However, given the way the check is done in new(), there's no way to set the node to a zero value. I suggest that if the incoming node is NULL, that it be set to zero,

karlp commented 12 years ago

Ok, this only is a problem for the pi contexts. I just switched to regular tcp for the master, and it works just fine now. For tcp, it ignores the ip address if you use the listen/accept pairs

stephane commented 10 years ago

Hi Karl,

Never too late ;) Thanks for the report.

karlp commented 10 years ago

Thanks for this, and thanks for #190 as well, making the regular tcp_ method also observe the addresses passed in :)