From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LfgdT-00087R-3v for qemu-devel@nongnu.org; Fri, 06 Mar 2009 15:27:11 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LfgdR-00086q-Py for qemu-devel@nongnu.org; Fri, 06 Mar 2009 15:27:10 -0500 Received: from [199.232.76.173] (port=46328 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfgdR-00086m-KL for qemu-devel@nongnu.org; Fri, 06 Mar 2009 15:27:09 -0500 Received: from savannah.gnu.org ([199.232.41.3]:42059 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LfgdR-0000Q7-4W for qemu-devel@nongnu.org; Fri, 06 Mar 2009 15:27:09 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LfgdO-0000cm-Br for qemu-devel@nongnu.org; Fri, 06 Mar 2009 20:27:06 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LfgdO-0000ch-5P for qemu-devel@nongnu.org; Fri, 06 Mar 2009 20:27:06 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Fri, 06 Mar 2009 20:27:06 +0000 Subject: [Qemu-devel] [6720] Enhance 'info vnc' monitor output ("Daniel P. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6720 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6720 Author: aliguori Date: 2009-03-06 20:27:05 +0000 (Fri, 06 Mar 2009) Log Message: ----------- Enhance 'info vnc' monitor output ("Daniel P. Berrange") The current 'info vnc' monitor output just displays the VNC server address as provided by the -vnc command line flag. This isn't particularly useful since it doesn't tell you what VNC is actually listening on. eg, if you use '-vnc :1' it is useful to know whether this translated to '0.0.0.0:5901' or chose IPv6 ':::5901'. It is also useful to know the address of the client that is currently connected. It is also useful to know the active authentication (if any). This patch tweaks the monitor output to look like: (qemu) info vnc Server: address: 0.0.0.0:5902 auth: vencrypt+x509 Client: none And when 2 clients are connected (qemu) info vnc Server: address: 0.0.0.0:5902 auth: vencrypt+x509 Client: address: 10.33.6.67:38621 Client: address: 10.33.6.63:38620 More data will be added to this later in the patch series... The 'addr_to_string' helper method in this patch is overly generic for the needs of this patch alone. This is because it will be re-used by the later SASL patches in this series, where the flexibility is important. vnc.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 127 insertions(+), 10 deletions(-) Signed-off-by: Daniel P. Berrange Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/vnc.c Modified: trunk/vnc.c =================================================================== --- trunk/vnc.c 2009-03-06 20:27:02 UTC (rev 6719) +++ trunk/vnc.c 2009-03-06 20:27:05 UTC (rev 6720) @@ -167,19 +167,136 @@ static VncDisplay *vnc_display; /* needed for info vnc */ static DisplayChangeListener *dcl; +static char *addr_to_string(const char *format, + struct sockaddr_storage *sa, + socklen_t salen) { + char *addr; + char host[NI_MAXHOST]; + char serv[NI_MAXSERV]; + int err; + + if ((err = getnameinfo((struct sockaddr *)sa, salen, + host, sizeof(host), + serv, sizeof(serv), + NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { + VNC_DEBUG("Cannot resolve address %d: %s\n", + err, gai_strerror(err)); + return NULL; + } + + if (asprintf(&addr, format, host, serv) < 0) + return NULL; + + return addr; +} + +static char *vnc_socket_local_addr(const char *format, int fd) { + struct sockaddr_storage sa; + socklen_t salen; + + salen = sizeof(sa); + if (getsockname(fd, (struct sockaddr*)&sa, &salen) < 0) + return NULL; + + return addr_to_string(format, &sa, salen); +} + +static char *vnc_socket_remote_addr(const char *format, int fd) { + struct sockaddr_storage sa; + socklen_t salen; + + salen = sizeof(sa); + if (getpeername(fd, (struct sockaddr*)&sa, &salen) < 0) + return NULL; + + return addr_to_string(format, &sa, salen); +} + +static const char *vnc_auth_name(VncDisplay *vd) { + switch (vd->auth) { + case VNC_AUTH_INVALID: + return "invalid"; + case VNC_AUTH_NONE: + return "none"; + case VNC_AUTH_VNC: + return "vnc"; + case VNC_AUTH_RA2: + return "ra2"; + case VNC_AUTH_RA2NE: + return "ra2ne"; + case VNC_AUTH_TIGHT: + return "tight"; + case VNC_AUTH_ULTRA: + return "ultra"; + case VNC_AUTH_TLS: + return "tls"; + case VNC_AUTH_VENCRYPT: +#ifdef CONFIG_VNC_TLS + switch (vd->subauth) { + case VNC_AUTH_VENCRYPT_PLAIN: + return "vencrypt+plain"; + case VNC_AUTH_VENCRYPT_TLSNONE: + return "vencrypt+tls+none"; + case VNC_AUTH_VENCRYPT_TLSVNC: + return "vencrypt+tls+vnc"; + case VNC_AUTH_VENCRYPT_TLSPLAIN: + return "vencrypt+tls+plain"; + case VNC_AUTH_VENCRYPT_X509NONE: + return "vencrypt+x509+none"; + case VNC_AUTH_VENCRYPT_X509VNC: + return "vencrypt+x509+vnc"; + case VNC_AUTH_VENCRYPT_X509PLAIN: + return "vencrypt+x509+plain"; + default: + return "vencrypt"; + } +#else + return "vencrypt"; +#endif + } + return "unknown"; +} + +#define VNC_SOCKET_FORMAT_PRETTY "local %s:%s" + +static void do_info_vnc_client(Monitor *mon, VncState *client) +{ + char *clientAddr = + vnc_socket_remote_addr(" address: %s:%s\n", + client->csock); + if (!clientAddr) + return; + + monitor_printf(mon, "Client:\n"); + monitor_printf(mon, "%s", clientAddr); + free(clientAddr); +} + void do_info_vnc(Monitor *mon) { - if (vnc_display == NULL || vnc_display->display == NULL) - monitor_printf(mon, "VNC server disabled\n"); - else { - monitor_printf(mon, "VNC server active on: "); - monitor_print_filename(mon, vnc_display->display); - monitor_printf(mon, "\n"); + if (vnc_display == NULL || vnc_display->display == NULL) { + monitor_printf(mon, "Server: disabled\n"); + } else { + char *serverAddr = vnc_socket_local_addr(" address: %s:%s\n", + vnc_display->lsock); - if (vnc_display->clients == NULL) - monitor_printf(mon, "No client connected\n"); - else - monitor_printf(mon, "Client connected\n"); + if (!serverAddr) + return; + + monitor_printf(mon, "Server:\n"); + monitor_printf(mon, "%s", serverAddr); + free(serverAddr); + monitor_printf(mon, " auth: %s\n", vnc_auth_name(vnc_display)); + + if (vnc_display->clients) { + VncState *client = vnc_display->clients; + while (client) { + do_info_vnc_client(mon, client); + client = client->next; + } + } else { + monitor_printf(mon, "Client: none\n"); + } } }