2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #include <palacios/vmm_socket.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vmm_debug.h>
24 #include <palacios/vmm_types.h>
27 struct v3_socket_hooks * sock_hooks = 0;
29 void V3_Init_Sockets(struct v3_socket_hooks * hooks) {
31 PrintDebug("V3 sockets inited\n");
38 uint32_t v3_inet_addr(const char * ip_str) {
42 uint32_t * pp = parts;
47 * Collect number up to ``.''.
48 * Values are specified as for C:
49 * 0x=hex, 0=octal, 1-9=decimal.
60 if ((c == 'x') || (c == 'X')) {
70 val = (val * base) + (int)(c - '0');
72 } else if ((base == 16) && (isxdigit(c))) {
73 val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
84 * a.b.c (with c treated as 16 bits)
85 * a.b (with b treated as 24 bits)
87 if (pp >= parts + 3) {
99 * Check for trailing characters.
102 ( (!isprint(c)) || (!isspace(c)) ) ) {
107 * Concoct the address according to
108 * the number of parts specified.
114 return 0; /* initial nondigit */
116 case 1: /* a -- 32 bits */
119 case 2: /* a.b -- 8.24 bits */
120 if (val > 0xffffffUL) {
124 val |= parts[0] << 24;
127 case 3: /* a.b.c -- 8.8.16 bits */
132 val |= (parts[0] << 24) | (parts[1] << 16);
135 case 4: /* a.b.c.d -- 8.8.8.8 bits */
140 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
145 return v3_htonl(val);
152 char * v3_inet_ntoa(uint32_t addr) {
162 ap = (uint8_t *)&addr;
164 for(n = 0; n < 4; n++) {
168 rem = *ap % (uint8_t)10;
172 inv[i++] = '0' + rem;
192 uint16_t v3_htons(uint16_t n) {
193 return (((n & 0xff) << 8) | ((n & 0xff00) >> 8));
197 uint16_t v3_ntohs(uint16_t n) {
202 uint32_t v3_htonl(uint32_t n) {
203 return (((n & 0xff) << 24) |
204 ((n & 0xff00) << 8) |
205 ((n & 0xff0000UL) >> 8) |
206 ((n & 0xff000000UL) >> 24));
210 uint32_t v3_ntohl(uint32_t n) {