Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


cleanup of debugging functions
[palacios.git] / palacios / src / palacios / vmm_socket.c
index dbc19c0..acf881d 100644 (file)
 
 #include <palacios/vmm_socket.h>
 #include <palacios/vmm.h>
+#include <palacios/vmm_debug.h>
+#include <palacios/vmm_types.h>
 
 
 struct v3_socket_hooks * sock_hooks = 0;
 
+void V3_Init_Sockets(struct v3_socket_hooks * hooks) {
+    sock_hooks = hooks;
+    PrintDebug("V3 sockets inited\n");
 
+    return;
+}
 
 
-void V3_Init_Sockets(struct v3_socket_hooks * hooks) {
-  PrintInfo("Initializing Socket Interface\n");
-  sock_hooks = hooks;
-}
 
+uint32_t v3_inet_addr(const char * ip_str) {
+    uint32_t val;
+    int base, n, c;
+    uint32_t parts[4];
+    uint32_t * pp = parts;
+
+    c = *ip_str;
+    for (;;) {
+       /*
+        * Collect number up to ``.''.
+        * Values are specified as for C:
+        * 0x=hex, 0=octal, 1-9=decimal.
+        */
+       if (!isdigit(c)) {
+           return (0);
+       }
+
+       val = 0;
+       base = 10;
+
+       if (c == '0') {
+           c = *++ip_str;
+           if ((c == 'x') || (c == 'X')) {
+               base = 16;
+               c = *++ip_str;
+           } else {
+               base = 8;
+           }
+       }
+
+       for (;;) {
+           if (isdigit(c)) {
+               val = (val * base) + (int)(c - '0');
+               c = *++ip_str;
+           } else if ((base == 16) && (isxdigit(c))) {
+               val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
+               c = *++ip_str;
+           } else {
+               break;
+           }
+       }
+
+       if (c == '.') {
+           /*
+            * Internet format:
+            *  a.b.c.d
+            *  a.b.c   (with c treated as 16 bits)
+            *  a.b (with b treated as 24 bits)
+            */
+           if (pp >= parts + 3) {
+               return 0;
+           }
+
+           *pp++ = val;
+           c = *++ip_str;
+       } else {
+           break;
+       }
+    }
+
+    /*
+     * Check for trailing characters.
+     */
+    if ( (c != '\0') && 
+        ( (!isprint(c)) || (!isspace(c)) ) ) {
+       return 0;
+    }
+
+    /*
+     * Concoct the address according to
+     * the number of parts specified.
+     */
+    n = pp - parts + 1;
+
+    switch (n) {
+       case 0:
+           return 0;       /* initial nondigit */
+
+       case 1:             /* a -- 32 bits */
+           break;
+
+       case 2:             /* a.b -- 8.24 bits */
+           if (val > 0xffffffUL) {
+               return 0;
+           }
 
+           val |= parts[0] << 24;
+           break;
 
-void v3_init_sock_set(struct v3_sock_set * sock_set) {
-  sock_set->num_socks = 0;
-  sock_set->socks = NULL;
+       case 3:             /* a.b.c -- 8.8.16 bits */
+           if (val > 0xffff) {
+               return 0;
+           }
 
+           val |= (parts[0] << 24) | (parts[1] << 16);
+           break;
+
+       case 4:             /* a.b.c.d -- 8.8.8.8 bits */
+           if (val > 0xff) {
+               return 0;
+           }
+
+           val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+           break;
+    }
+  
+    if (val) {
+       return v3_htonl(val);
+    }
+  
+    return -1;
 }
 
 
+char * v3_inet_ntoa(uint32_t addr) {
+    static char str[16];
+    char inv[3];
+    char * rp;
+    uint8_t * ap;
+    uint8_t rem;
+    uint8_t n;
+    uint8_t i;
+
+    rp = str;
+    ap = (uint8_t *)&addr;
 
+    for(n = 0; n < 4; n++) {
+       i = 0;
 
+       do {
+           rem = *ap % (uint8_t)10;
 
-/* This should probably check if the socket is already added */
-// adds socket to the sockset
-void v3_set_sock(struct v3_sock_set * sock_set, V3_SOCK sock) {
-  struct v3_sock_entry * new_entry = V3_Malloc(sizeof(struct v3_sock_entry));
+           *ap /= (uint8_t)10;
 
-  new_entry->sock = sock;
-  new_entry->is_set = 0;
+           inv[i++] = '0' + rem;
+       } while(*ap);
 
-  if (sock_set->socks) {
-    new_entry->next = sock_set->socks;
-  }
+       while(i--) {
+           *rp++ = inv[i];
+       }
 
-  sock_set->socks = new_entry;
+       *rp++ = '.';
+       ap++;
+    }
+
+    *--rp = 0;
 
-  sock_set->num_socks++;
+    return str;
 }
 
 
-// deletes socket from sockset
-void v3_clr_sock(struct v3_sock_set * sock_set, V3_SOCK sock) {
-  struct v3_sock_entry * iter, * back_ptr;
 
-  iter = sock_set->socks;
-  back_ptr = NULL;
 
-  v3_foreach_sock(sock_set, iter) {
-    if (iter->sock == sock) {
-      if (back_ptr == NULL) {
-       sock_set->socks = iter->next;
-      } else {
-       back_ptr->next = iter->next;
-      }
 
-      V3_Free(iter);
+uint16_t v3_htons(uint16_t n) {
+    return (((n & 0xff) << 8) | ((n & 0xff00) >> 8));
+}
 
-      sock_set->num_socks--;
-      break;
-    }
 
-    back_ptr = iter;
-  }
+uint16_t v3_ntohs(uint16_t n) {
+    return v3_htons(n);
 }
 
-// checks is_set vairable 
-int v3_isset_sock(struct v3_sock_set * sock_set, V3_SOCK sock) {
-  struct v3_sock_entry * iter;
 
-  v3_foreach_sock(sock_set, iter) {
-    if (iter->sock == sock) {
-      return iter->is_set;
-    }
-  }
-  return -1;
+uint32_t v3_htonl(uint32_t n) {
+    return (((n & 0xff) << 24) |
+           ((n & 0xff00) << 8) |
+           ((n & 0xff0000UL) >> 8) |
+           ((n & 0xff000000UL) >> 24));
 }
 
 
-// clears all is_set variables.
-void v3_zero_sockset(struct v3_sock_set * sock_set) {
-  struct v3_sock_entry * iter;
-  v3_foreach_sock(sock_set, iter) {
-    iter->is_set = 0;
-  }
+uint32_t v3_ntohl(uint32_t n) {
+  return v3_htonl(n);
 }