Skip to contentSkip to conversation

[5695] sockets: helper functions for qemu (Gerd Hoffman)

Qemu-devel Anthony Liguori 1 participant 1 message Nov 11, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

Revision: 5695

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5695
Author:   aliguori
Date:     2008-11-11 20:46:40 +0000 (Tue, 11 Nov 2008)

Log Message:
-----------
sockets: helper functions for qemu (Gerd Hoffman)

This patch creates a new source file qemu-sockets.c with a bunch of helper functions to create listening and connected sockets.

New features of this code are (a) support for searching for a free port in a given range and (b) support for IPv6.

The following patches put that code into use.

Compile fixes for Windows added by Anthony Liguori

Modified Paths:
--------------
trunk/Makefile.target
trunk/qemu-char.c
trunk/qemu-common.h
trunk/qemu_socket.h

Added Paths:
-----------
trunk/qemu-sockets.c

Modified: trunk/Makefile.target
===================================================================

Makefile.target +1 -1
@@ -589,7 +589,7 @@
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o net-checksum.o
 OBJS+=fw_cfg.o aio.o buffered_file.o migration.o migration-tcp.o qemu-char.o
-OBJS+=net.o
+OBJS+=net.o qemu-sockets.o
 ifdef CONFIG_KVM
 OBJS+=kvm.o kvm-all.o
 endif

Modified: trunk/qemu-char.c
===================================================================

qemu-char.c +2 -2
@@ -442,7 +442,7 @@
 
 
 #ifdef _WIN32
-int send_all(int fd, const uint8_t *buf, int len1)
+int send_all(int fd, const void *buf, int len1)
 {
     int ret, len;
 
@@ -487,7 +487,7 @@
     return len1 - len;
 }
 
-int send_all(int fd, const uint8_t *buf, int len1)
+int send_all(int fd, const void *buf, int len1)
 {
     return unix_write(fd, buf, len1);
 }

Modified: trunk/qemu-common.h
===================================================================

qemu-common.h +1 -0
@@ -29,6 +29,7 @@
 
 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
+#define WINVER 0x0501  /* needed for ipv6 bits */
 #include <windows.h>
 #define fsync _commit
 #define lseek _lseeki64

Added: trunk/qemu-sockets.c
===================================================================

qemu-sockets.c +400 -0

400 lines not on this page · raw message

Modified: trunk/qemu_socket.h
===================================================================

qemu_socket.h +13 -3
@@ -4,6 +4,7 @@
 
 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
+#define WINVER 0x0501  /* needed for ipv6 bits */
 #include <windows.h>
 #include <winsock2.h>
 #include <ws2tcpip.h>
@@ -28,15 +29,24 @@
 #define socket_error() errno
 #define closesocket(s) close(s)
 
-int parse_unix_path(struct sockaddr_un *uaddr, const char *str);
-
 #endif /* !_WIN32 */
 
+/* misc helpers */
 void socket_set_nonblock(int fd);
+int send_all(int fd, const void *buf, int len1);
+
+/* New, ipv6-ready socket helper functions, see qemu-sockets.c */
+int inet_listen(const char *str, char *ostr, int olen,
+                int socktype, int port_offset);
+int inet_connect(const char *str, int socktype);
+
+int unix_listen(const char *path, char *ostr, int olen);
+int unix_connect(const char *path);
+
+/* Old, ipv4 only bits.  Don't use for new code. */
 int parse_host_port(struct sockaddr_in *saddr, const char *str);
 int parse_host_src_port(struct sockaddr_in *haddr,
                         struct sockaddr_in *saddr,
                         const char *str);
-int send_all(int fd, const uint8_t *buf, int len1);
 
 #endif /* QEMU_SOCKET_H */