[net][netdev] Improve netdev DNS setting function
This commit is contained in:
parent
ca7ebe6175
commit
126fa9b561
|
@ -144,10 +144,10 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
|
|||
}
|
||||
|
||||
#ifdef RT_LWIP_DNS
|
||||
static int lwip_netdev_set_dns_server(struct netdev *netif, ip_addr_t *dns_server)
|
||||
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
|
||||
{
|
||||
extern void set_dns(char* dns_server);
|
||||
set_dns(ipaddr_ntoa(dns_server));
|
||||
extern void set_dns(uint8_t dns_num, char* dns_server);
|
||||
set_dns(dns_num, ipaddr_ntoa(dns_server));
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* RT_LWIP_DNS */
|
||||
|
@ -729,13 +729,13 @@ FINSH_FUNCTION_EXPORT(set_if, set network interface address);
|
|||
|
||||
#if LWIP_DNS
|
||||
#include <lwip/dns.h>
|
||||
void set_dns(char* dns_server)
|
||||
void set_dns(uint8_t dns_num, char* dns_server)
|
||||
{
|
||||
struct ip_addr addr;
|
||||
|
||||
if ((dns_server != RT_NULL) && ipaddr_aton(dns_server, &addr))
|
||||
{
|
||||
dns_setserver(0, &addr);
|
||||
dns_setserver(dns_num, &addr);
|
||||
}
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(set_dns, set DNS server address);
|
||||
|
|
|
@ -152,10 +152,10 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
|
|||
}
|
||||
|
||||
#ifdef RT_LWIP_DNS
|
||||
static int lwip_netdev_set_dns_server(struct netdev *netif, ip_addr_t *dns_server)
|
||||
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
|
||||
{
|
||||
extern void set_dns(char* dns_server);
|
||||
set_dns(ipaddr_ntoa(dns_server));
|
||||
extern void set_dns(uint8_t dns_num, char* dns_server);
|
||||
set_dns(dns_num, ipaddr_ntoa(dns_server));
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* RT_LWIP_DNS */
|
||||
|
@ -758,13 +758,13 @@ FINSH_FUNCTION_EXPORT(set_if, set network interface address);
|
|||
|
||||
#if LWIP_DNS
|
||||
#include <lwip/dns.h>
|
||||
void set_dns(char* dns_server)
|
||||
void set_dns(uint8_t dns_num, char* dns_server)
|
||||
{
|
||||
ip_addr_t addr;
|
||||
|
||||
if ((dns_server != RT_NULL) && ipaddr_aton(dns_server, &addr))
|
||||
{
|
||||
dns_setserver(0, &addr);
|
||||
dns_setserver(dns_num, &addr);
|
||||
}
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(set_dns, set DNS server address);
|
||||
|
|
|
@ -153,10 +153,10 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
|
|||
}
|
||||
|
||||
#ifdef RT_LWIP_DNS
|
||||
static int lwip_netdev_set_dns_server(struct netdev *netif, ip_addr_t *dns_server)
|
||||
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
|
||||
{
|
||||
extern void set_dns(char* dns_server);
|
||||
set_dns(ipaddr_ntoa(dns_server));
|
||||
extern void set_dns(uint8_t dns_num, char* dns_server);
|
||||
set_dns(dns_num, ipaddr_ntoa(dns_server));
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* RT_LWIP_DNS */
|
||||
|
@ -762,13 +762,13 @@ FINSH_FUNCTION_EXPORT(set_if, set network interface address);
|
|||
|
||||
#if LWIP_DNS
|
||||
#include <lwip/dns.h>
|
||||
void set_dns(char* dns_server)
|
||||
void set_dns(uint8_t dns_num, char* dns_server)
|
||||
{
|
||||
ip_addr_t addr;
|
||||
|
||||
if ((dns_server != RT_NULL) && ipaddr_aton(dns_server, &addr))
|
||||
{
|
||||
dns_setserver(0, &addr);
|
||||
dns_setserver(dns_num, &addr);
|
||||
}
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(set_dns, set DNS server address);
|
||||
|
|
|
@ -119,7 +119,7 @@ struct netdev_ops
|
|||
|
||||
/* set network interface device address information operations */
|
||||
int (*set_addr_info)(struct netdev *netdev, ip_addr_t *ip_addr, ip_addr_t *netmask, ip_addr_t *gw);
|
||||
int (*set_dns_server)(struct netdev *netdev, ip_addr_t *dns_server);
|
||||
int (*set_dns_server)(struct netdev *netdev, uint8_t dns_num, ip_addr_t *dns_server);
|
||||
int (*set_dhcp)(struct netdev *netdev, rt_bool_t is_enabled);
|
||||
|
||||
/* set network interface device common network interface device operations */
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
|
@ -510,7 +511,7 @@ int netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_
|
|||
}
|
||||
|
||||
/* execute network interface device set DNS server address operations */
|
||||
return netdev->ops->set_dns_server(netdev, (ip_addr_t *)dns_server);
|
||||
return netdev->ops->set_dns_server(netdev, dns_num, (ip_addr_t *)dns_server);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1028,7 +1029,7 @@ static void netdev_list_dns(void)
|
|||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
static void netdev_set_dns(char *netdev_name, char *dns_server)
|
||||
static void netdev_set_dns(char *netdev_name, uint8_t dns_num, char *dns_server)
|
||||
{
|
||||
struct netdev *netdev = RT_NULL;
|
||||
ip_addr_t dns_addr;
|
||||
|
@ -1041,7 +1042,7 @@ static void netdev_set_dns(char *netdev_name, char *dns_server)
|
|||
}
|
||||
|
||||
inet_aton(dns_server, &dns_addr);
|
||||
netdev_set_dns_server(netdev, 0, &dns_addr);
|
||||
netdev_set_dns_server(netdev, dns_num, &dns_addr);
|
||||
|
||||
rt_kprintf("set network interface device(%s) dns server #0: %s\n", netdev_name, dns_server);
|
||||
}
|
||||
|
@ -1054,11 +1055,16 @@ int netdev_dns(int argc, char **argv)
|
|||
}
|
||||
else if (argc == 3)
|
||||
{
|
||||
netdev_set_dns(argv[1], argv[2]);
|
||||
netdev_set_dns(argv[1], 0, argv[2]);
|
||||
}
|
||||
else if (argc == 4)
|
||||
{
|
||||
netdev_set_dns(argv[1], atoi(argv[2]), argv[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("bad parameter! e.g: dns name 114.114.114.114\n");
|
||||
rt_kprintf("bad parameter! input: dns <netdev_name> [dns_num] <dns_server>\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue