* [LTP] [PATCH] net/tst_net_vars: Fix IPv4 network computing on big endianness
@ 2019-06-14 12:27 Petr Vorel
2019-06-17 12:21 ` Petr Vorel
0 siblings, 1 reply; 2+ messages in thread
From: Petr Vorel @ 2019-06-14 12:27 UTC (permalink / raw)
To: ltp
by converting IP to network byte order and adjust printing.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/lib/tst_net_vars.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/testcases/lib/tst_net_vars.c b/testcases/lib/tst_net_vars.c
index 43cd92bcf..b1ea99df6 100644
--- a/testcases/lib/tst_net_vars.c
+++ b/testcases/lib/tst_net_vars.c
@@ -476,23 +476,19 @@ static char *get_ipv4_network(int ip, unsigned int prefix)
unsigned char byte;
unsigned int i;
+ ip = htonl(ip);
+
if (prefix > MAX_IPV4_PREFIX)
return NULL;
if (prefix == MAX_IPV4_PREFIX)
return strdup("\0");
- prefix &= 0x18;
+ prefix &= MAX_IPV4_PREFIX - 8;
- for (i = 0; i < MAX_IPV4_PREFIX && (prefix == 0 || i < prefix);
- i += 8) {
- if (i == 0) {
- byte = ip & 0xff;
- sprintf(p_buf, "%d", byte);
- } else {
- byte = (ip >> i) & 0xff;
- sprintf(p_buf, ".%d", byte);
- }
+ for (i = prefix; i > 0; i -= 8) {
+ byte = (ip >> i) & 0xff;
+ sprintf(p_buf, i < prefix ? ".%d" : "%d", byte);
p_buf += strlen(p_buf);
}
--
2.21.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [LTP] [PATCH] net/tst_net_vars: Fix IPv4 network computing on big endianness
2019-06-14 12:27 [LTP] [PATCH] net/tst_net_vars: Fix IPv4 network computing on big endianness Petr Vorel
@ 2019-06-17 12:21 ` Petr Vorel
0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2019-06-17 12:21 UTC (permalink / raw)
To: ltp
Hi,
> by converting IP to network byte order and adjust printing.
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> testcases/lib/tst_net_vars.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
Merged.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-17 12:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-14 12:27 [LTP] [PATCH] net/tst_net_vars: Fix IPv4 network computing on big endianness Petr Vorel
2019-06-17 12:21 ` Petr Vorel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.