public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] lib6/in6_2: don't assume that machine has 'eth0' interface name
@ 2015-05-13 11:54 Alexey Kodanev
  2015-06-09 11:44 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Kodanev @ 2015-05-13 11:54 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

systemd can rename network interfaces. We should look at LHOST_IFACES
variable for predefined test interface names.

Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
 testcases/network/lib6/in6_02.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/testcases/network/lib6/in6_02.c b/testcases/network/lib6/in6_02.c
index fea1827..dadb2a5 100644
--- a/testcases/network/lib6/in6_02.c
+++ b/testcases/network/lib6/in6_02.c
@@ -255,4 +255,36 @@ void initest(void)
 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");
+		return;
+	}
+
+	char *end = strchr(ifnames, ' ');
+
+	if (!end)
+		end = strchr(ifnames, '\0');
+
+	if (!end || end <= ifnames)
+		return;
+
+	size_t size = end - ifnames + 1;
+
+	char *name = malloc(size);
+
+	strncpy(name, ifnames, size - 1);
+	name[size] = '\0';
+
+	if (!strcmp(name, n2i[1].name)) {
+		free(name);
+		return;
+	}
+
+	tst_resm(TINFO, "change default 'eth0' name to '%s'", name);
+	n2i[1].name = name;
 }
-- 
1.7.1


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH] lib6/in6_2: don't assume that machine has 'eth0' interface name
  2015-05-13 11:54 [LTP] [PATCH] lib6/in6_2: don't assume that machine has 'eth0' interface name Alexey Kodanev
@ 2015-06-09 11:44 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2015-06-09 11:44 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list

Hi!
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> ---
>  testcases/network/lib6/in6_02.c |   32 ++++++++++++++++++++++++++++++++
>  1 files changed, 32 insertions(+), 0 deletions(-)
> 
> diff --git a/testcases/network/lib6/in6_02.c b/testcases/network/lib6/in6_02.c
> index fea1827..dadb2a5 100644
> --- a/testcases/network/lib6/in6_02.c
> +++ b/testcases/network/lib6/in6_02.c
> @@ -255,4 +255,36 @@ void initest(void)
>  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");
> +		return;
> +	}

Hmm, why not to use sscanf() instead?

sscanf(ifnames, "%ms", &name);

And even when we want to be compatible before glibc 2.7 (2007) we can
do:

static char *name[256];

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

> +	tst_resm(TINFO, "change default 'eth0' name to '%s'", name);
> +	n2i[1].name = name;
>  }
> -- 
> 1.7.1
> 
> 
> ------------------------------------------------------------------------------
> One dashboard for servers and applications across Physical-Virtual-Cloud 
> Widest out-of-the-box monitoring support with 50+ applications
> Performance metrics, stats and reports that give you Actionable Insights
> Deep dive visibility with transaction tracing using APM Insight.
> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-09 11:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-13 11:54 [LTP] [PATCH] lib6/in6_2: don't assume that machine has 'eth0' interface name Alexey Kodanev
2015-06-09 11:44 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox