Преглед изворни кода

Eliminate confusion between functions that return pointers and

functions that return status codes.

Zero the DHCP packet buffer *before* creating the options structures
inside it.
tags/v0.9.3
Michael Brown пре 18 година
родитељ
комит
e8daeb62b1
1 измењених фајлова са 17 додато и 15 уклоњено
  1. 17
    15
      src/net/udp/dhcp.c

+ 17
- 15
src/net/udp/dhcp.c Прегледај датотеку

@@ -231,6 +231,16 @@ static int create_dhcp_packet ( struct dhcp_session *dhcp, uint8_t msgtype,
231 231
 	struct dhcphdr *dhcphdr = data;
232 232
 	static const uint8_t overloading = ( DHCP_OPTION_OVERLOAD_FILE |
233 233
 					     DHCP_OPTION_OVERLOAD_SNAME );
234
+	int rc;
235
+
236
+	/* Initialise DHCP packet content */
237
+	memset ( dhcphdr, 0, max_len );
238
+	dhcphdr->xid = dhcp->xid;
239
+	dhcphdr->magic = htonl ( DHCP_MAGIC_COOKIE );
240
+	dhcphdr->htype = ntohs ( dhcp->netdev->ll_protocol->ll_proto );
241
+	dhcphdr->hlen = dhcp->netdev->ll_protocol->ll_addr_len;
242
+	memcpy ( dhcphdr->chaddr, dhcp->netdev->ll_addr, dhcphdr->hlen );
243
+	dhcphdr->op = dhcp_op[msgtype];
234 244
 
235 245
 	/* Initialise DHCP packet structure */
236 246
 	dhcppkt->dhcphdr = dhcphdr;
@@ -243,25 +253,17 @@ static int create_dhcp_packet ( struct dhcp_session *dhcp, uint8_t msgtype,
243 253
 	init_dhcp_options ( &dhcppkt->options[OPTS_SNAME], dhcphdr->sname,
244 254
 			    sizeof ( dhcphdr->sname ) );
245 255
 	
246
-	/* Initialise DHCP packet content */
247
-	memset ( dhcphdr, 0, max_len );
248
-	dhcphdr->xid = dhcp->xid;
249
-	dhcphdr->magic = htonl ( DHCP_MAGIC_COOKIE );
250
-	dhcphdr->htype = ntohs ( dhcp->netdev->ll_protocol->ll_proto );
251
-	dhcphdr->hlen = dhcp->netdev->ll_protocol->ll_addr_len;
252
-	memcpy ( dhcphdr->chaddr, dhcp->netdev->ll_addr, dhcphdr->hlen );
253
-	dhcphdr->op = dhcp_op[msgtype];
254
-
255 256
 	/* Set DHCP_OPTION_OVERLOAD option within the main options block */
256
-	if ( ! set_dhcp_option ( &dhcppkt->options[OPTS_MAIN],
257
-				 DHCP_OPTION_OVERLOAD, &overloading,
258
-				 sizeof ( overloading ) ) )
257
+	if ( set_dhcp_option ( &dhcppkt->options[OPTS_MAIN],
258
+			       DHCP_OPTION_OVERLOAD, &overloading,
259
+			       sizeof ( overloading ) ) == NULL )
259 260
 		return -ENOSPC;
260 261
 
261 262
 	/* Set DHCP_MESSAGE_TYPE option */
262
-	if ( ! set_dhcp_packet_option ( dhcppkt, DHCP_MESSAGE_TYPE,
263
-					&msgtype, sizeof ( msgtype ) ) )
264
-		return -ENOSPC;
263
+	if ( ( rc = set_dhcp_packet_option ( dhcppkt, DHCP_MESSAGE_TYPE,
264
+					     &msgtype,
265
+					     sizeof ( msgtype ) ) ) != 0 )
266
+		return rc;
265 267
 
266 268
 	return 0;
267 269
 }

Loading…
Откажи
Сачувај