mirror of https://github.com/ipxe/ipxe.git
Change dhcp_num_option() to return the numerical value directly.
parent
d8b51332c6
commit
bd0c8b21ad
|
@ -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 ;
|
for ( data = option->data.bytes ;
|
||||||
data < ( option->data.bytes + option->len ) ; data++ )
|
data < ( option->data.bytes + option->len ) ; data++ )
|
||||||
tmp = ( ( tmp << 8 ) | *data );
|
value = ( ( value << 8 ) | *data );
|
||||||
*value = tmp;
|
}
|
||||||
return 0;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue