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_stddef.h>
27 struct v3_socket_hooks * sock_hooks = 0;
29 void V3_Init_Sockets(struct v3_socket_hooks * hooks) {
30 PrintInfo("Initializing Socket Interface\n");
32 PrintDebug("V3 sockets inited\n");
39 uint32_t v3_inet_addr(const char * ip_str) {
43 uint32_t * pp = parts;
48 * Collect number up to ``.''.
49 * Values are specified as for C:
50 * 0x=hex, 0=octal, 1-9=decimal.
61 if ((c == 'x') || (c == 'X')) {
71 val = (val * base) + (int)(c - '0');
73 } else if ((base == 16) && (isxdigit(c))) {
74 val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
85 * a.b.c (with c treated as 16 bits)
86 * a.b (with b treated as 24 bits)
88 if (pp >= parts + 3) {
100 * Check for trailing characters.
103 ( (!isprint(c)) || (!isspace(c)) ) ) {
108 * Concoct the address according to
109 * the number of parts specified.
115 return 0; /* initial nondigit */
117 case 1: /* a -- 32 bits */
120 case 2: /* a.b -- 8.24 bits */
121 if (val > 0xffffffUL) {
125 val |= parts[0] << 24;
128 case 3: /* a.b.c -- 8.8.16 bits */
133 val |= (parts[0] << 24) | (parts[1] << 16);
136 case 4: /* a.b.c.d -- 8.8.8.8 bits */
141 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
146 return v3_htonl(val);
153 char * v3_inet_ntoa(uint32_t addr) {
163 ap = (uint8_t *)&addr;
165 for(n = 0; n < 4; n++) {
169 rem = *ap % (uint8_t)10;
173 inv[i++] = '0' + rem;
193 uint16_t v3_htons(uint16_t n) {
194 return (((n & 0xff) << 8) | ((n & 0xff00) >> 8));
198 uint16_t v3_ntohs(uint16_t n) {
203 uint32_t v3_htonl(uint32_t n) {
204 return (((n & 0xff) << 24) |
205 ((n & 0xff00) << 8) |
206 ((n & 0xff0000UL) >> 8) |
207 ((n & 0xff000000UL) >> 24));
211 uint32_t v3_ntohl(uint32_t n) {