mirror of https://github.com/ipxe/ipxe.git
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.pull/1/head
parent
3369f93036
commit
e8daeb62b1
|
@ -231,6 +231,16 @@ static int create_dhcp_packet ( struct dhcp_session *dhcp, uint8_t msgtype,
|
||||||
struct dhcphdr *dhcphdr = data;
|
struct dhcphdr *dhcphdr = data;
|
||||||
static const uint8_t overloading = ( DHCP_OPTION_OVERLOAD_FILE |
|
static const uint8_t overloading = ( DHCP_OPTION_OVERLOAD_FILE |
|
||||||
DHCP_OPTION_OVERLOAD_SNAME );
|
DHCP_OPTION_OVERLOAD_SNAME );
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Initialise DHCP packet content */
|
||||||
|
memset ( dhcphdr, 0, max_len );
|
||||||
|
dhcphdr->xid = dhcp->xid;
|
||||||
|
dhcphdr->magic = htonl ( DHCP_MAGIC_COOKIE );
|
||||||
|
dhcphdr->htype = ntohs ( dhcp->netdev->ll_protocol->ll_proto );
|
||||||
|
dhcphdr->hlen = dhcp->netdev->ll_protocol->ll_addr_len;
|
||||||
|
memcpy ( dhcphdr->chaddr, dhcp->netdev->ll_addr, dhcphdr->hlen );
|
||||||
|
dhcphdr->op = dhcp_op[msgtype];
|
||||||
|
|
||||||
/* Initialise DHCP packet structure */
|
/* Initialise DHCP packet structure */
|
||||||
dhcppkt->dhcphdr = dhcphdr;
|
dhcppkt->dhcphdr = dhcphdr;
|
||||||
|
@ -243,25 +253,17 @@ static int create_dhcp_packet ( struct dhcp_session *dhcp, uint8_t msgtype,
|
||||||
init_dhcp_options ( &dhcppkt->options[OPTS_SNAME], dhcphdr->sname,
|
init_dhcp_options ( &dhcppkt->options[OPTS_SNAME], dhcphdr->sname,
|
||||||
sizeof ( dhcphdr->sname ) );
|
sizeof ( dhcphdr->sname ) );
|
||||||
|
|
||||||
/* Initialise DHCP packet content */
|
|
||||||
memset ( dhcphdr, 0, max_len );
|
|
||||||
dhcphdr->xid = dhcp->xid;
|
|
||||||
dhcphdr->magic = htonl ( DHCP_MAGIC_COOKIE );
|
|
||||||
dhcphdr->htype = ntohs ( dhcp->netdev->ll_protocol->ll_proto );
|
|
||||||
dhcphdr->hlen = dhcp->netdev->ll_protocol->ll_addr_len;
|
|
||||||
memcpy ( dhcphdr->chaddr, dhcp->netdev->ll_addr, dhcphdr->hlen );
|
|
||||||
dhcphdr->op = dhcp_op[msgtype];
|
|
||||||
|
|
||||||
/* Set DHCP_OPTION_OVERLOAD option within the main options block */
|
/* Set DHCP_OPTION_OVERLOAD option within the main options block */
|
||||||
if ( ! set_dhcp_option ( &dhcppkt->options[OPTS_MAIN],
|
if ( set_dhcp_option ( &dhcppkt->options[OPTS_MAIN],
|
||||||
DHCP_OPTION_OVERLOAD, &overloading,
|
DHCP_OPTION_OVERLOAD, &overloading,
|
||||||
sizeof ( overloading ) ) )
|
sizeof ( overloading ) ) == NULL )
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
|
|
||||||
/* Set DHCP_MESSAGE_TYPE option */
|
/* Set DHCP_MESSAGE_TYPE option */
|
||||||
if ( ! set_dhcp_packet_option ( dhcppkt, DHCP_MESSAGE_TYPE,
|
if ( ( rc = set_dhcp_packet_option ( dhcppkt, DHCP_MESSAGE_TYPE,
|
||||||
&msgtype, sizeof ( msgtype ) ) )
|
&msgtype,
|
||||||
return -ENOSPC;
|
sizeof ( msgtype ) ) ) != 0 )
|
||||||
|
return rc;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue