summaryrefslogtreecommitdiffstats
path: root/src/net/udp/dhcp.c
diff options
context:
space:
mode:
authorMichael Brown2006-07-19 20:11:31 +0200
committerMichael Brown2006-07-19 20:11:31 +0200
commite8daeb62b1f6ae1390320efd2dddb6487f7c8c22 (patch)
treed7476a9ba134cd3b68cf11bd09eb00e93e835460 /src/net/udp/dhcp.c
parentAdd block identification to debug messages (diff)
downloadipxe-e8daeb62b1f6ae1390320efd2dddb6487f7c8c22.tar.gz
ipxe-e8daeb62b1f6ae1390320efd2dddb6487f7c8c22.tar.xz
ipxe-e8daeb62b1f6ae1390320efd2dddb6487f7c8c22.zip
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.
Diffstat (limited to 'src/net/udp/dhcp.c')
-rw-r--r--src/net/udp/dhcp.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c
index f5a8f08d..a2b3ed50 100644
--- a/src/net/udp/dhcp.c
+++ b/src/net/udp/dhcp.c
@@ -231,6 +231,16 @@ static int create_dhcp_packet ( struct dhcp_session *dhcp, uint8_t msgtype,
struct dhcphdr *dhcphdr = data;
static const uint8_t overloading = ( DHCP_OPTION_OVERLOAD_FILE |
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 */
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,
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 */
- if ( ! set_dhcp_option ( &dhcppkt->options[OPTS_MAIN],
- DHCP_OPTION_OVERLOAD, &overloading,
- sizeof ( overloading ) ) )
+ if ( set_dhcp_option ( &dhcppkt->options[OPTS_MAIN],
+ DHCP_OPTION_OVERLOAD, &overloading,
+ sizeof ( overloading ) ) == NULL )
return -ENOSPC;
/* Set DHCP_MESSAGE_TYPE option */
- if ( ! set_dhcp_packet_option ( dhcppkt, DHCP_MESSAGE_TYPE,
- &msgtype, sizeof ( msgtype ) ) )
- return -ENOSPC;
+ if ( ( rc = set_dhcp_packet_option ( dhcppkt, DHCP_MESSAGE_TYPE,
+ &msgtype,
+ sizeof ( msgtype ) ) ) != 0 )
+ return rc;
return 0;
}