summaryrefslogtreecommitdiff
path: root/lib/if.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2022-06-20 19:54:35 +0300
committerGitHub <noreply@github.com>2022-06-20 19:54:35 +0300
commit2af482767c9197646e21dbb605ab12e690b8a266 (patch)
treebf063842b27f8393c522653f4801030a9225dd44 /lib/if.c
parent298ff7e35721fbc7397f3dc94465cbf65d431283 (diff)
parentf33abb817d81d2fb0f2b3a31ba690829f56dd2b8 (diff)
Merge pull request #11146 from NicolasDichtel/master
lib/if: fix interface name comparison
Diffstat (limited to 'lib/if.c')
-rw-r--r--lib/if.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/if.c b/lib/if.c
index 89d30e4fb3..fa4fdb82d3 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -82,6 +82,8 @@ int if_cmp_name_func(const char *p1, const char *p2)
int res;
while (*p1 && *p2) {
+ char *tmp1, *tmp2;
+
/* look up to any number */
l1 = strcspn(p1, "0123456789");
l2 = strcspn(p2, "0123456789");
@@ -111,8 +113,8 @@ int if_cmp_name_func(const char *p1, const char *p2)
if (!*p2)
return 1;
- x1 = strtol(p1, (char **)&p1, 10);
- x2 = strtol(p2, (char **)&p2, 10);
+ x1 = strtol(p1, (char **)&tmp1, 10);
+ x2 = strtol(p2, (char **)&tmp2, 10);
/* let's compare numbers now */
if (x1 < x2)
@@ -120,6 +122,16 @@ int if_cmp_name_func(const char *p1, const char *p2)
if (x1 > x2)
return 1;
+ /* Compare string if numbers are equal (distinguish foo-1 from foo-001) */
+ l1 = strspn(p1, "0123456789");
+ l2 = strspn(p2, "0123456789");
+ if (l1 != l2)
+ return (strcmp(p1, p2));
+
+ /* Continue to parse the rest of the string */
+ p1 = (const char *)tmp1;
+ p2 = (const char *)tmp2;
+
/* numbers were equal, lets do it again..
(it happens with name like "eth123.456:789") */
}