diff mbox

[4/8] VNC: Add 'family' key

Message ID 1263487859-6318-5-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino Jan. 14, 2010, 4:50 p.m. UTC
It contains the socket adress family name, like "ipv4" or
"ipv6".

This is useful for clients so that they can interpret the
'host' key reliably.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 vnc.c |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

Comments

Gerd Hoffmann Jan. 15, 2010, 7:54 a.m. UTC | #1
> +static QString *get_sock_family(const struct sockaddr_storage *sa)
> +{
> +    const char *name;
> +
> +    switch (sa->ss_family)
> +    {
> +        case AF_INET:
> +            name = "ipv4";
> +            break;
> +        case AF_INET6:
> +            name = "ipv6";
> +            break;
> +        default:
> +            name = "unknown";
> +            break;
> +    }
> +
> +    return qstring_from_str(name);
> +}

qemu-socket has inet_strfamily() already.  You might want to un-static 
that one, then simply do

   return qstring_from_str(inet_strfamily(sa->ss_family));

cheers,
   Gerd
Luiz Capitulino Jan. 15, 2010, 11:54 a.m. UTC | #2
On Fri, 15 Jan 2010 08:54:56 +0100
Gerd Hoffmann <kraxel@redhat.com> wrote:

> > +static QString *get_sock_family(const struct sockaddr_storage *sa)
> > +{
> > +    const char *name;
> > +
> > +    switch (sa->ss_family)
> > +    {
> > +        case AF_INET:
> > +            name = "ipv4";
> > +            break;
> > +        case AF_INET6:
> > +            name = "ipv6";
> > +            break;
> > +        default:
> > +            name = "unknown";
> > +            break;
> > +    }
> > +
> > +    return qstring_from_str(name);
> > +}
> 
> qemu-socket has inet_strfamily() already.  You might want to un-static 
> that one, then simply do
> 
>    return qstring_from_str(inet_strfamily(sa->ss_family));

 Will do and resend.

 Thanks Gerd.
diff mbox

Patch

diff --git a/vnc.c b/vnc.c
index e35cc36..e023824 100644
--- a/vnc.c
+++ b/vnc.c
@@ -100,6 +100,26 @@  char *vnc_socket_remote_addr(const char *format, int fd) {
     return addr_to_string(format, &sa, salen);
 }
 
+static QString *get_sock_family(const struct sockaddr_storage *sa)
+{
+    const char *name;
+
+    switch (sa->ss_family)
+    {
+        case AF_INET:
+            name = "ipv4";
+            break;
+        case AF_INET6:
+            name = "ipv6";
+            break;
+        default:
+            name = "unknown";
+            break;
+    }
+
+    return qstring_from_str(name);
+}
+
 static int put_addr_qdict(QDict *qdict, struct sockaddr_storage *sa,
                           socklen_t salen)
 {
@@ -118,6 +138,7 @@  static int put_addr_qdict(QDict *qdict, struct sockaddr_storage *sa,
 
     qdict_put(qdict, "host", qstring_from_str(host));
     qdict_put(qdict, "service", qstring_from_str(serv));
+    qdict_put(qdict, "family", get_sock_family(sa));
 
     return 0;
 }
@@ -294,6 +315,7 @@  void do_info_vnc_print(Monitor *mon, const QObject *data)
  *
  * - "enabled": true or false
  * - "host": server's IP address
+ * - "family": address family ("ipv4" or "ipv6")
  * - "service": server's port number
  * - "auth": authentication method
  * - "clients": a QList of all connected clients
@@ -301,6 +323,7 @@  void do_info_vnc_print(Monitor *mon, const QObject *data)
  * Clients are described by a QDict, with the following information:
  *
  * - "host": client's IP address
+ * - "family": address family ("ipv4" or "ipv6")
  * - "service": client's port number
  * - "x509_dname": TLS dname (optional)
  * - "sasl_username": SASL username (optional)
@@ -308,7 +331,8 @@  void do_info_vnc_print(Monitor *mon, const QObject *data)
  * Example:
  *
  * { "enabled": true, "host": "0.0.0.0", "service": "50402", "auth": "vnc",
- *   "clients": [ { "host": "127.0.0.1", "service": "50401" } ] }
+ *   "family": "ipv4",
+ *   "clients": [{ "host": "127.0.0.1", "service": "50401", "family": "ipv4" }]}
  */
 void do_info_vnc(Monitor *mon, QObject **ret_data)
 {