GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Jens Axboe <[email protected]>
Cc: Ammar Faizi <[email protected]>,
	Pavel Begunkov <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>,
	io-uring Mailing List <[email protected]>,
	Linux Kernel Mailing List <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH liburing 1/3] io_uring-udp: Fix the wrong IPv6 binary to string conversion
Date: Sat, 15 Apr 2023 23:59:02 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Another io_uring-udp fix. The verbose output shows the wrong address
when using IPv6.

When the address family is AF_INET6, the pointer should be cast to
'struct sockaddr_in6', not 'struct sockaddr_in'.

While in there, also add a square bracket around the IP address to
easily read the port number, especially for IPv6.

Before this patch:

    port bound to 49567
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:47048
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:54755
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:57968

(the IPv6 address is wrong)

After this patch:

    port bound to 48033
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:40456
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:50306
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:52291

Link: https://github.com/axboe/liburing/issues/814#issuecomment-1458862489
Fixes: https://github.com/axboe/liburing/issues/814
Fixes: 61d472b51e761e61c ("add an example for a UDP server")
Signed-off-by: Ammar Faizi <[email protected]>
---
 examples/io_uring-udp.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/examples/io_uring-udp.c b/examples/io_uring-udp.c
index b81a5e7c47afd9c8..4697af171ba68999 100644
--- a/examples/io_uring-udp.c
+++ b/examples/io_uring-udp.c
@@ -271,14 +271,22 @@ static int process_cqe_recv(struct ctx *ctx, struct io_uring_cqe *cqe,
 	}
 
 	if (ctx->verbose) {
+		struct sockaddr_in *addr = io_uring_recvmsg_name(o);
+		struct sockaddr_in6 *addr6 = (void *)addr;
 		char buff[INET6_ADDRSTRLEN + 1];
 		const char *name;
-		struct sockaddr_in *addr = io_uring_recvmsg_name(o);
+		void *paddr;
 
-		name = inet_ntop(ctx->af, &addr->sin_addr, buff, sizeof(buff));
+		if (ctx->af == AF_INET6)
+			paddr = &addr6->sin6_addr;
+		else
+			paddr = &addr->sin_addr;
+
+		name = inet_ntop(ctx->af, paddr, buff, sizeof(buff));
 		if (!name)
 			name = "<INVALID>";
-		fprintf(stderr, "received %u bytes %d from %s:%d\n",
+
+		fprintf(stderr, "received %u bytes %d from [%s]:%d\n",
 			io_uring_recvmsg_payload_length(o, cqe->res, &ctx->msg),
 			o->namelen, name, (int)ntohs(addr->sin_port));
 	}
-- 
Ammar Faizi


  reply	other threads:[~2023-04-15 16:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-15 16:59 [PATCH liburing 0/3] io_uring-udp fix, manpage fix, and hppa cross-compiler Ammar Faizi
2023-04-15 16:59 ` Ammar Faizi [this message]
2023-04-15 16:59 ` [PATCH liburing 2/3] github: Add hppa cross compiler Ammar Faizi
2023-04-15 16:59 ` [PATCH liburing 3/3] man/io_uring_cqe_get_data.3: Fix a misleading return value Ammar Faizi
2023-04-15 20:37 ` [PATCH liburing 0/3] io_uring-udp fix, manpage fix, and hppa cross-compiler Jens Axboe

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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