david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Change dhcp_num_option() to return the numerical value directly.

This commit is contained in:
Michael Brown 2006-06-28 12:16:41 +00:00
parent d8b51332c6
commit bd0c8b21ad
1 changed files with 14 additions and 18 deletions

View File

@ -37,34 +37,30 @@ static LIST_HEAD ( option_blocks );
* Obtain value of a numerical DHCP option * Obtain value of a numerical DHCP option
* *
* @v option DHCP option, or NULL * @v option DHCP option, or NULL
* @v value Unsigned long for storing the result * @ret value Numerical value of the option, or 0
* @ret rc Return status code
* *
* Parses the numerical value from a DHCP option, if present. It is * Parses the numerical value from a DHCP option, if present. It is
* permitted to call dhcp_num_option() with @c option set to NULL; in * permitted to call dhcp_num_option() with @c option set to NULL; in
* this case the result value will not be modified and an error will * this case 0 will be returned.
* be returned.
* *
* The caller does not specify the size of the DHCP option data; this * The caller does not specify the size of the DHCP option data; this
* is implied by the length field stored within the DHCP option * is implied by the length field stored within the DHCP option
* itself. * itself.
*/ */
int dhcp_num_option ( struct dhcp_option *option, unsigned long *value ) { unsigned long dhcp_num_option ( struct dhcp_option *option ) {
unsigned long value = 0;
uint8_t *data; uint8_t *data;
unsigned long tmp = 0;
if ( ! option ) if ( option ) {
return -EINVAL; /* This is actually smaller code than using htons()
* etc., and will also cope well with malformed
/* This is actually smaller code than using htons() etc., and * options (such as zero-length options).
* will also cope well with malformed options (such as */
* zero-length options). for ( data = option->data.bytes ;
*/ data < ( option->data.bytes + option->len ) ; data++ )
for ( data = option->data.bytes ; value = ( ( value << 8 ) | *data );
data < ( option->data.bytes + option->len ) ; data++ ) }
tmp = ( ( tmp << 8 ) | *data ); return value;
*value = tmp;
return 0;
} }
/** /**