I am creating a tcp connection using the function socket()
, bind()
, and then listen()
.
Our customers would like to be able to define an IP address of the server at runtime. Is there a way of changing the IP at runtime or must it be done in the BIOS?
Thanks for any tips
I am not sure what you mean by defining 'IP address of the server at runtime?'. Obviously for a given
socket
it's IP address cannot be changed. It's an endpoint of a connection, it cannot be changed run time. If you just want to assign multiple IP addresses to a host that's possible.In general - you can add as many IP addresses as you want to your machine (ok not exactly) but certainly a hundred or so (ie. statically allocated). That's not the problem (management of that is a nightmare, but sure not impossible). The problem is how those IP addresses are reached, that is not in your control, that depends upon the settings on client especially the routing entries. eg. you could use all of the IP addresses in a Subnet (say
10.1.2/24
).Not recommended - but possible.
Once you have those IP addresses - you
bind
on the port and address asINADDR_ANY
, which says accept connection on 'any ' of the local addresses. On which address the connection was made to can be determined on server usinggetsockname
.