From nobody Sat Feb 7 08:53:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1770388728; cv=none; d=zohomail.com; s=zohoarc; b=hUY10n7Y0u7aKGFawzqJ1dIIuUl4RfzFKqy6Zt1FXf1cJC2WUmwxHS6iy4kiIo01OA2iY+7Do7PvhrrQNG9TpMXskz12eQet9XZpgUSMHA7VLA1g7U3P7o+0wERYIuWtuOrY2qKkfXwPldrUpioc7/JRH747+yvXzumIIPiQdGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770388728; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=6qWfgG01CKPbMT2UqTb+UMVEif2yWUR8HUMGnqTp3Dg=; b=RzoL3TMdqP5X5Q6G8Q4g9T12TEUNViNoD1tnMfQ29xXA+PE2ErVckci+73lkm7Vo+h2LOe4dEP8SyWr1eXxo6qNd7DbyQgFsmN2Jd5D4Y2+uvzOkZHN0iWtaqd1jh3XJN6pZpP2sROr/1K6D1s/uttl/y6B6YKdN+SbV1XWDMHk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1770388727766485.5586697799016; Fri, 6 Feb 2026 06:38:47 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id C355D4181A; Fri, 6 Feb 2026 09:38:46 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 441AB41AA6; Fri, 6 Feb 2026 09:38:00 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 6941B417E0; Fri, 6 Feb 2026 09:37:55 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id B4D303F95E for ; Fri, 6 Feb 2026 09:37:53 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-572-2l1OqBa1PQuCbx1Ws4sL4g-1; Fri, 06 Feb 2026 09:37:52 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 50A601800349 for ; Fri, 6 Feb 2026 14:37:51 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9B4A23000709 for ; Fri, 6 Feb 2026 14:37:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770388673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6qWfgG01CKPbMT2UqTb+UMVEif2yWUR8HUMGnqTp3Dg=; b=EWsXF+xkVznEf9e3Phn9D1Or+tJiGeH/tLZ8Sp26enOT+4/mh89kI0i+fwhse2Q7o+ixoS 30GtBqmy9oANOgvcWaHMhdXNO42WiKH8B8DV5yVBZ8ccrbxMX0kiNK3rZ0XLn9DEo1G0Yl 1G860nrJ+BiEZesCa0QiGNlu6sDQRq4= X-MC-Unique: 2l1OqBa1PQuCbx1Ws4sL4g-1 X-Mimecast-MFC-AGG-ID: 2l1OqBa1PQuCbx1Ws4sL4g_1770388671 To: devel@lists.libvirt.org Subject: [PATCH] virsh: Switch cmdDomIfAddr() to vshTable Date: Fri, 6 Feb 2026 15:37:42 +0100 Message-ID: <7a11ef7050d3fa557a1ce81dfd51a1152ffffd2c.1770388662.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: V6zoXKivFIzAPQvewHtxF9XxGNZbY0gnrzQS_Y_e2Q0_1770388671 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: G6R5KI76U7ZLAGGSP3R6YTDQCACPDQ7Y X-Message-ID-Hash: G6R5KI76U7ZLAGGSP3R6YTDQCACPDQ7Y X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1770388735590158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The aim of cmdDomIfAddr() is to obtain IP addresses for given domain and then print (ifName, MAC, type, IP Address) tuple. Preferably in an aligned table. This is hard to do with printf style of spacing ("%-NNs") since the interface name (ifName) can vary a lot in length. Fortunately, we have vshTable which is designed to handle this case. Signed-off-by: Michal Privoznik --- tools/virsh-domain-monitor.c | 53 ++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index f4274f2721..c0db30cb11 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -2279,6 +2279,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) bool full =3D vshCommandOptBool(cmd, "full"); const char *sourcestr =3D NULL; int source =3D VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE; + g_autoptr(vshTable) table =3D NULL; =20 if (vshCommandOptString(ctl, cmd, "interface", &ifacestr) < 0) return false; @@ -2299,28 +2300,30 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - vshPrintExtra(ctl, " %-10s %-20s %-8s %s\n%s%s\n", _("Name"), - _("MAC address"), _("Protocol"), _("Address"), - _("-------------------------------------------------"), - _("------------------------------")); + table =3D vshTableNew(_("Name"), _("MAC address"), _("Protocol"), _("A= ddress"), NULL); + if (!table) + return false; =20 for (i =3D 0; i < ifaces_count; i++) { virDomainInterfacePtr iface =3D ifaces[i]; const char *type =3D NULL; + const char *hwaddr =3D "N/A"; =20 if (ifacestr && STRNEQ(ifacestr, iface->name)) continue; =20 + if (iface->hwaddr) + hwaddr =3D iface->hwaddr; + /* When the interface has no IP address */ if (!iface->naddrs) { - vshPrint(ctl, " %-10s %-17s %-12s %s\n", - iface->name, - iface->hwaddr ? iface->hwaddr : "N/A", "N/A", "N/A"); + if (vshTableRowAppend(table, + iface->name, hwaddr, "N/A", "N/A", NULL)= < 0) + goto cleanup; continue; } =20 for (j =3D 0; j < iface->naddrs; j++) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *ip_addr_str =3D NULL; =20 switch (iface->addrs[j].type) { @@ -2332,26 +2335,30 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) break; } =20 - virBufferAsprintf(&buf, "%-12s %s/%d", - type, iface->addrs[j].addr, - iface->addrs[j].prefix); - - ip_addr_str =3D virBufferContentAndReset(&buf); - - if (!ip_addr_str) - ip_addr_str =3D g_strdup(""); + ip_addr_str =3D g_strdup_printf("%s/%d", + iface->addrs[j].addr, + iface->addrs[j].prefix); =20 /* Don't repeat interface name */ - if (full || !j) - vshPrint(ctl, " %-10s %-17s %s\n", - iface->name, - NULLSTR_EMPTY(iface->hwaddr), ip_addr_str); - else - vshPrint(ctl, " %-10s %-17s %s\n", - "-", "-", ip_addr_str); + if (full || !j) { + if (vshTableRowAppend(table, + iface->name, + NULLSTR_EMPTY(iface->hwaddr), + NULLSTR_MINUS(type), ip_addr_str, NU= LL) < 0) { + goto cleanup; + } + } else { + if (vshTableRowAppend(table, + "-", "-", + NULLSTR_MINUS(type), ip_addr_str, NU= LL) < 0) { + goto cleanup; + } + } } } =20 + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: --=20 2.52.0