11#include <stdlib.h>
22#include <string.h>
3-
4-
5-
63#include "lwipDhcpServer.h"
74#include "lwipDhcpServerPriv.h"
85
@@ -11,37 +8,12 @@ static const u32_t magic_cookie = 0x63538263;
118
129#define BOOTP_BROADCAST 0x8000
1310
14- #define DHCP_REQUEST 1
15- #define DHCP_REPLY 2
1611#define DHCP_HTYPE_ETHERNET 1
17- #define DHCP_HLEN_ETHERNET 6
18- #define DHCP_MSG_LEN 236
1912
2013#define DHCPS_SERVER_PORT 67
2114#define DHCPS_CLIENT_PORT 68
2215
23- #define DHCPDISCOVER 1
24- #define DHCPOFFER 2
25- #define DHCPREQUEST 3
26- #define DHCPDECLINE 4
27- #define DHCPACK 5
28- #define DHCPNAK 6
29- #define DHCPRELEASE 7
30-
31- #define DHCP_OPTION_SUBNET_MASK 1
32- #define DHCP_OPTION_ROUTER 3
33- #define DHCP_OPTION_DNS_SERVER 6
34- #define DHCP_OPTION_REQ_IPADDR 50
35- #define DHCP_OPTION_LEASE_TIME 51
36- #define DHCP_OPTION_MSG_TYPE 53
37- #define DHCP_OPTION_SERVER_ID 54
38- #define DHCP_OPTION_INTERFACE_MTU 26
3916#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31
40- #define DHCP_OPTION_BROADCAST_ADDRESS 28
41- #define DHCP_OPTION_REQ_LIST 55
42- #define DHCP_OPTION_END 255
43-
44-
4517
4618#ifdef DHCPS_DEBUG
4719/* function defined in CNetIf.cpp */
@@ -184,7 +156,7 @@ void dhcps_set_option_info(uint8_t op_id, void *opt_info, u32_t opt_len)
184156*******************************************************************************/
185157static uint8_t * add_msg_type (uint8_t * optptr , uint8_t type )
186158{
187- * optptr ++ = DHCP_OPTION_MSG_TYPE ;
159+ * optptr ++ = DHCP_OPTION_MESSAGE_TYPE ;
188160 * optptr ++ = 1 ;
189161 * optptr ++ = type ;
190162 return optptr ;
@@ -253,7 +225,7 @@ static uint8_t *add_offer_options(uint8_t *optptr)
253225 }
254226
255227
256- * optptr ++ = DHCP_OPTION_INTERFACE_MTU ;
228+ * optptr ++ = DHCP_OPTION_MTU ;
257229 * optptr ++ = 2 ;
258230 * optptr ++ = 0x05 ;
259231 * optptr ++ = 0xdc ;
@@ -294,7 +266,7 @@ static uint8_t *add_end(uint8_t *optptr)
294266*******************************************************************************/
295267static void create_msg (struct dhcps_msg * m )
296268{
297- m -> op = DHCP_REPLY ;
269+ m -> op = DHCP_BOOTREPLY ;
298270
299271 m -> htype = DHCP_HTYPE_ETHERNET ;
300272
@@ -348,7 +320,7 @@ static void send_offer(struct dhcps_msg *msg, uint16_t len)
348320 err_t SendOffer_err_t ;
349321 #endif
350322 create_msg (msg );
351- end = add_msg_type (& msg -> options [4 ], DHCPOFFER );
323+ end = add_msg_type (& msg -> options [4 ], DHCP_OFFER );
352324 end = add_offer_options (end );
353325 end = add_end (end );
354326
@@ -418,7 +390,7 @@ static void send_nak(struct dhcps_msg *m, uint16_t len)
418390 #endif
419391 create_msg (m );
420392
421- end = add_msg_type (& m -> options [4 ], DHCPNAK );
393+ end = add_msg_type (& m -> options [4 ], DHCP_NAK );
422394 end = add_end (end );
423395
424396 p = dhcps_pbuf_alloc (len );
@@ -482,7 +454,7 @@ static void send_ack(struct dhcps_msg *m, uint16_t len)
482454 err_t SendAck_err_t ;
483455 create_msg (m );
484456
485- end = add_msg_type (& m -> options [4 ], DHCPACK );
457+ end = add_msg_type (& m -> options [4 ], DHCP_ACK );
486458 end = add_offer_options (end );
487459 end = add_end (end );
488460
@@ -564,10 +536,10 @@ static uint8_t parse_options(uint8_t *OptionsPtr, int16_t len)
564536 DHCPS_LOG ("dhcps: (int16_t)*optptr = %d\n" , (int16_t )* OptionsPtr );
565537 #endif
566538 switch ((int16_t ) * OptionsPtr ) {
567- case DHCP_OPTION_MSG_TYPE : //53
539+ case DHCP_OPTION_MESSAGE_TYPE : //53
568540 type = * (OptionsPtr + 2 );
569541 break ;
570- case DHCP_OPTION_REQ_IPADDR ://50
542+ case DHCP_OPTION_REQUESTED_IP ://50
571543 s .state = DHCPS_STATE_ACK ;
572544 break ;
573545 case DHCP_OPTION_END : {
@@ -583,26 +555,26 @@ static uint8_t parse_options(uint8_t *OptionsPtr, int16_t len)
583555 }
584556
585557 switch (type ) {
586- case DHCPDISCOVER ://1
558+ case DHCP_DISCOVER ://1
587559 #if DHCPS_DEBUG
588560 DHCPS_LOG ("dhcps: DHCPD_STATE_DHCPDISCOVER -- SEND_OFFER\n" );
589561 #endif
590562 s .state = DHCPS_STATE_OFFER ;
591563 break ;
592- case DHCPREQUEST ://3
564+ case DHCP_REQUEST ://3
593565 #if DHCPS_DEBUG
594566 DHCPS_LOG ("dhcps: DHCPD_STATE_DHCPREQUEST -- SEND_ACK\n" );
595567 #endif
596568 s .state = DHCPS_STATE_ACK ;
597569
598570 break ;
599- case DHCPDECLINE ://4
571+ case DHCP_DECLINE ://4
600572 s .state = DHCPS_STATE_IDLE ;
601573 #if DHCPS_DEBUG
602574 DHCPS_LOG ("dhcps: DHCPD_STATE_IDLE\n" );
603575 #endif
604576 break ;
605- case DHCPRELEASE ://7
577+ case DHCP_RELEASE ://7
606578 s .state = DHCPS_STATE_RELEASE ;
607579 #if DHCPS_DEBUG
608580 DHCPS_LOG ("dhcps: DHCPD_STATE_IDLE\n" );
0 commit comments