public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] TST_GET_UNUSED_PORT returns ports < 1024
@ 2019-05-29  9:33 Christian Amann
  2019-05-30 19:00 ` Petr Vorel
  2019-06-06 13:43 ` Cyril Hrubis
  0 siblings, 2 replies; 5+ messages in thread
From: Christian Amann @ 2019-05-29  9:33 UTC (permalink / raw)
  To: ltp

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).

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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190529/18f11994/attachment.html>

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

end of thread, other threads:[~2019-06-07  6:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2019-06-07  6:21     ` Christian Amann

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