I am working on an application that requires changing IP, gateway, or subnet mask information. Is it best to build in calls to do this or is it best to call external applications (ifconfig and route) to make the changes?
c code or external app
Dec 13, 2004
3 Replies
Just open a TCP or UDP socket and use the appropriate ioctl()'s on the socket.
Please understand that this kind of operation needs that the process has superuser rights (root).
Tauno Voipio
tauno voipio (at) iki fi
Yes and yes. If you want the changes to be permanent, you will want to update configuration files.
The answer is YES and NO. It is all matter of your taste, choice and how details you know about your system.
For instance, if you are not very familiar with all the configuration files then from your C code call the external function (call execXX function family) and pass the parameter to it. If you are familiar with all configuration file for your particular platform then modify the configuration file (read/write to configuration file).
Personally, for me since I will do a very similar thing in the near future, my choice is to modify the configuration files and then reboot the system.
Good luck.
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required