Visit Our UNIX and Linux User Community


C program : how to list interfaces with a valid IP ?


 
Thread Tools Search this Thread
Top Forums Programming C program : how to list interfaces with a valid IP ?
# 1  
Old 01-15-2008
Question C program : how to list interfaces with a valid IP ?

Hi all,

I think that the title is explicit enough Smilie I would like in a C program to list the interfaces with a valid IP. Those that can permit to send something over a network.

Thanks Smilie
# 2  
Old 01-16-2008
Having an IP address does not mean the routing is good enough to be able to send or receive anything over the interface.

I have been able to do so with getifaddrs() on Linux. Not sure other Unix flavours. Go search for manpage for that function.
# 3  
Old 01-16-2008
Hi

You can use the "system" function from C, and you can call ifconfig like commands (i'm not sure that such command exist on UN*X, but it is possible). In that way you can list the interfaces. If you pipe the command with grep, you can also filter out which interfaces has a valid IP address.

Hope it helps
# 4  
Old 01-16-2008
Stevens has a good example that is pretty compliant and portable.
Buy, beg or borrow Unix Network Programming if you don't already have a copy.
# 5  
Old 01-16-2008
that's what I know

perhaps you need to write the survices by yourself,the interfaces should be designed thorouly .well,that's all what I know.
# 6  
Old 01-16-2008
Quote:
Originally Posted by ramen_noodle
Stevens has a good example that is pretty compliant and portable.
Buy, beg or borrow Unix Network Programming if you don't already have a copy.
Who is 'Stevens' ? I'll look for this book thanks for the tip
# 7  
Old 01-16-2008
Quote:
Originally Posted by cbkihong
Having an IP address does not mean the routing is good enough to be able to send or receive anything over the interface.

I have been able to do so with getifaddrs() on Linux. Not sure other Unix flavours. Go search for manpage for that function.
Nice function ! That works but I have a problem with the assignment "ifcur = iflist" : error: incompatible types in assignment ?! I don't understand why.

Code:
	
...
struct ifaddrs*		iflist 
,		        ifcur ;
	
if (getifaddrs (&iflist) < 0)
	printf ("* Erreur getifaddrs ! \n") ;

ifcur = iflist ;
	
freeifaddrs(iflist);
...


Previous Thread | Next Thread
Test Your Knowledge in Computers #627
Difficulty: Medium
When a function clones itself, it is considered to be recursive-clone function.
True or False?

9 More Discussions You Might Find Interesting

1. Solaris

can't see other interfaces

Hi Guys, I have a Netra240 server with four interfaces. However, when I ran this command dladm show-dev it showed only one interface bge0. Can someone please explain to me how to fix this problem? Thanks guys. (1 Reply)
Discussion started by: cjashu
1 Replies

2. Solaris

Interfaces and Virtual-interfaces queries

Hi Al, In course of understanding networking in Solaris, I have these doubts on Interfaces. Please clarify me. I have done fair research in this site and others but could not be clarified. 1. In the "ifconfig -a" command, I see many interfaces and their configurations. But I see many... (1 Reply)
Discussion started by: satish51392111
1 Replies

3. Shell Programming and Scripting

Selecting files from a list and passing them to a program using csh

I have a list of files, example as shown below n02-z30-dsr65-ndelt0.25-varp0.002-4x3drw-csq.msf n02-z30-dsr65-ndelt0.25-varp0.004-4x3drw-csq.msf n02-z30-dsr65-ndelt0.25-varp0.006-4x3drw-csq.msf n02-z30-dsr65-ndelt0.25-varp0.008-4x3drw-csq.msf... (8 Replies)
Discussion started by: kristinu
8 Replies

4. Ubuntu

How to list my program or package that i compile and installed?

Hi I would like to ask in ubuntu or linux on how to list all my package or software the i installed via source code( compile installed in dir default is /usr/local) just like i solaris in which if you installed a package in ur choosing default root installation dir you can just issue a command... (2 Replies)
Discussion started by: jao_madn
2 Replies

5. Homework & Coursework Questions

Valid Name

Could someone help me by midnight tonight!!! Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Insert a reference to the Bourne shell as the command... (0 Replies)
Discussion started by: cody007
0 Replies

6. Solaris

list of physical net interfaces

hi, Can I listdown all available net interfaces on my system like SF4800 or Netra440. I know there are 4 port physically present but I can't see or list them using either sysdef -v prtconf -vp prtdiag -v dladm kstat may be I'm missing switched on these or may some other command... (8 Replies)
Discussion started by: busyboy
8 Replies

7. UNIX for Advanced & Expert Users

find: 0652-019 The status on /interfaces/eu3/hmsl/EBS/20070722 is not valid.

I am getting this error when i issue find command. Any advice. Regards, Vishal (0 Replies)
Discussion started by: vishal_ranjan
0 Replies

8. Programming

valid code?

hey , everyone. I have a few questions about pieces of code and was wondering if someone could tell me what exactly they did or if they are even valid. bool1 && bool2 || bool3 <---in what order do these get processed? if (! isdigit(c)) <---What does this do? i = j % 3; <---what does this do?... (4 Replies)
Discussion started by: bebop1111116
4 Replies

9. UNIX for Dummies Questions & Answers

interfaces

Hello, which network interface i must sellect during the solaris9 installation le0 or hme0 ? this system is part of the network, it is a standalone system and is not on any domain. thanks for your help, em (1 Reply)
Discussion started by: emsakopa
1 Replies

Featured Tech Videos