PDA

View Full Version : dev_get_by_name("eth0") crashes if eth0 not bound?


nregi
07-09-2002, 01:06 AM
Hello,
I am using the function dev_get_by_name() to get IP information relating to an interface in a kernel module.

For example:
The eth0 interface is bound to IP by querying a DHCP server for IP. Sometimes, if the DHCP server is not up, the eth0 interface is not bound to IP, at this point if my module uses the function dev_get_by_name("eth0") , the module crashes and I have to reboot the machine.

Is there a way I can test to see if eth0 does exist on the system before calling dev_get_by_name()?


Thanks in advance.

EscapeCharacter
07-10-2002, 03:08 AM
from the kernel documentation is looks like dev_get_by_name returns NULL if the device is not found so i guess check if its == NULL would be enough to fix that(i really have no idea never done this before).

some thing like this should suffice(sp?)

struct net_device *test = dev_get_by_name("eth0")
if(test == NULL){
//what ever you want
}
else{
//do something cool;
}

nregi
07-10-2002, 06:05 PM
Thank you for the response,
I found the problem,
I was testing the NULL condition, but the error is caused referencing sub items in "test" where I failed to test NULL condition.