Re: Programatically change IP Address

Tauno Voipio <tauno.voipio@xxxxxxxxxxxxx> writes:

>ibondre@xxxxxxxxx wrote:
>> How can i programatically change the IP Address, DNS, gateway,
>> Enable/disable DHCP, in Linux Using C or C++.
>> Is there also an API to get this properties?

The dns server is in /etc/resolv.conf. The gateway is set by the route
command or the ip command in more modern situations.
The address of the card is set either by dhcp or by ifconfig.

You can run programs from within your C program (execle)

>The DNS and DHCP settings are in configuration files
>you can modify if you have sufficient access rights.

>To effect the changes you may need to send a signal
>to the corresponding daemon or to restart it.

>The IP addresses and routing information are in
>kernel tables which are accessible with suitable
>ioctl() calls. For details, get a book on network
>programming, e.g.

> W. Richard Stevens, UNIX Network Programming

>Needless to say that the process modifying any network
>settings needs sufficient privileges.