summaryrefslogtreecommitdiff
path: root/lib/dynamic-string.c
diff options
context:
space:
mode:
authorJesse Gross <jesse@nicira.com>2015-05-20 18:47:21 -0700
committerJesse Gross <jesse@nicira.com>2015-05-28 18:34:21 -0700
commite7ae59f9900ede275edfffc82d3a0d0110fd826d (patch)
tree3ce3f8eb25c4fe447d100f2f7c74348a98847659 /lib/dynamic-string.c
parent65da723b40a5fdeff6c63c94758fb4121d89fe8a (diff)
downloadopenvswitch-e7ae59f9900ede275edfffc82d3a0d0110fd826d.tar.gz
util: Library routines for printing and scanning large hex integers.
Geneve options are variable length and up to 124 bytes long, which means that they can't be easily manipulated by the integer string functions like we do for other fields. This adds a few helper routines to make these operations easier. Signed-off-by: Jesse Gross <jesse@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
Diffstat (limited to 'lib/dynamic-string.c')
-rw-r--r--lib/dynamic-string.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c
index 914af64c1..a6c8f6c76 100644
--- a/lib/dynamic-string.c
+++ b/lib/dynamic-string.c
@@ -361,6 +361,29 @@ ds_swap(struct ds *a, struct ds *b)
*b = temp;
}
+void
+ds_put_hex(struct ds *ds, const void *buf_, size_t size)
+{
+ const uint8_t *buf = buf_;
+ bool printed = false;
+ int i;
+
+ for (i = 0; i < size; i++) {
+ uint8_t val = buf[i];
+ if (val || printed) {
+ if (!printed) {
+ ds_put_format(ds, "0x%"PRIx8, val);
+ } else {
+ ds_put_format(ds, "%02"PRIx8, val);
+ }
+ printed = true;
+ }
+ }
+ if (!printed) {
+ ds_put_char(ds, '0');
+ }
+}
+
/* Writes the 'size' bytes in 'buf' to 'string' as hex bytes arranged 16 per
* line. Numeric offsets are also included, starting at 'ofs' for the first
* byte in 'buf'. If 'ascii' is true then the corresponding ASCII characters