Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp2023285rwe; Sat, 15 Apr 2023 09:59:58 -0700 (PDT) X-Google-Smtp-Source: AKy350ZiaTrmCRs13Oi2CE2RWIhYFY/6wmg4KEdXipVPnm2hYnjRJ0/gT4Blp4twfdBZWy/bX64p X-Received: by 2002:a05:6a20:5490:b0:ee:f5a4:c072 with SMTP id i16-20020a056a20549000b000eef5a4c072mr2662710pzk.46.1681577997774; Sat, 15 Apr 2023 09:59:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681577997; cv=none; d=google.com; s=arc-20160816; b=bLggeb23XDAqpc+SpxL/c+KoVxgLL0tJTiqnMy/2YMfs0T4JR6QLb4cX3vyOErqNeT 83e+r8XKCR0kfcqSpi8gL/MHYWnmbtVSQeHN0I9zvLwChdARP7zBnSzdcotmCuylZM4L dobdNckyxlxzIaNzfQdQ6JB44o8BBNtboBgkFP3lt1aTG29Y39tbUGpI05kJt7S9rECL f4PepK/UAHbbBUTHZi1ejcw6h0i+qJ0Gvy0v8puWFrePFFo9rmsWv3W9S6ug0Zu+rOHD nHBmDLbqq3TlSTXvQooGrzdQtzZPqQml0IGrE4PsJHASwauYqZi5zSUR/3Sara7f2Cyi Ol1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=048hmv3cIHoAcuJjrNU29KleR6151XxAcp/x6wgvhCI=; b=w088cqYmwXPCV45DlAYmGooLvOsdHimXQI8SHrFWOdKOEZIEfZoY3lNtzHJHWMddPt FqxhcfniGD9Hsnz1wNX52RJPInUhRky+AQwfgmgm4Qya9JcF4sd41AG+SaE17DlYaP3E /GqvoeemF4cBCbWmNVyJ/9MBtqbws3eLagXHutfmf0fipekVXlgDs+C8ix93hEUXd/nw aOP1ElFIrGTBwfwN+Ftk4Db1zuFZc3bZlsS1CXYWB9txFA9YCCTxW/DDLIGzxkveTJLm HiuK+KnKglofWdZka4pjD6/d/58JooQbpQsVTpZymLFyf0wrSst4xYHu9nt61JClsNNk VHCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=VPmETBGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o26-20020aa7979a000000b0063b17fb3596si7257517pfp.341.2023.04.15.09.59.46; Sat, 15 Apr 2023 09:59:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=VPmETBGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjDOQ7b (ORCPT + 99 others); Sat, 15 Apr 2023 12:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229989AbjDOQ72 (ORCPT ); Sat, 15 Apr 2023 12:59:28 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C50FD3C25; Sat, 15 Apr 2023 09:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1681577957; bh=QWY+Zl3F1B+NIqLmMETedIlIuKxQpaMYeUw+n9XJjn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VPmETBGuOfeU9HhDCmto5vPxpe3Q4+4tGX8NGPX1t+hlE8aGInj9W0c4RjyVnH5qf 6PG6z0Ln1PBof0KPRRbHYA7b9lOS5ovz6loK1t4ddKrcVXbL21VJ78gNs65fKKvu5Y VAQST6SDa+Ha1oUqG6nS+NlpnCHl9a8jqD3yFKykIQJb0RzoKgSRX55ETo15KNH2Ba HjyLIAqPquXL7fqEJBOalaewLLnkb0Hec+ca5K+E3ULG9NYA9EcXz6oz352GEcQhIp lk+5MTMRAOzz5CoMSQrEjDtLdytmcdS+E3d/e6TTRZv8kTrs1Vbe+cXKcgBp88wXA3 h1UfZ8SNB52Pg== Received: from localhost.localdomain (unknown [182.253.88.211]) by gnuweeb.org (Postfix) with ESMTPSA id AF4F324552A; Sat, 15 Apr 2023 23:59:14 +0700 (WIB) From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Pavel Begunkov , Alviro Iskandar Setiawan , io-uring Mailing List , Linux Kernel Mailing List , GNU/Weeb Mailing List 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 Message-Id: <20230415165904.791841-2-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230415165904.791841-1-ammarfaizi2@gnuweeb.org> References: <20230415165904.791841-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 = ""; - 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