Seems there is no cross-platform way to listen only specific network
interface.
And there is no good platform-specific way too.
On Linux:
- It can be easily done with iptables. However it is out of OpenHPI scope.
- There is setsockopt(SO_BINDTODEVICE). But it was described as deprecated
and it requires root rights.
I have examined several network services and found they used bind() call.
They did convert interface name to interface address and called bind().
Which is actually socket address binding but not the network interface
binding.
And the socket binded to the interface address stops working if the
interface address is changed.
For example DHCP server can change the interface address. And an User can
do this too.
NTPd developers introduced periodical check for interface address change.
It can be good way.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
After long distressful reflection I decided to take "bind address" road.
So we have OPENHPI_DAEMON_BIND_ADDRESS env. var and -b (--bind) command line option.
Implemented in trunk (rev. #7297)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Seems there is no cross-platform way to listen only specific network
interface.
And there is no good platform-specific way too.
On Linux:
- It can be easily done with iptables. However it is out of OpenHPI scope.
- There is setsockopt(SO_BINDTODEVICE). But it was described as deprecated
and it requires root rights.
I have examined several network services and found they used bind() call.
They did convert interface name to interface address and called bind().
Which is actually socket address binding but not the network interface
binding.
And the socket binded to the interface address stops working if the
interface address is changed.
For example DHCP server can change the interface address. And an User can
do this too.
NTPd developers introduced periodical check for interface address change.
It can be good way.
After long distressful reflection I decided to take "bind address" road.
So we have OPENHPI_DAEMON_BIND_ADDRESS env. var and -b (--bind) command line option.
Implemented in trunk (rev. #7297)