IP address of a server at runtime

Hello,

I developed a client task in C and a server task in C (an application strongly coupled). The client needs the server IP address to connect to the server. The problem is: I don't know in advance which machine will run the client and which machine will run the server so I can know the ip address of the server only at runtime My question: how at run time the client will know the ip address of the server?

Thank you so much for help

On a Unix system of a standard flavour it can get its own ip address usig the ifconfig command.

If the ip address of the target machine (your server) is not constant then you will need some "lookup" service running either maintained locally or remote (ie, a DNS server). You can set up a "dynamic DNS service" on a machine locally or remote which can "resolve" the nodename of the target into its current ip address.

This kind of dynamic service is not recommended but from what you describe, I don't think that there's much choice.

Of course, you might have a DHCP server (maybe a router) which also runs a name resolution service which will track the changing ip addresses.

Let's see what others on this forum say.

1 Like

try the gethostbyname() function, assuming you can enter the DSN name. Note this function is deprecated but it is easy to use.

gethostbyname(), gethostbyaddr()

1 Like

Thank you for your answers
You mean:
I assign to the server a hostname (for example : serv) and the client get the @ip of the server by get-host-by-name (serv) ?

Thank you