Browse Source

Change dhcp_num_option() to return the numerical value directly.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
bd0c8b21ad
1 changed files with 15 additions and 19 deletions
  1. 15
    19
      src/net/dhcpopts.c

+ 15
- 19
src/net/dhcpopts.c View File

@@ -37,34 +37,30 @@ static LIST_HEAD ( option_blocks );
37 37
  * Obtain value of a numerical DHCP option
38 38
  *
39 39
  * @v option		DHCP option, or NULL
40
- * @v value		Unsigned long for storing the result
41
- * @ret rc		Return status code
40
+ * @ret value		Numerical value of the option, or 0
42 41
  *
43 42
  * Parses the numerical value from a DHCP option, if present.  It is
44 43
  * permitted to call dhcp_num_option() with @c option set to NULL; in
45
- * this case the result value will not be modified and an error will
46
- * be returned.
44
+ * this case 0 will be returned.
47 45
  *
48 46
  * The caller does not specify the size of the DHCP option data; this
49 47
  * is implied by the length field stored within the DHCP option
50 48
  * itself.
51 49
  */
52
-int dhcp_num_option ( struct dhcp_option *option, unsigned long *value ) {
50
+unsigned long dhcp_num_option ( struct dhcp_option *option ) {
51
+	unsigned long value = 0;
53 52
 	uint8_t *data;
54
-	unsigned long tmp = 0;
55
-
56
-	if ( ! option )
57
-		return -EINVAL;
58
-
59
-	/* This is actually smaller code than using htons() etc., and
60
-	 * will also cope well with malformed options (such as
61
-	 * zero-length options).
62
-	 */
63
-	for ( data = option->data.bytes ;
64
-	      data < ( option->data.bytes + option->len ) ; data++ )
65
-		tmp = ( ( tmp << 8 ) | *data );
66
-	*value = tmp;
67
-	return 0;
53
+
54
+	if ( option ) {
55
+		/* This is actually smaller code than using htons()
56
+		 * etc., and will also cope well with malformed
57
+		 * options (such as zero-length options).
58
+		 */
59
+		for ( data = option->data.bytes ;
60
+		      data < ( option->data.bytes + option->len ) ; data++ )
61
+			value = ( ( value << 8 ) | *data );
62
+	}
63
+	return value;
68 64
 }
69 65
 
70 66
 /**

Loading…
Cancel
Save