Re: How to know Network Interface Name

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

 



Shivdas Patil wrote:

Hi,
I have Intel 915 Motherboard with onboard Network Card (Intel PRO 10/100 VE Network Connection).
I installed Redhat 9 ( Kernel 2.4.20-8) successfully..
Now when I say
#ifconfig eth0 up
I get an error unknown device: eth0..


How do I know what interface name is assigned ??
& before that, how do I know whether the card is detected & configured properly ???
I checked for dmesg output , but did not see any "eth" related entry...
Thanks in advance..
Shiv




hi there ,
here is some code, i have written sometime ago for testing . you could use to get the name of the interface , if one exists . Put it all together and get it working , to check interface name . program'atically . Take some care while you use the code .





/* Include files */

#include<sys/ioctl.h>           /* for ioctl() call    */
#include<net/if.h>              /* for struct ifreq{}  */
#include<sys/socket.h>          /* for socket() Api    */
#include<sys/types.h>
#include<linux/in.h>



/************** Global variables ****************/

int     ret_val;
int     sock_fd;
struct  ifreq req;
struct  sockaddr_in *saptr;



/ * ****************************************************************************
* Function : getInterfaceName
*
* Description :This function gets the name of the interface, if any , on
the given index.
* * Paramters :
* if_index - the index which is queried.
* if_name - the interface name , if if_index is valid.
* Example : on PC's index 2 is generally interface name "eth0".
* *
* Return value :
* int - SUCCESS (0) /FAILURE (-1)/INVALID INPUT (-2).
* ****************************************************************************


<http://clients.rediff.com/signature/track_sig.asp>

int
getInterfaceName(int if_index, char *if_name)
{
int ret_val;
/* sanity check */
if( if_name == NULL )
{
printf(" Invalid Input [if_name] \n");
return -2;


       }

/* if_name should be sufficiently long to accomodate if_name returned, otherwise it will crash */

req.ifr_ifindex = if_index;
ret_val = ioctl(sock_fd, SIOCGIFNAME, &req);
if( ret_val != -1)
{
strcpy(if_name,req.ifr_name);
return 1;
}
else
{
strcpy(if_name,"");
return -1;
}
}



* Note:
* For using the API's defined here , you would need a valid socket
* descriptor created using the socket() system call. It does'nt matter
* whether it is a TCP or UDP socket descriptor. * Argument checking has to be done by the user making the call :-)
* Needs some testing !
* ****************************************************************************
*/




cheers,
Amith


[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