#include <netinet/in.h>
#endif
+#include <arpa/inet.h>
+
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
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
Name: ovirt-viewer
Version: 1.0.0
-Release: 2%{?dist}
+Release: 4%{?dist}
Summary: ovirt-viewer is a vnc viewer for ovirt managed vms
Group: Applications/System
%{_bindir}/ovirt-viewer
%changelog
+* Mon Jun 01 2009 <mmorsi@redhat.com> - 1.0.0-4
+- bugfixes, dns lookup and local tunnel port assignment
+
+* Wed May 20 2009 <mmorsi@redhat.com> - 1.0.0-3
+- changes to viewer to connect to ovirt server
+ through vnc proxy
+
* Thu Apr 30 2009 <mmorsi@redhat.com> - 1.0.0-2
- ssl support, see check-certificate cmd line flag
- wire up send key menu
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
+#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
/* constants */
-// port to try to listen on, if we can't, increment until we find one we can
-const int PORT_RANGE_START = 5600;
-
// max length of a vm name
const int VM_NAME_MAX_LEN = 250;
static gpointer
tunnel_thread (gpointer _data)
{
+ struct hostent *dns_serv;
+
//char vm_data[VM_NAME_MAX_LEN];
int local_server_socketfd, ovirt_server_socket, client_socketfd;
unsigned int local_server_len, client_len, ovirt_server_len;
struct sockaddr_in ovirt_server_address;
struct sockaddr_in client_address;
+ struct sockaddr_in local_server_address_lookup;
+ unsigned int local_server_address_lookup_len = sizeof(local_server_address_lookup);
+
GThread *client_server_gthread = NULL;
GThread *server_client_gthread = NULL;
DEBUG ("tunnel thread starting up");
// ovirt server address
+ dns_serv = gethostbyname(hostname);
+ if(dns_serv == NULL){
+ DEBUG("ovirt server lookup failed");
+ return NULL;
+ }
ovirt_server_address.sin_family = PF_INET;
- ovirt_server_address.sin_addr.s_addr = inet_addr(hostname);
+ ovirt_server_address.sin_addr.s_addr = ((struct in_addr*)(dns_serv->h_addr))->s_addr; //inet_addr(hostname);
ovirt_server_address.sin_port = htons(OVIRT_SERVER_PORT);
ovirt_server_len = sizeof(ovirt_server_address);
sockets = g_slist_prepend(sockets, c_socket);
// local server address
- tunnel_port = PORT_RANGE_START;
local_server_address.sin_family = PF_INET;
local_server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
- local_server_address.sin_port = htons(tunnel_port);
+ local_server_address.sin_port = 0;
local_server_len = sizeof(local_server_address);
// increment ports until one is available
- while(bind(local_server_socketfd, (struct sockaddr*)&local_server_address, local_server_len) < 0){
- tunnel_port += 1;
- local_server_address.sin_port += htons(tunnel_port);
+ if(bind(local_server_socketfd, (struct sockaddr*)&local_server_address, local_server_len) < 0){
+ DEBUG("tunnel bind failed");
+ return NULL;
}
+ getsockname(local_server_socketfd,
+ (struct sockaddr*) &local_server_address_lookup,
+ &local_server_address_lookup_len);
+ tunnel_port = (int)ntohs(local_server_address_lookup.sin_port);
DEBUG ("tunnel bound to local port %i", tunnel_port);
// increase client buffer size?