#include <gtk/gtk.h>
#include <vncdisplay.h>
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
static void viewer_initialized (GtkWidget *vnc, GtkWidget *data);
static void viewer_disconnected (GtkWidget *vnc);
static void viewer_credential (GtkWidget *vnc, GValueArray *credList);
-static int viewer_open_tunnel_ssh (const char *sshhost, int sshport, const char *sshuser, int vncport);
+static int viewer_open_vnc_socket (const char *vnchost, int vncport);
/* For any widgets accessed from multiple functions. */
static GtkWidget *window;
int i, uuidlen, len, fd;
GtkWidget *child;
const char *label;
+ const char* hostname;
char *label2;
DEBUG ("searching tabs for uuid %s", vm->uuid);
DEBUG ("not found, creating new tab");
/* This VM isn't in the notebook already, so create a new console. */
- fd = viewer_open_tunnel_ssh (/*vm->host XXX*/ "192.168.50.6",
- 0, /* Default SSH port. */
- "root", /* Root account. */
- vm->vnc_port);
+ hostname = gtk_entry_get_text (GTK_ENTRY (ca_hostname));
+ fd = viewer_open_vnc_socket(hostname, vm->forward_vnc_port);
if (fd == -1) return; /* We've already given an error. */
child = vnc_display_new ();
gtk_widget_destroy(GTK_WIDGET(dialog));
}
-#if defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK)
+#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME)
-static int viewer_open_tunnel(const char **cmd)
+static int
+viewer_open_vnc_socket(const char* vnchost, int vncport)
{
- int fd[2];
- pid_t pid;
+ int socketfd;
+ struct hostent *serv;
+ struct sockaddr_in serv_addr;
- if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd) < 0)
- return -1;
+ socketfd = socket(PF_INET, SOCK_STREAM, 0);
+ if(socketfd < 0){
+ return -1;
+ }
- pid = fork();
- if (pid == -1) {
- close(fd[0]);
- close(fd[1]);
- return -1;
- }
+ serv = gethostbyname(vnchost);
+ if(serv == NULL){
+ return -1;
+ }
- if (pid == 0) { /* child */
- close(fd[0]);
- close(0);
- close(1);
- if (dup(fd[1]) < 0)
- _exit(1);
- if (dup(fd[1]) < 0)
- _exit(1);
- close(fd[1]);
- execvp("ssh", (char *const*)cmd);
- _exit(1);
- }
- close(fd[1]);
- return fd[0];
-}
+ serv_addr.sin_family = PF_INET;
+ serv_addr.sin_port = htons(vncport);
+ serv_addr.sin_addr.s_addr = ((struct in_addr *)(serv->h_addr))->s_addr;
-static int
-viewer_open_tunnel_ssh (const char *sshhost, int sshport, const char *sshuser,
- int vncport)
-{
- const char *cmd[10];
- char portstr[50], portstr2[50];
- int n = 0;
-
- if (!sshport)
- sshport = 22;
-
- snprintf (portstr, sizeof portstr, "%d", sshport);
- snprintf (portstr2, sizeof portstr2, "%d", vncport);
-
- cmd[n++] = "ssh";
- cmd[n++] = "-p";
- cmd[n++] = portstr;
- if (sshuser) {
- cmd[n++] = "-l";
- cmd[n++] = sshuser;
+ if (connect(socketfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0){
+ return -1;
}
- cmd[n++] = sshhost;
- cmd[n++] = "nc";
- cmd[n++] = "localhost";
- cmd[n++] = portstr2;
- cmd[n++] = NULL;
- return viewer_open_tunnel(cmd);
+ return socketfd;
}
-#endif /* defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK) */
+#endif /* defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME) */
/* Remove all menu items from the Connect menu. */
static void
vm.hostid = -1;
vm.id = -1;
vm.vnc_port = -1;
+ vm.forward_vnc_port = -1;
vm.mem_allocated = -1;
vm.mem_used = -1;
vm.vcpus_allocated = -1;
xmlFree (str);
}
}
+ else if (xmlStrcmp (p->name, (const xmlChar *) "forward-vnc-port") == 0) {
+ str = xmlNodeGetContent (p);
+ if (str != NULL) {
+ vm.forward_vnc_port = strtol ((char *) str, NULL, 10);
+ xmlFree (str);
+ }
+ }
else if (xmlStrcmp (p->name, (const xmlChar *) "vnic-mac-addr") == 0) {
str = xmlNodeGetContent (p);
if (str != NULL) {
DEBUG ("required field \"description\" missing from <vm> structure");
else if (vm.vnc_port == -1)
DEBUG ("required field \"vnc-port\" missing from <vm> structure");
+ else if (vm.forward_vnc_port == -1)
+ DEBUG ("required field \"forward-vnc-port\" missing from <vm> structure");
else if (vm.uuid == NULL)
DEBUG ("required field \"uuid\" missing from <vm> structure");
else