[Libvirt-cim] [PATCH 1 of 4] Add vnc_ports struct and functions for building a list of ports

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Tue Oct 21 01:59:03 UTC 2008


# HG changeset patch
# User kaitlin at elm3b43.beaverton.ibm.com
# Date 1224552268 25200
# Node ID 155077ac9e3ca778dc8564aa86e991f24f373e7e
# Parent  f0a209b602e707305a713611097310ec503451df
Add vnc_ports struct and functions for building a list of ports.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r f0a209b602e7 -r 155077ac9e3c src/Virt_KVMRedirectionSAP.c
--- a/src/Virt_KVMRedirectionSAP.c	Wed Oct 08 09:13:55 2008 -0700
+++ b/src/Virt_KVMRedirectionSAP.c	Mon Oct 20 18:24:28 2008 -0700
@@ -39,7 +39,75 @@
 
 #include "Virt_KVMRedirectionSAP.h"
 
+#define PROC_TCP "/proc/net/tcp"
+#define VNC_PORT_MIN 5900
+#define VNC_PORT_MAX 5999
+#define HASH_SIZE    128
+
 const static CMPIBroker *_BROKER;
+
+struct vnc_ports {
+        char **list;
+        unsigned int max;
+        unsigned int cur;
+};
+
+static int resize(struct vnc_ports *list, int newmax)
+{
+        char **newlist;
+        int i;
+
+        newlist = realloc(list->list, newmax * sizeof(char *));
+        if (!newlist)
+                return 0;
+
+        list->max = newmax;
+        list->list = newlist;
+
+        for (i = list->cur; i < list->max; i++)
+                list->list[i] = NULL;
+
+        return 1;
+}
+
+static void vnc_list_init(struct vnc_ports *vnc_hash[])
+{
+        int i;
+
+        for (i = 0; i < HASH_SIZE; i++) {
+                vnc_hash[i] = malloc(sizeof(struct vnc_ports));
+                vnc_hash[i]->list = NULL;
+                vnc_hash[i]->cur = vnc_hash[i]->max = 0;
+       }
+}
+
+static void vnc_list_free(struct vnc_ports *vnc_hash[])
+{
+        int i;
+
+       for (i = 0; i < HASH_SIZE; i++) {
+                if (vnc_hash[i]->list != NULL)
+                        free(vnc_hash[i]->list);
+        }
+        vnc_list_init(vnc_hash);
+}
+
+static int vnc_list_add(struct vnc_ports *list, char *port)
+{
+       if ((list->cur + 1) >= list->max) {
+                int ret;
+
+                ret = resize(list, list->max + 5);
+
+                if (!ret)
+                       return 0;
+        }
+
+        list->list[list->cur] = strdup(port);
+        list->cur++;
+
+        return 1;
+}
 
 static int inst_from_dom(const CMPIBroker *broker,
                          const CMPIObjectPath *ref,




More information about the Libvirt-cim mailing list