aboutgitcodebugslistschat
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/parse.c b/parse.c
index 9bd0e81..ad21040 100644
--- a/parse.c
+++ b/parse.c
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
+#include "common.h"
#include "parse.h"
/**
@@ -83,3 +84,30 @@ bool parse_unsigned(const char **cursor, int base, unsigned long *valp)
*cursor = p;
return true;
}
+
+/**
+ * parse_port_range() - Parse a range of port numbers '<first>[-<last>]'
+ * @range: Update with the parsed values on success
+ */
+bool parse_port_range(const char **cursor, struct port_range *range)
+{
+ unsigned long first, last;
+ const char *p = *cursor;
+
+ if (!parse_unsigned(&p, 10, &first))
+ return false;
+
+ last = first;
+
+ if (parse_literal(&p, "-"))
+ if (!parse_unsigned(&p, 10, &last))
+ return false;
+
+ if ((last < first) || (last >= NUM_PORTS))
+ return false;
+
+ range->first = first;
+ range->last = last;
+ *cursor = p;
+ return true;
+}