RE: Information abt rotuing and interfaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Fill in the Index Value using SIOCGIFINDEX (Preventive measure)
* Dump the contents in Hex..say from ifr ->ifr_addr.sa_data[0]
to ifr ->ifr_addr.sa_data[3] and check.

HTH
-Mani


-----Original Message-----
From: paridhi bansal [mailto:paridhibansal@yahoo.com]
Sent: Tuesday, November 19, 2002 3:05 PM
To: Mani Mahadevan; kernelnewbies@nl.linux.org; dharmenderr@cybage.comT
Subject: RE: Information abt rotuing and interfaces


Thanx for the answers. I am able to get the some
portion of the ips but not the complete ip of the
interfaces. Here's the code i am using. Could u pls
tell me whre exactly is the error??Thanx in advance.

#include<stdio.h>
#include<net/if.h>
#include<sys/ioctl.h>
#include<sys/socket.h>
#include<netdb.h>

#define BUFSIZ 4096 

main()
{

	int s,n;
	struct ifconf ifc;
	char buf[BUFSIZ];
      	struct ifreq *ifr;
	struct in_addr *iff;

	s=socket(AF_INET, SOCK_DGRAM, 0);
	ifc.ifc_len = sizeof(buf);
	ifc.ifc_buf = buf;
	if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) 
	{
           printf("\nError1");
	}
 
	ifr = ifc.ifc_req;
	printf("Before for loop");

	for (n=ifc.ifc_len/sizeof(struct ifreq); --n >= 0;
ifr++) 
	{
		printf("\nPrinting name: %s" ,ifr->ifr_name);
		
		if(ioctl(s, SIOCGIFADDR, (char *)ifr) < 0)
			printf("\nError2");
		else 
		{
		      iff=(struct in_addr *)(ifr ->ifr_addr.sa_data
);
		      printf("\nPrinting address:
%s",inet_aton(*iff));
		}
				
		if(ioctl(s, SIOCGIFNETMASK, (char *)ifr) < 0)
			printf("\nError3");
		else 
		{
		      iff=(struct in_addr *)(ifr
->ifr_netmask.sa_data );
		      printf("\nPrinting mask: %s",inet_aton(*iff));
		}
				

Paridhi
--- Mani Mahadevan <mrsmani@cisco.com> wrote:
> Thanks for correcting me.
> 
> -Mani
> 
> -----Original Message-----
> From: kernelnewbies-bounce@nl.linux.org
> [mailto:kernelnewbies-bounce@nl.linux.org]On Behalf
> Of Dharmender Rai
> Sent: Tuesday, November 19, 2002 12:08 PM
> To: Mani Mahadevan; paridhi bansal;
> kernelnewbies@nl.linux.org
> Subject: RE: Information abt rotuing and interfaces
> 
> 
> routing info can be found in /etc/gateways
>  --- Mani Mahadevan <mrsmani@cisco.com> wrote: > *
> For
> getting the Interface List use SIOCGIFCONF cmd
> > in ioctl.
> > * Then use the SIOCGIFFLAGS ioctl cmd for each of
> > the above found interface
> >   and check for ifr.ifr_flags to be IFF_UP. This
> > would tell you whether the
> > interface is
> >   Up or not.
> > * Go thru the list of ioctl commands in
> > linux/sockios.h & use them
> > appropriately
> >   as per your requirement.
> > 
> > * Reg routing it should be in the /proc, but not
> > sure about the exact
> > loaction.
> > 
> > -Mani
> > 
> > 
> > -----Original Message-----
> > From: kernelnewbies-bounce@nl.linux.org
> > [mailto:kernelnewbies-bounce@nl.linux.org]On
> Behalf
> > Of paridhi bansal
> > Sent: Monday, November 18, 2002 2:40 PM
> > To: kernelnewbies@nl.linux.org
> > Subject: Information abt rotuing and interfaces
> > 
> > 
> > Hi!!
> > 
> > Can somebody tell me how can i get the all
> > information
> > abt the interfaces that r up on my machine using
> > ioctl
> > call???
> > 
> > Where is the kernel file that stores the routing
> > information??
> > 
> > Paridhi 
> > 
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Web Hosting - Let the expert host your site
> > http://webhosting.yahoo.com
> > --
> > Kernelnewbies: Help each other learn about the
> Linux
> > kernel.
> > Archive:      
> > http://mail.nl.linux.org/kernelnewbies/
> > FAQ:           http://kernelnewbies.org/faq/
> > 
> 
> > ATTACHMENT part 2 application/ms-tnef
> name=winmail.dat
>  
> 
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
> --
> Kernelnewbies: Help each other learn about the Linux
> kernel.
> Archive:      
> http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux