Are there any program accessible equivalents to network configuration tools such as 'ifconfig', 'iwconfig' e.t.c.?

I am looking for an elegant method of accessing the functionality and information these provide from within a program.

  • Which type of program needs to know these information? There are different solutions for different languages, e.g. use getifaddrs to get the IP's from within C code.. – binfalse Apr 25 '11 at 7:44
  • 2
    FYI... ifconfig is not recommended for use under linux, as it has bugs and is no longer maintained... use ip addr show – Mike Pennington Apr 25 '11 at 12:09

ifconfig and friends obtain most of the information they show by calling various ioctl's on sockets. I recommend reading the source of ifconfig and other tools to see exactly what they do. But in most cases, it'll be easier to popen an ifconfig command.

Note that in both cases, your program will have to be ported to different unix variants. Neither ioctl nor the output format of ifconfig and other commands is portable.

An advantage of using ioctl's is not depending on external tools. On Linux, you can count on ifconfig and route being available, as well as iwconfig if there are wireless interfaces, but not necessarily ip (ip shows more information and its output is easier to parse, but most distributions don't install it by default, so it's actually not a good idea for portability).

  • Thanks a lot for the hints everyone...I'm already getting to know the 'ip' utility and reading about it in 'Linux Advanced Routing & Traffic Control HOWTO' by Bert Hubert. It's much neater than 'ifconfig'. Next step might be to get the source and have a peek in there to get ideas about performing the queries from within my program. – darbehdar Apr 29 '11 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.