All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/accept4_01: don't hardcode port number for test
@ 2022-07-26 13:33 Jan Stancek
  2022-07-26 16:22 ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Stancek @ 2022-07-26 13:33 UTC (permalink / raw)
  To: ltp

Leave it to bind() to pick a free port number.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/syscalls/accept4/accept4_01.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/accept4/accept4_01.c b/testcases/kernel/syscalls/accept4/accept4_01.c
index 58115ea43213..b2f785d0a6aa 100644
--- a/testcases/kernel/syscalls/accept4/accept4_01.c
+++ b/testcases/kernel/syscalls/accept4/accept4_01.c
@@ -22,8 +22,6 @@
 #include "lapi/fcntl.h"
 #include "lapi/syscalls.h"
 
-#define PORT_NUM 33333
-
 static const char *variant_desc[] = {
 	"libc accept4()",
 	"__NR_accept4 syscall",
@@ -54,7 +52,7 @@ static int create_listening_socket(void)
 	memset(&svaddr, 0, sizeof(struct sockaddr_in));
 	svaddr.sin_family = AF_INET;
 	svaddr.sin_addr.s_addr = htonl(INADDR_ANY);
-	svaddr.sin_port = htons(PORT_NUM);
+	svaddr.sin_port = 0;
 
 	lfd = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
 
@@ -68,14 +66,16 @@ static int create_listening_socket(void)
 
 static void setup(void)
 {
+	socklen_t slen = sizeof(*conn_addr);
+
 	tst_res(TINFO, "Testing variant: %s", variant_desc[tst_variant]);
 
+	listening_fd = create_listening_socket();
+
 	memset(conn_addr, 0, sizeof(*conn_addr));
-	conn_addr->sin_family = AF_INET;
+	SAFE_GETSOCKNAME(listening_fd, (struct sockaddr *)conn_addr, &slen);
 	conn_addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-	conn_addr->sin_port = htons(PORT_NUM);
-
-	listening_fd = create_listening_socket();
+	tst_res(TINFO, "server listening on: %d", ntohs(conn_addr->sin_port));
 }
 
 static void cleanup(void)
-- 
2.27.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH] syscalls/accept4_01: don't hardcode port number for test
  2022-07-26 13:33 [LTP] [PATCH] syscalls/accept4_01: don't hardcode port number for test Jan Stancek
@ 2022-07-26 16:22 ` Petr Vorel
  2022-08-10  8:40   ` Jan Stancek
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2022-07-26 16:22 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp

> Leave it to bind() to pick a free port number.
IMHO more common use case => +1

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH] syscalls/accept4_01: don't hardcode port number for test
  2022-07-26 16:22 ` Petr Vorel
@ 2022-08-10  8:40   ` Jan Stancek
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Stancek @ 2022-08-10  8:40 UTC (permalink / raw)
  To: Petr Vorel; +Cc: LTP List

On Tue, Jul 26, 2022 at 6:23 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> > Leave it to bind() to pick a free port number.
> IMHO more common use case => +1
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>

Thanks, pushed.

>
> Kind regards,
> Petr
>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2022-08-10  8:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-26 13:33 [LTP] [PATCH] syscalls/accept4_01: don't hardcode port number for test Jan Stancek
2022-07-26 16:22 ` Petr Vorel
2022-08-10  8:40   ` Jan Stancek

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.