From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] TST_GET_UNUSED_PORT returns ports < 1024
Date: Thu, 30 May 2019 21:00:13 +0200 [thread overview]
Message-ID: <20190530190012.GA32123@x230> (raw)
In-Reply-To: <7b0b763f-0b6b-fb18-7916-d25afdcb5c68@suse.com>
Hi Christian,
> Hi,
> 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).
That surprised me. I thought using bind() with non-root user doesn't do that,
but need to check the implementation in the kernel.
> Of course you could write a wrapper like the following to avoid that
> issue, but in my opinion it would be nice to have the option to get
> non-root ports directly from the library.
> /* Wrapper to to get a non-root port if necessary */
> static int get_port(uid_t uid)
> {
> static int count = 10;
> int port;
> port = TST_GET_UNUSED_PORT(AF_INET, SOCK_STREAM);
> if (port < 1000 && uid != 0) {
> if (!count)
> tst_brk(TBROK, "Could not get fitting port");
> count--;
> return get_port(uid);
> }
> return port;
> }
> Kind regards,
> Christian
Kind regards,
Petr
next prev parent reply other threads:[~2019-05-30 19:00 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 [this message]
2019-06-06 13:43 ` Cyril Hrubis
2019-06-06 14:45 ` Petr Vorel
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=20190530190012.GA32123@x230 \
--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