<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 6, 2019, at 7:30 AM, Petr Vorel <<a href="mailto:pvorel@suse.cz" class="">pvorel@suse.cz</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">tst_get_unused_port is a shell helper, therefore it should use host<br class="">byte order (we're not expecting this value would be added directly to<br class="">sockaddr_in structure, which require network byte order).<br class="">Wrap TST_GET_UNUSED_PORT() with ntohs() to achieve it.<br class=""><br class="">Reported-by: Christian Amann <<a href="mailto:camann@suse.com" class="">camann@suse.com</a>><br class="">Suggested-by: Cyril Hrubis <<a href="mailto:chrubis@suse.cz" class="">chrubis@suse.cz</a>><br class="">Signed-off-by: Petr Vorel <<a href="mailto:pvorel@suse.cz" class="">pvorel@suse.cz</a>><br class="">---<br class="">Hi,<br class=""><br class="">I guess we didn't noticed this in shell script as sendfile01 is the only<br class="">one not requiring root (dns-stress, tst_net_stress.sh, ssh-stress, ssh-stress03-rmt do require it).<br class=""><br class="">I tested patch with little script (could be easily converted to proper<br class="">test placed in lib/newlib_tests/)<br class=""><br class="">export PATH="/opt/ltp/testcases/bin/:$PATH"<br class="">i=0<br class="">while [ $i -lt 2048 ]; do<br class=""> for j in ipv4 ipv6; do<br class=""> for k in stream dgram; do<br class=""> p="$(tst_get_unused_port $j $k)"<br class=""> printf "$i ($j $k): $p "<br class=""> if [ $p -lt 1024 ]; then<br class=""> echo "(bad)"<br class=""> exit 1<br class=""> else<br class=""> echo "(ok)"<br class=""> fi<br class=""> done<br class=""> done<br class=""> i=$((i+1))<br class="">done<br class="">echo "Test was ok"<br class=""><br class=""> testcases/lib/tst_get_unused_port.c | 2 +-<br class=""> 1 file changed, 1 insertion(+), 1 deletion(-)<br class=""><br class="">diff --git a/testcases/lib/tst_get_unused_port.c b/testcases/lib/tst_get_unused_port.c<br class="">index 0173f1634..a843cc6e3 100644<br class="">--- a/testcases/lib/tst_get_unused_port.c<br class="">+++ b/testcases/lib/tst_get_unused_port.c<br class="">@@ -54,6 +54,6 @@ int main(int argc, char *argv[])<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>return 1;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>}<br class=""><br class="">-<span class="Apple-tab-span" style="white-space:pre"> </span>printf("%d", TST_GET_UNUSED_PORT(family, type));<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>printf("%d", ntohs(TST_GET_UNUSED_PORT(family, type)));<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>return 0;<br class=""> }<br class="">-- <br class="">2.21.0<br class=""></div></div></blockquote></div><br class=""><div class="">Reviewed-by: Enji Cooper <<a href="mailto:yaneurabeya@gmail.com" class="">yaneurabeya@gmail.com</a>></div><div class=""><br class=""></div><div class="">Thanks!</div><div class="">-Enji</div></body></html>