eclipse-threadx / netxduo

Eclipse ThreadX - NetXDuo is an advanced, industrial-grade TCP/IP network stack designed specifically for deeply embedded real-time and IoT applications
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/index.md
MIT License
242 stars 137 forks source link

Socket bind/listen to specific IP #94

Closed vks3 closed 2 years ago

vks3 commented 2 years ago

I'm having a device with two Ethernet ports. I've set them up under a single IP instance by adding a secondary interface. Now, using either the NetX native API or the BSD API, is it possible to do a bind/listen on specific IP address only? What I need is for a TCP server to be able to listen on a specific IP only, or a TCP client to make a connect request with source address as explicitly specified during bind or listen. An addon question to the above is that is it allowed to have multiple IP addresses assigned to a single physical port under NetX.

TiejunMS commented 2 years ago

It is possible to bind to specific IP address by both native and BSD APIs. For BSD APIs, you can simply use bind(). While in native APIs, you will need to setup nx_tcp_socket_syn_received_notify and do the filtering in this callback function.

To support multiple IPv4 addresses, you will need to create multiple logical interfaces (NX_INTERFACE) and handle them correctly in network driver. See example here. For IPv6 addresses, each interface can have multiple addresses.

TiejunMS commented 2 years ago

Closing. Feel free to reopen it.