probing.c, probing.h, dhcp.c: code fixes, use black list.
+ probing.h/free_net_devices(): - New function declared; + probing.c/free_net_devices(): - Reverse for get_net_devices() to avoid memory leaks; + probing.c/net_dev_black_list: - Wireless interfaces "wlan*" added to black list; + dhcp.c/perform_dhcp(): - No more restrict by interface name;
This commit is contained in:
parent
da664f7f9e
commit
485839e4cc
2
dhcp.c
2
dhcp.c
@ -520,10 +520,12 @@ enum return_type perform_dhcp(struct interface_info * intf)
|
|||||||
int num_options;
|
int num_options;
|
||||||
char requested_options[50];
|
char requested_options[50];
|
||||||
|
|
||||||
|
/* Now used net_dev_black_list[], see get_net_devices() in probing.c
|
||||||
if (strncmp(intf->device, "en", 2) & strncmp(intf->device, "eth", 3)) {
|
if (strncmp(intf->device, "en", 2) & strncmp(intf->device, "eth", 3)) {
|
||||||
stg1_info_message("DHCP available only for Ethernet networking.");
|
stg1_info_message("DHCP available only for Ethernet networking.");
|
||||||
return RETURN_ERROR;
|
return RETURN_ERROR;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
|
37
probing.c
37
probing.c
@ -60,6 +60,7 @@ struct net_description_elem
|
|||||||
char * intf_name;
|
char * intf_name;
|
||||||
char * intf_description;
|
char * intf_description;
|
||||||
};
|
};
|
||||||
|
static char * net_dev_black_list[] = {"lo", "wlan", /* add what you need here! */ NULL};
|
||||||
static struct net_description_elem net_descriptions[50];
|
static struct net_description_elem net_descriptions[50];
|
||||||
static int net_descr_number = 0;
|
static int net_descr_number = 0;
|
||||||
static char * intf_descr_for_discover = NULL;
|
static char * intf_descr_for_discover = NULL;
|
||||||
@ -292,21 +293,41 @@ static int net_device_available(char * device)
|
|||||||
char ** get_net_devices(void)
|
char ** get_net_devices(void)
|
||||||
{
|
{
|
||||||
DIR * sys_net;
|
DIR * sys_net;
|
||||||
char * tmp[50];
|
char * tmp[50] = {NULL};
|
||||||
struct dirent * ent;
|
struct dirent * ent;
|
||||||
int i = 0;
|
int drop, j, i = 0;
|
||||||
|
|
||||||
sys_net = opendir("/sys/class/net");
|
sys_net = opendir("/sys/class/net");
|
||||||
if (sys_net == NULL) return(strdup("\0"));
|
if (sys_net == NULL)
|
||||||
|
return memdup(tmp, sizeof(tmp[0]));
|
||||||
while ( ent = readdir(sys_net)){
|
while ((ent = readdir(sys_net)) != NULL)
|
||||||
if( !strcmp("lo", ent->d_name))continue;
|
{
|
||||||
if (net_device_available(ent->d_name)){
|
/* check interface name in black list */
|
||||||
|
for (drop=j=0; net_dev_black_list[j] != NULL; j++)
|
||||||
|
if (strncmp(ent->d_name, net_dev_black_list[j], strlen(net_dev_black_list[j])) == 0) {
|
||||||
|
drop = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!drop && net_device_available(ent->d_name)) {
|
||||||
tmp[i++] = strdup(ent->d_name);
|
tmp[i++] = strdup(ent->d_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmp[i++] = NULL;
|
tmp[i++] = NULL;
|
||||||
|
closedir(sys_net);
|
||||||
|
|
||||||
return memdup(tmp, sizeof(char *) * i);
|
return memdup(tmp, sizeof(tmp[0]) * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* reverse for get_net_devices() to avoid memory leaks */
|
||||||
|
void free_net_devices(char ** list)
|
||||||
|
{
|
||||||
|
char ** item;
|
||||||
|
|
||||||
|
for (item = list; *item; item++) {
|
||||||
|
free(*item);
|
||||||
|
*item = NULL;
|
||||||
|
}
|
||||||
|
free(list);
|
||||||
}
|
}
|
||||||
#endif /* DISABLE_NETWORK */
|
#endif /* DISABLE_NETWORK */
|
||||||
|
@ -27,6 +27,7 @@ enum media_type { CDROM, DISK, FLOPPY, TAPE, UNKNOWN_MEDIA };
|
|||||||
void get_medias(enum media_type media, char *** names, char *** models);
|
void get_medias(enum media_type media, char *** names, char *** models);
|
||||||
void probe_hiddev();
|
void probe_hiddev();
|
||||||
char ** get_net_devices(void);
|
char ** get_net_devices(void);
|
||||||
|
void free_net_devices(char ** list);
|
||||||
void net_discovered_interface(char * intf_name);
|
void net_discovered_interface(char * intf_name);
|
||||||
char * get_net_intf_description(char * intf_name);
|
char * get_net_intf_description(char * intf_name);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user