Commit 12f5a0c5 authored by Jiri Popelka's avatar Jiri Popelka

Fix nstrcmp() to prevent ifconfig from showing duplicate interfaces.

Patch from TAKADA Yoshihito
https://bugzilla.redhat.com/show_bug.cgi?id=1021109
parent f919c51b
...@@ -56,14 +56,19 @@ int nstrcmp(const char *ap, const char *bp) ...@@ -56,14 +56,19 @@ int nstrcmp(const char *ap, const char *bp)
int complen=(aindex<bindex)?aindex:bindex; int complen=(aindex<bindex)?aindex:bindex;
int res = strncmp(a, b, complen); int res = strncmp(a, b, complen);
if (res != 0) if (res != 0) {
{ free(a); free(b); return res; } goto out;
}
if (aindex > bindex) if (aindex > bindex) {
{ free(a); free(b); return 1; } res = 1;
goto out;
}
if (aindex < bindex) if (aindex < bindex) {
{ free(a); free(b); return -1; } res = -1;
goto out;
}
an = a+aindex; an = a+aindex;
bn = b+bindex; bn = b+bindex;
...@@ -71,11 +76,20 @@ int nstrcmp(const char *ap, const char *bp) ...@@ -71,11 +76,20 @@ int nstrcmp(const char *ap, const char *bp)
av = atoi(an); av = atoi(an);
bv = atoi(bn); bv = atoi(bn);
if (av < bv) if (av < bv) {
{ free(a); free(b); return -1; } res = -1;
goto out;
}
if (av > bv) {
res = 1;
goto out;
}
if (av > bv) res = strcmp(a, b);
{ free(a); free(b); return 1; } if (res != 0) {
goto out;
}
av = -1; av = -1;
if (aalias != NULL) if (aalias != NULL)
...@@ -85,15 +99,25 @@ int nstrcmp(const char *ap, const char *bp) ...@@ -85,15 +99,25 @@ int nstrcmp(const char *ap, const char *bp)
if (balias != NULL) if (balias != NULL)
bv = atoi(balias); bv = atoi(balias);
free(a); free(b); if (av < bv) {
res = -1;
goto out;
}
if (av < bv) if (av > bv) {
return -1; res = 1;
goto out;
}
if (av > bv) if (aalias && balias) {
return 1; res = strcmp(aalias, balias);
}
return 0; out:
free(a); free(b);
return res;
} }
...@@ -151,6 +175,15 @@ int main() ...@@ -151,6 +175,15 @@ int main()
err |= dotest("a:", "a", 1); err |= dotest("a:", "a", 1);
err |= dotest("a1b12", "a1b2", 1); err |= dotest("a1b12", "a1b2", 1);
err |= dotest("eth1", "eth01", 1);
err |= dotest("eth01", "eth1", -1);
err |= dotest("eth1:1", "eth01:1", 1);
err |= dotest("eth01:1", "eth1:1", -1);
err |= dotest("eth1:1", "eth01:01", 1);
err |= dotest("eth1:01", "eth01:1", 1);
err |= dotest("eth01:1", "eth1:01", -1);
err |= dotest("eth01:01", "eth1:1", -1);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment