diff options
| author | Bernard Xiong <[email protected]> | 2018-05-09 22:19:38 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-05-09 22:19:38 +0800 |
| commit | 236fd82e5d7a405b175cb33c2f62421b20e0c9a0 (patch) | |
| tree | 96d2b2a4dcda04aacbfead56b9bd2d799b4608a9 /components | |
| parent | f64c0b2ad89a377fe7f6dd6a489246905c46856d (diff) | |
| parent | efadb37f4c8f872293d9bcb68cc9ec2a136d890d (diff) | |
Merge pull request #1418 from aozima/DHCPD
update DHCPD
Diffstat (limited to 'components')
| -rw-r--r-- | components/net/Kconfig | 10 | ||||
| -rw-r--r-- | components/net/lwip_dhcpd/dhcp_server.c | 40 | ||||
| -rw-r--r-- | components/net/lwip_dhcpd/dhcp_server.h | 2 |
3 files changed, 35 insertions, 17 deletions
diff --git a/components/net/Kconfig b/components/net/Kconfig index 53d85b516d..58a327ee1e 100644 --- a/components/net/Kconfig +++ b/components/net/Kconfig @@ -201,6 +201,16 @@ config LWIP_USING_DHCPD bool "Enable DHCP server" default n + if LWIP_USING_DHCPD + config DHCPD_SERVER_IP + string "DHCPD SERVER IP address" + default 192.168.169.1 + + config DHCPD_USING_ROUTER + bool "alloc gateway ip for router" + default y + endif + endif endmenu diff --git a/components/net/lwip_dhcpd/dhcp_server.c b/components/net/lwip_dhcpd/dhcp_server.c index d2e644cb93..0a3cca6d3e 100644 --- a/components/net/lwip_dhcpd/dhcp_server.c +++ b/components/net/lwip_dhcpd/dhcp_server.c @@ -41,33 +41,30 @@ #include <lwip/init.h> #if (LWIP_VERSION) >= 0x02000000U -#include <lwip/prot/dhcp.h> + #include <lwip/prot/dhcp.h> #endif /* DHCP server option */ /* allocated client ip range */ #ifndef DHCPD_CLIENT_IP_MIN -#define DHCPD_CLIENT_IP_MIN 2 + #define DHCPD_CLIENT_IP_MIN 2 #endif #ifndef DHCPD_CLIENT_IP_MAX -#define DHCPD_CLIENT_IP_MAX 254 + #define DHCPD_CLIENT_IP_MAX 254 #endif /* the DHCP server address */ -#ifndef DHCPD_SERVER_IPADDR0 -#define DHCPD_SERVER_IPADDR0 192UL -#define DHCPD_SERVER_IPADDR1 168UL -#define DHCPD_SERVER_IPADDR2 169UL -#define DHCPD_SERVER_IPADDR3 1UL +#ifndef DHCPD_SERVER_IP + #define DHCPD_SERVER_IP "192.168.169.1" #endif //#define DHCP_DEBUG_PRINTF #ifdef DHCP_DEBUG_PRINTF -#define DEBUG_PRINTF rt_kprintf("[DHCP] "); rt_kprintf + #define DEBUG_PRINTF rt_kprintf("[DHCP] "); rt_kprintf #else -#define DEBUG_PRINTF(...) + #define DEBUG_PRINTF(...) #endif /* DHCP_DEBUG_PRINTF */ /* we need some routines in the DHCP of lwIP */ @@ -79,11 +76,11 @@ #define BUFSZ 1024 #ifndef MAC_ADDR_LEN -#define MAC_ADDR_LEN 6 + #define MAC_ADDR_LEN 6 #endif #ifndef MAC_TABLE_LEN -#define MAC_TABLE_LEN 4 + #define MAC_TABLE_LEN 4 #endif struct mac_addr_t @@ -215,12 +212,26 @@ static void dhcpd_thread_entry(void *parameter) struct dhcp_msg *msg; int optval = 1; struct mac_addr_t mac_addr; + uint8_t DHCPD_SERVER_IPADDR0, DHCPD_SERVER_IPADDR1, DHCPD_SERVER_IPADDR2, DHCPD_SERVER_IPADDR3; /* get ethernet interface. */ netif = (struct netif *) parameter; RT_ASSERT(netif != RT_NULL); /* our DHCP server information */ + { +#if (LWIP_VERSION) >= 0x02000000U + ip4_addr_t addr; +#else + struct ip_addr addr; +#endif /* LWIP_VERSION */ + + ip4addr_aton(DHCPD_SERVER_IP, &addr); + DHCPD_SERVER_IPADDR0 = (ntohl(addr.addr) >> 24) & 0xFF; + DHCPD_SERVER_IPADDR1 = (ntohl(addr.addr) >> 16) & 0xFF; + DHCPD_SERVER_IPADDR2 = (ntohl(addr.addr) >> 8) & 0xFF; + DHCPD_SERVER_IPADDR3 = (ntohl(addr.addr) >> 0) & 0xFF; + } DEBUG_PRINTF("DHCP server IP: %d.%d.%d.%d client IP: %d.%d.%d.%d-%d\n", DHCPD_SERVER_IPADDR0, DHCPD_SERVER_IPADDR1, DHCPD_SERVER_IPADDR2, DHCPD_SERVER_IPADDR3, @@ -492,12 +503,9 @@ void dhcpd_start(const char *netif_name) { extern void set_if(const char *netif_name, const char *ip_addr, const char *gw_addr, const char *nm_addr); - char ip_str[4 * 4 + 1]; - dhcp_stop(netif); - sprintf(ip_str, "%d.%d.%d.%d", DHCPD_SERVER_IPADDR0, DHCPD_SERVER_IPADDR1, DHCPD_SERVER_IPADDR2, DHCPD_SERVER_IPADDR3); - set_if(netif_name, ip_str, "0.0.0.0", "255.255.255.0"); + set_if(netif_name, DHCPD_SERVER_IP, "0.0.0.0", "255.255.255.0"); netif_set_up(netif); } diff --git a/components/net/lwip_dhcpd/dhcp_server.h b/components/net/lwip_dhcpd/dhcp_server.h index 981337e6b1..03009b2eb1 100644 --- a/components/net/lwip_dhcpd/dhcp_server.h +++ b/components/net/lwip_dhcpd/dhcp_server.h @@ -31,7 +31,7 @@ #ifndef DHCPV4_SERVER_H__ #define DHCPV4_SERVER_H__ -void dhcpd_start(const char* netif_name); +void dhcpd_start(const char *netif_name); #endif |
