Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
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
up vote 1 down vote accepted

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).

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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