Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[network] Check configured interface, fallback to usb0 if it does not…
… exist Fixes: JB#21324

If for some reason the configured network interface does not exist. (As
rndis0 on mako/N4, while it is an android device, using the android gadget).
We test if the interface exists, if not we fall back on usb0.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Jul 9, 2014
1 parent 5da860b commit 10cab68
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/usb_moded-network.c
Expand Up @@ -74,9 +74,22 @@ static void free_ipforward_data (struct ipforward_data *ipforward)
}
}

/* This function checks if the configured interface exists */
static int check_interface(char *interface)
{
char command[32];
int ret = 0;

snprintf(command, 32, "ifconfig %s\n", interface );
ret = system(command);

return(ret);
}

static char* get_interface(struct mode_list_elem *data)
{
char *interface = NULL;
int check = 0;

if(data)
{
Expand All @@ -88,12 +101,20 @@ static char* get_interface(struct mode_list_elem *data)
else
interface = (char *)get_network_interface();

if(interface == NULL)
if(interface != NULL)
check = check_interface(interface);

if(interface == NULL && check != 0)
{
interface = malloc(sizeof(default_interface)*sizeof(char));
strncpy(interface, default_interface, sizeof(default_interface));
}

check = check_interface(interface);
if(check)
log_warning("Configured interface is incorrect, nor does usb0 exists. Check your config!\n");
/* TODO: Make it so that interface configuration gets skipped */

log_debug("interface = %s\n", interface);
return interface;
}
Expand Down

0 comments on commit 10cab68

Please sign in to comment.