public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] TST_GET_UNUSED_PORT returns ports < 1024
Date: Thu, 6 Jun 2019 16:45:49 +0200	[thread overview]
Message-ID: <20190606144549.GA14501@dell5510> (raw)
In-Reply-To: <20190606134321.GA30964@rei.lan>

Hi Cyril,

> > when using the TST_GET_UNUSED_PORT macro you sometimes get ports lower
> > than 1024 which would require a testcase to have the
> > CAP_NET_BIND_SERVICE capability (or simply run as root).

> Looking at the code as far as I can tell the function returns the port
> in the network endianity, which is big endian. Intel CPUs are little
> endian, so if you want to print the port you actually have to use
> ntohs() function to convert it to the host endianity. And if you are
> passing that value in the sockaddr_in structure you must not use the
> htons() since the value is already in the correct byte order. And yes
> this is horribly confusing, but that's how it is.
Thanks for debugging the problem.

> I guess that we should write down this piece of information in the
> documentation, because it looks like the tst_get_unused_port shell
> helper does this incorrectly and prints the raw value instead of
> converting it with ntohs().
Correct, I've sent a patch fixing it for shell tests [1].
As I noted there, this problem was even on version for old API.

Not sure about docs as there is no docs for network API shell/C functions yet
But even the problem for shell was fixed by that patch it'd be worth to add note
about byte order to C code tst_get_unused_port() and/or header defining
TST_GET_UNUSED_PORT() developers using it in C.

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/patch/1111167/

  reply	other threads:[~2019-06-06 14:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29  9:33 [LTP] TST_GET_UNUSED_PORT returns ports < 1024 Christian Amann
2019-05-30 19:00 ` Petr Vorel
2019-06-06 13:43 ` Cyril Hrubis
2019-06-06 14:45   ` Petr Vorel [this message]
2019-06-07  6:21     ` Christian Amann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190606144549.GA14501@dell5510 \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox