]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
Add missing hunk to patch "Allow specifying protocols by number"
authorJozsef Kadlecsik <kadlec@netfilter.org>
Fri, 16 Jul 2021 12:53:26 +0000 (14:53 +0200)
committerJozsef Kadlecsik <kadlec@netfilter.org>
Fri, 16 Jul 2021 12:53:26 +0000 (14:53 +0200)
Actually, this is the part of it which allows specifying protocols
by number :-)

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
lib/parse.c

index 32fc34c3503c9ed983898f938282e67e8b49eeea..aabf2a8fdbdc3ec9429c611dab360abe948edfde 100644 (file)
@@ -280,8 +280,10 @@ static int
 parse_portname(struct ipset_session *session, const char *str,
               uint16_t *port, const char *proto)
 {
-       char *saved, *tmp;
+       char *saved, *tmp, *protoname;
+       const struct protoent *protoent;
        struct servent *service;
+       uint8_t protonum = 0;
 
        saved = tmp = ipset_strdup(session, str);
        if (tmp == NULL)
@@ -290,7 +292,15 @@ parse_portname(struct ipset_session *session, const char *str,
        if (tmp == NULL)
                goto error;
 
-       service = getservbyname(tmp, proto);
+       protoname = (char *)proto;
+       if (string_to_u8(session, proto, &protonum, IPSET_WARNING) == 0) {
+               protoent = getprotobynumber(protonum);
+               if (protoent == NULL)
+                       goto error;
+               protoname = protoent->p_name;
+       }
+
+       service = getservbyname(tmp, protoname);
        if (service != NULL) {
                *port = ntohs((uint16_t) service->s_port);
                free(saved);