summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2010-12-17 21:26:43 +0100
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2010-12-17 21:26:43 +0100
commit0aec3af45d839beb5054c6f0ed7ff9b115b8d907 (patch)
tree3cec335e622a39e57ad81923ab46a4d7567befb1 /lib
parent5c269cc6982f664153bd73af93c41312b862e15d (diff)
downloadipset-0aec3af45d839beb5054c6f0ed7ff9b115b8d907.tar.gz
Add ipset_parse_tcpudp_port function
Add new parser function to parse TCP/UDP port name, number, or range of them.
Diffstat (limited to 'lib')
-rw-r--r--lib/parse.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/parse.c b/lib/parse.c
index 08e3d7c..fa8a4f7 100644
--- a/lib/parse.c
+++ b/lib/parse.c
@@ -244,20 +244,21 @@ ipset_parse_port(struct ipset_session *session,
}
/**
- * ipset_parse_tcp_port - parse TCP port name, number, or range of them
+ * ipset_parse_tcpudp_port - parse TCP/UDP port name, number, or range of them
* @session: session structure
* @opt: option kind of the data
* @str: string to parse
+ * @proto: TCP|UDP
*
- * Parse string as a TCP port name or number or range of them
+ * Parse string as a TCP/UDP port name or number or range of them
* separated by a dash. The parsed port numbers are stored
* in the data blob of the session.
*
* Returns 0 on success or a negative error code.
*/
int
-ipset_parse_tcp_port(struct ipset_session *session,
- enum ipset_opt opt, const char *str)
+ipset_parse_tcpudp_port(struct ipset_session *session,
+ enum ipset_opt opt, const char *str, const char *proto)
{
char *a, *saved, *tmp;
int err = 0;
@@ -276,11 +277,11 @@ ipset_parse_tcp_port(struct ipset_session *session,
if (a != NULL) {
/* port-port */
*a++ = '\0';
- err = ipset_parse_port(session, IPSET_OPT_PORT_TO, a, "TCP");
+ err = ipset_parse_port(session, IPSET_OPT_PORT_TO, a, proto);
if (err)
goto error;
}
- err = ipset_parse_port(session, opt, tmp, "TCP");
+ err = ipset_parse_port(session, opt, tmp, proto);
error:
free(saved);
@@ -288,6 +289,25 @@ error:
}
/**
+ * ipset_parse_tcp_port - parse TCP port name, number, or range of them
+ * @session: session structure
+ * @opt: option kind of the data
+ * @str: string to parse
+ *
+ * Parse string as a TCP port name or number or range of them
+ * separated by a dash. The parsed port numbers are stored
+ * in the data blob of the session.
+ *
+ * Returns 0 on success or a negative error code.
+ */
+int
+ipset_parse_tcp_port(struct ipset_session *session,
+ enum ipset_opt opt, const char *str)
+{
+ return ipset_parse_tcpudp_port(session, opt, str, "TCP");
+}
+
+/**
* ipset_parse_single_tcp_port - parse TCP port name or number
* @session: session structure
* @opt: option kind of the data
@@ -516,7 +536,7 @@ ipset_parse_proto_port(struct ipset_session *session,
goto error;
}
parse_port:
- err = ipset_parse_port(session, opt, tmp, proto);
+ err = ipset_parse_tcpudp_port(session, opt, tmp, proto);
error:
free(saved);