@@ -87,49 +87,46 @@ void dhcp_request(uint8_t *requested_ip) {
8787
8888 uint8_t * options = packet .options ;
8989
90- // Magic cookie
90+ // magic cookie
9191 * ((uint32_t * )(options )) = htonl (DHCP_MAGIC_COOKIE );
9292 options += 4 ;
9393
94- // Message type (REQUEST)
94+ // message type (REQUEST)
9595 uint8_t msg_type = DHCP_REQUEST ;
9696 options = add_dhcp_option (options , DHCP_OPT_MSG_TYPE , 1 , & msg_type );
9797
98- // Client identifier
98+ // client identifier
9999 uint8_t client_id [7 ];
100- client_id [0 ] = 1 ; // Hardware type (Ethernet)
100+ client_id [0 ] = 0x1 ; // hardware type (Ethernet)
101101 get_mac_addr (client_id + 1 );
102102 options = add_dhcp_option (options , DHCP_OPT_CLIENT_ID , 7 , client_id );
103103
104- // Requested IP address
105104 if (requested_ip ) {
106105 options = add_dhcp_option (options , DHCP_OPT_REQUESTED_IP , 4 , requested_ip );
107106 }
108107
109- // Server identifier (if we have it)
108+ // server identifier (if we have it)
110109 if (dhcp_server_ip != 0 ) {
111110 options =
112111 add_dhcp_option (options , 54 , 4 , & dhcp_server_ip ); // 54 = Server ID
113112 }
114113
115- // Host name (optional)
114+ // host name (optional)
116115 char hostname [] = "os-dev" ;
117116 options =
118117 add_dhcp_option (options , DHCP_OPT_HOST_NAME , strlen (hostname ), hostname );
119118
120- // Parameter request list
119+ // parameter request list
121120 uint8_t params [] = {
122- DHCP_OPT_SUBNET_MASK , // Subnet mask
123- DHCP_OPT_ROUTER , // Router
121+ DHCP_OPT_SUBNET_MASK , // subnet mask
122+ DHCP_OPT_ROUTER , // router
124123 DHCP_OPT_DNS // DNS server
125124 };
126125 options =
127126 add_dhcp_option (options , DHCP_OPT_PARAM_REQ_LIST , sizeof (params ), params );
128127
129- // End option
130128 * (options ++ ) = DHCP_OPT_END ;
131129
132- // Send the packet
133130 udp_send_packet (dst_ip , DHCP_CLIENT , DHCP_SERVER , & packet ,
134131 sizeof (dhcp_packet_t ));
135132}
@@ -139,7 +136,7 @@ void *get_dhcp_option(dhcp_packet_t *packet, uint8_t type) {
139136 return NULL ;
140137 }
141138
142- uint8_t * options = packet -> options + 4 ; // Skip magic cookie
139+ uint8_t * options = packet -> options + 4 ; // skip magic cookie
143140
144141 while (options < packet -> options + sizeof (packet -> options )) {
145142 uint8_t curr_type = * options ;
@@ -174,10 +171,9 @@ void dhcp_handle_packet(dhcp_packet_t *packet) {
174171 return ;
175172 }
176173
177- // Get message type
178174 uint8_t * type_ptr = get_dhcp_option (packet , DHCP_OPT_MSG_TYPE );
179175 if (!type_ptr ) {
180- return ; // No message type option
176+ return ;
181177 }
182178
183179 uint8_t msg_type = * type_ptr ;
0 commit comments