Skip to content

Commit

Permalink
network/in6_02: Don't use default value for LHOST_IFACES
Browse files Browse the repository at this point in the history
In case of LHOST_IFACES not being defined was 'eth0' used as default.
Although eth0 is common iface, we cannot guarantee it, therefore skip
testing it.

Also check sscanf return value to catch whitespace only.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
Acked-by: Alexey Kodanev <alexey.kodanev@oracle.com>
  • Loading branch information
pevik committed Apr 23, 2018
1 parent bcb0a51 commit 95c40a1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions testcases/network/lib6/in6_02.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static struct {
int nonzero;
} n2i[] = {
{ "lo", 1 },
{ "eth0", 1 },
{ NULL, 1 },
{ "hoser75", 0 },
{ "6", 0 },
};
Expand Down Expand Up @@ -80,6 +80,11 @@ void n2itest(void)
char ifname[IF_NAMESIZE], *pifn;

for (i = 0; i < N2I_COUNT; ++i) {
if (n2i[i].name == NULL) {
tst_resm(TCONF, "LHOST_IFACES not defined or invalid, skip testing it");
return;
}

TEST(if_nametoindex(n2i[i].name));
if (!TEST_RETURN != !n2i[i].nonzero) {
tst_resm(TFAIL, "if_nametoindex(\"%s\") %ld "
Expand Down Expand Up @@ -256,22 +261,17 @@ void setup(void)
{
TEST_PAUSE;

tst_resm(TINFO, "get interface name from LHOST_IFACES var");

char *ifnames = getenv("LHOST_IFACES");

if (!ifnames) {
tst_resm(TWARN, "LHOST_IFACES not defined, default to eth0");
if (!ifnames)
return;
}

static char name[256];
int ret;

sscanf(ifnames, "%255s", name);

if (!strcmp(name, n2i[1].name))
ret = sscanf(ifnames, "%255s", name);
if (ret == -1)
return;

tst_resm(TINFO, "change default 'eth0' name to '%s'", name);
tst_resm(TINFO, "get interface name from LHOST_IFACES: '%s'", name);
n2i[1].name = name;
}

0 comments on commit 95c40a1

Please sign in to comment.