char * get_network_setting(const char *config) { char * ret = 0; struct mode_list_elem *data; if(!strcmp(config, NETWORK_IP_KEY)) { ret = get_network_ip(); if(!ret) ret = strdup("192.168.2.15"); } else if(!strcmp(config, NETWORK_INTERFACE_KEY)) { data = get_usb_mode_data(); if(data) { if(data->network_interface) { ret = strdup(data->network_interface); goto end; } } ret = get_network_interface(); if(!ret) ret = strdup("usb0"); } else if(!strcmp(config, NETWORK_GATEWAY_KEY)) return(get_network_gateway()); else /* no matching keys, return error */ return(NULL); end: return(ret); }
/** * Update the network interface with the new setting if connected. * */ int usb_network_update(void) { struct mode_list_elem * data; if(!get_usb_connection_state()) return(0); data = get_usb_mode_data(); if(data == NULL) return(0); if(data->network) { usb_network_down(data); usb_network_up(data); return(0); } else return(0); }