Browse Source

[dhcp] Accept filename via DHCP option 67 as well as BOOTP filename field

Allow options with dedicated BOOTP fields to fall back to using the
equivalent DHCP option if the relevant field is empty.
tags/v0.9.8
Michael Brown 15 years ago
parent
commit
b363d19a16
1 changed files with 8 additions and 4 deletions
  1. 8
    4
      src/net/dhcppkt.c

+ 8
- 4
src/net/dhcppkt.c View File

@@ -155,6 +155,8 @@ int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
155 155
 		memset ( field_data, 0, field->len );
156 156
 		memcpy ( dhcp_packet_field ( dhcppkt->dhcphdr, field ),
157 157
 			 data, len );
158
+		/* Erase any equivalent option from the options block */
159
+		dhcpopt_store ( &dhcppkt->options, tag, NULL, 0 );
158 160
 		return 0;
159 161
 	}
160 162
 
@@ -181,14 +183,16 @@ int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
181 183
 		    void *data, size_t len ) {
182 184
 	struct dhcp_packet_field *field;
183 185
 	void *field_data;
184
-	size_t field_len;
186
+	size_t field_len = 0;
185 187
 	
186
-	/* If this is a special field, return it */
188
+	/* Identify special field, if any */
187 189
 	if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
188 190
 		field_data = dhcp_packet_field ( dhcppkt->dhcphdr, field );
189 191
 		field_len = field->used_len ( field_data, field->len );
190
-		if ( ! field_len )
191
-			return -ENOENT;
192
+	}
193
+
194
+	/* Return special field, if it exists and is populated */
195
+	if ( field_len ) {
192 196
 		if ( len > field_len )
193 197
 			len = field_len;
194 198
 		memcpy ( data, field_data, len );

Loading…
Cancel
Save