Getting Network Interface Information
I am using Redhat Linux 7.2 and C programming language. I want to know two things:
1. How to get the list of Network interfaces the system has? 2. How to get the IP addresses (IPv4/IPv6) associated with each interface? any comments on this will be appreciated.. |
ifconfig -a
|
Thanx leed_25 but i want some function call which does this within my C program. I dont want to use the system call and parsing.
|
Well you can read the information directly from the proc filesystem. But the proc filesystem isn't always present and you will have to write a parser for the information which isn't always convenient.
There are other ways to get information using ioctls. You should read the following manpage: 'man 7 netdevice' |
Well since I was curious on how it actually worked, I wrote a small program which gets a list of all the interfaces and their ip numbers. Well here is the source code:
Code:
#include <sys/ioctl.h> |
Thanx for the code Nik. It was great help.
|
All times are GMT -5. The time now is 05:17 PM. |