|
@@ -101,6 +101,40 @@ void dhcp_ipv4_option ( struct dhcp_option *option, struct in_addr *inp ) {
|
101
|
101
|
*inp = option->data.in;
|
102
|
102
|
}
|
103
|
103
|
|
|
104
|
+/**
|
|
105
|
+ * Print DHCP string option value into buffer
|
|
106
|
+ *
|
|
107
|
+ * @v buf Buffer into which to write the string
|
|
108
|
+ * @v size Size of buffer
|
|
109
|
+ * @v option DHCP option, or NULL
|
|
110
|
+ * @ret len Length of formatted string
|
|
111
|
+ *
|
|
112
|
+ * DHCP option strings are stored without a NUL terminator. This
|
|
113
|
+ * function provides a convenient way to extract these DHCP strings
|
|
114
|
+ * into standard C strings. It is permitted to call dhcp_snprintf()
|
|
115
|
+ * with @c option set to NULL; in this case the buffer will be filled
|
|
116
|
+ * with an empty string.
|
|
117
|
+ *
|
|
118
|
+ * The usual snprintf() semantics apply with regard to buffer size,
|
|
119
|
+ * return value when the buffer is too small, etc.
|
|
120
|
+ */
|
|
121
|
+int dhcp_snprintf ( char *buf, size_t size, struct dhcp_option *option ) {
|
|
122
|
+ size_t len;
|
|
123
|
+ char *content = "";
|
|
124
|
+
|
|
125
|
+ if ( option ) {
|
|
126
|
+ /* Shrink buffer size so that it is only just large
|
|
127
|
+ * enough to contain the option data. snprintf() will
|
|
128
|
+ * take care of everything else (inserting the NUL etc.)
|
|
129
|
+ */
|
|
130
|
+ len = ( option->len + 1 );
|
|
131
|
+ if ( len < size )
|
|
132
|
+ size = len;
|
|
133
|
+ content = option->data.string;
|
|
134
|
+ }
|
|
135
|
+ return snprintf ( buf, size, "%s", content );
|
|
136
|
+}
|
|
137
|
+
|
104
|
138
|
/**
|
105
|
139
|
* Calculate length of a normal DHCP option
|
106
|
140
|
*
|