summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2006-07-20 16:13:11 +0200
committerMichael Brown2006-07-20 16:13:11 +0200
commitb26806cf182e67e759511ccc95e50fb165f305c9 (patch)
tree7b75dedd9c03609b8c20aad532ff255a1d7ea69f
parentPrint out the lease time, just to show how easy it is. (diff)
downloadipxe-b26806cf182e67e759511ccc95e50fb165f305c9.tar.gz
ipxe-b26806cf182e67e759511ccc95e50fb165f305c9.tar.xz
ipxe-b26806cf182e67e759511ccc95e50fb165f305c9.zip
Add dhcp_snprintf() for extracting DHCP string options.
-rw-r--r--src/include/gpxe/dhcp.h10
-rw-r--r--src/net/dhcpopts.c34
2 files changed, 44 insertions, 0 deletions
diff --git a/src/include/gpxe/dhcp.h b/src/include/gpxe/dhcp.h
index 51fd8195e..5f1943eba 100644
--- a/src/include/gpxe/dhcp.h
+++ b/src/include/gpxe/dhcp.h
@@ -160,6 +160,13 @@
*/
#define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 3 )
+/** BIOS drive number
+ *
+ * This is the drive number for a drive emulated via INT 13. 0x80 is
+ * the first hard disk, 0x81 is the second hard disk, etc.
+ */
+#define DHCP_EB_BIOS_DRIVE DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd )
+
/** Maximum normal DHCP option */
#define DHCP_MAX_OPTION 254
@@ -255,6 +262,7 @@ struct dhcp_option {
uint32_t dword;
struct in_addr in;
uint8_t bytes[0];
+ char string[0];
} data;
} __attribute__ (( packed ));
@@ -435,6 +443,8 @@ struct dhcp_session {
extern unsigned long dhcp_num_option ( struct dhcp_option *option );
extern void dhcp_ipv4_option ( struct dhcp_option *option,
struct in_addr *inp );
+extern int dhcp_snprintf ( char *buf, size_t size,
+ struct dhcp_option *option );
extern struct dhcp_option *
find_dhcp_option ( struct dhcp_option_block *options, unsigned int tag );
extern void register_dhcp_options ( struct dhcp_option_block *options );
diff --git a/src/net/dhcpopts.c b/src/net/dhcpopts.c
index ebd6de757..c906b1919 100644
--- a/src/net/dhcpopts.c
+++ b/src/net/dhcpopts.c
@@ -102,6 +102,40 @@ void dhcp_ipv4_option ( struct dhcp_option *option, struct in_addr *inp ) {
}
/**
+ * Print DHCP string option value into buffer
+ *
+ * @v buf Buffer into which to write the string
+ * @v size Size of buffer
+ * @v option DHCP option, or NULL
+ * @ret len Length of formatted string
+ *
+ * DHCP option strings are stored without a NUL terminator. This
+ * function provides a convenient way to extract these DHCP strings
+ * into standard C strings. It is permitted to call dhcp_snprintf()
+ * with @c option set to NULL; in this case the buffer will be filled
+ * with an empty string.
+ *
+ * The usual snprintf() semantics apply with regard to buffer size,
+ * return value when the buffer is too small, etc.
+ */
+int dhcp_snprintf ( char *buf, size_t size, struct dhcp_option *option ) {
+ size_t len;
+ char *content = "";
+
+ if ( option ) {
+ /* Shrink buffer size so that it is only just large
+ * enough to contain the option data. snprintf() will
+ * take care of everything else (inserting the NUL etc.)
+ */
+ len = ( option->len + 1 );
+ if ( len < size )
+ size = len;
+ content = option->data.string;
+ }
+ return snprintf ( buf, size, "%s", content );
+}
+
+/**
* Calculate length of a normal DHCP option
*
* @v option DHCP option