#include <netinet/in.h>
#endif
+#include <arpa/inet.h>
+
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
gboolean debug = 0;
+gboolean verbose = 0;
+
/* Usually /etc/pki/tls/certs/ca-bundle.crt unless overridden during
* configure or on the command line.
*/
*/
static GSList *vmlist = NULL;
+/* internal.h shared constructs */
+const char* hostname;
+struct vm* vm_in_focus;
+int ovirt_server_vnc_port = 5900;
+
/* Private functions. */
static void start_ui (void);
static GtkWidget *menu_item_new (int which_menu);
"Use '" PACKAGE " --help' to see a list of available command line options";
static const GOptionEntry options[] = {
+ { "port", 'p', 0, G_OPTION_ARG_INT, &ovirt_server_vnc_port,
+ "set port which to connect to server via vnc", NULL },
{ "cainfo", 0, 0, G_OPTION_ARG_STRING, &cainfo,
"set the path of the CA certificate bundle", NULL },
{ "check-certificate", 0, 0, G_OPTION_ARG_NONE, &check_cert,
"check the SSL certificate of the server", NULL },
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
"turn on debugging messages", NULL },
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+ "turn on verbose messages", NULL },
{ "version", 'V', 0, G_OPTION_ARG_NONE, &print_version,
"display version and exit", NULL },
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
* processed in the main thread - see:
* http://mail.gnome.org/archives/gtk-app-devel-list/2007-March/msg00232.html
*
+ * A tunnel thread is also started to locally listen for vnc packets
+ * and make them proxyable, adding the vm name, before forwarding onto
+ * the server
+ *
* Note that under Win32 you must confine all Gtk/Gdk interactions
* to a single thread - see:
* http://developer.gimp.org/api/2.0/gdk/gdk-Threads.html
gtk_main ();
stop_wui_thread ();
+ stop_tunnel();
exit (0);
}
const char *authors[] = {
"Richard W.M. Jones <rjones@redhat.com>",
"Daniel P. Berrange <berrange@redhat.com>",
+ "Mohammed Morsi <mmorsi@redhat.com>",
NULL
};
static void
connect_to_wui (GtkWidget *widget, gpointer data)
{
- const char *hostname;
char *uri;
int len;
snprintf (uri, len, HTTPS "://%s/ovirt", hostname);
wui_thread_send_connect (uri);
+ start_tunnel();
}
static void
int i, uuidlen, len, fd;
GtkWidget *child;
const char *label;
- const char* hostname;
char *label2;
char new_title[97]; // 47 chars for title + 50 for vm name
return;
}
+ // FIXME on notebook tab switch, change vm_in_focus
+ vm_in_focus = vm;
+
/* This VM isn't in the notebook already, so create a new console. */
- hostname = gtk_entry_get_text (GTK_ENTRY (ca_hostname));
- fd = viewer_open_vnc_socket(hostname, vm->forward_vnc_port);
+ DEBUG ("connecting to local tunnel on port %i", tunnel_port);
+ fd = viewer_open_vnc_socket("127.0.0.1", tunnel_port);
if (fd == -1) return; /* We've already given an error. */
child = vnc_display_new ();
gtk_widget_destroy(GTK_WIDGET(dialog));
}
-#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME)
+#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS)
static int
viewer_open_vnc_socket(const char* vnchost, int vncport)
{
- int socketfd;
- struct hostent *serv;
- struct sockaddr_in serv_addr;
+ int result, socketfd;
+ char port[10];
+ struct addrinfo* vnc_addr;
- socketfd = socket(PF_INET, SOCK_STREAM, 0);
- if(socketfd < 0){
- return -1;
- }
+ sprintf(port, "%d", vncport);
- serv = gethostbyname(vnchost);
- if(serv == NULL){
+ result = getaddrinfo(vnchost, port, NULL, &vnc_addr);
+ if(result != 0 || vnc_addr == NULL)
return -1;
- }
- 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;
+ // just use first found, ignoring rest
+ socketfd = socket(vnc_addr->ai_family,
+ vnc_addr->ai_socktype,
+ vnc_addr->ai_protocol);
- if (connect(socketfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0){
- return -1;
- }
+ if(connect(socketfd, vnc_addr->ai_addr, vnc_addr->ai_addrlen) <0)
+ socketfd = -1;
+
+ freeaddrinfo(vnc_addr);
return socketfd;
}
-#endif /* defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME) */
+#endif /* defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) */
/* Remove all menu items from the Connect menu. */
static void