"Use '" PACKAGE " --help' to see a list of available command line options";
static const GOptionEntry options[] = {
"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,
{ "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,
- serv = gethostbyname(vnchost);
- if(serv == NULL){
+ result = getaddrinfo(vnchost, port, NULL, &vnc_addr);
+ if(result != 0 || vnc_addr == NULL)
- 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);