qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Doug Evans via <qemu-devel@nongnu.org>
To: qemu-devel@nongnu.org
Cc: "Samuel Thibault" <samuel.thibault@ens-lyon.org>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Doug Evans" <dje@google.com>
Subject: [PATCH v5 3/5] inet_parse_host_and_addr: Recognize []:port (empty ipv6 address)
Date: Fri, 19 Feb 2021 16:13:20 -0800	[thread overview]
Message-ID: <20210220001322.1311139-4-dje@google.com> (raw)
In-Reply-To: <20210220001322.1311139-1-dje@google.com>

Some callers need to distinguish empty ipv4 addresses from ipv6.

Signed-off-by: Doug Evans <dje@google.com>
---

Changes from v4:
- new in this patchset revision

 util/qemu-sockets.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 3ca6a6fb3d..062f0eb074 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -620,7 +620,8 @@ static int inet_parse_flag(const char *flagname, const char *optstr, bool *val,
  * Terminator may be '\0'.
  * The syntax for IPv4 addresses is: address:port. "address" is optional,
  * and may be empty (i.e., str is ":port").
- * The syntax for IPv6 addresses is: [address]:port. Upon return the wrapping
+ * The syntax for IPv6 addresses is: [address]:port. "address" is optional,
+ * and may be empty (i.e., str is "[]:port"). Upon return the wrapping
  * [] brackets are removed.
  * Host names are also supported as hostname:port. It is up to the caller to
  * distinguish host names from numeric IPv4 addresses.
@@ -654,7 +655,10 @@ const char *inet_parse_host_and_port(const char *str, int terminator,
         }
     } else if (buf[0] == '[') {
         /* IPv6 addr */
-        if (sscanf(buf, "[%64[^]]]:%32s", host, port) != 2) {
+        /* Note: sscanf %[ doesn't recognize empty contents. */
+        if (sscanf(buf, "[]:%32s", port) == 1) {
+            host[0] = '\0';
+        } else if (sscanf(buf, "[%64[^]]]:%32s", host, port) != 2) {
             error_setg(errp, "error parsing IPv6 address '%s'", buf);
             return NULL;
         }
-- 
2.30.0.617.g56c4b15f3c-goog



  parent reply	other threads:[~2021-02-20  0:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-20  0:13 [PATCH v5 0/5] Add support for ipv6 host forwarding Doug Evans via
2021-02-20  0:13 ` [PATCH v5 1/5] slirp: Advance libslirp submodule to add ipv6 host-forward support Doug Evans via
2021-02-20  0:20   ` Philippe Mathieu-Daudé
2021-02-23 20:18     ` Doug Evans
2021-02-26 12:18       ` Marc-André Lureau
2021-02-20  0:13 ` [PATCH v5 2/5] util/qemu-sockets.c: Split host:port parsing out of inet_parse Doug Evans via
2021-02-20  0:13 ` Doug Evans via [this message]
2021-02-20  0:13 ` [PATCH v5 4/5] net/slirp.c: Refactor address parsing Doug Evans via
2021-02-20  0:13 ` [PATCH v5 5/5] net: Extend host forwarding to support IPv6 Doug Evans via
2021-02-20  0:27 ` [PATCH v5 0/5] Add support for ipv6 host forwarding no-reply

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 \
    --in-reply-to=20210220001322.1311139-4-dje@google.com \
    --to=qemu-devel@nongnu.org \
    --cc=berrange@redhat.com \
    --cc=dje@google.com \
    --cc=samuel.thibault@ens-lyon.org \
    /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;
as well as URLs for NNTP newsgroup(s).