diff mbox

[3/3] net/socket: allow ipv6 for net_socket_listen_init and net_socket_connect_init

Message ID 61c052c3f189fb1ab0191cc1641578b94de6cc05.1300454243.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela March 18, 2011, 1:22 p.m. UTC
Remove use of parse_host_port.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 net/socket.c |   55 ++++++++++---------------------------------------------
 1 files changed, 10 insertions(+), 45 deletions(-)
diff mbox

Patch

diff --git a/net/socket.c b/net/socket.c
index de46506..aa0b2d8 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -391,24 +391,12 @@  static int net_socket_listen_init(VLANState *vlan,
 {
     NetSocketListenState *s;
     int fd, ret;
-    struct sockaddr_in saddr;
-
-    if (parse_host_port(&saddr, host_str) < 0)
-        return -1;

     s = qemu_mallocz(sizeof(NetSocketListenState));

-    fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
-    if (fd < 0) {
-        perror("socket");
-        return -1;
-    }
-    socket_set_nonblock(fd);
-    socket_set_reuseaddr(fd);
-
-    ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
+    ret = tcp_server_start(host_str, &fd);
     if (ret < 0) {
-        perror("bind");
+        fprintf(stderr, "tcp_server_start: %s\n", strerror(ret));
         return -1;
     }
     ret = listen(fd, 0);
@@ -430,40 +418,17 @@  static int net_socket_connect_init(VLANState *vlan,
                                    const char *host_str)
 {
     NetSocketState *s;
-    int fd, connected, ret, err;
+    int fd, connected, ret;
     struct sockaddr_in saddr;

-    if (parse_host_port(&saddr, host_str) < 0)
-        return -1;
-
-    fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
-    if (fd < 0) {
-        perror("socket");
+    ret = tcp_client_start(host_str, &fd);
+    if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) {
+        connected = 0;
+    } else if (ret < 0) {
+        closesocket(fd);
         return -1;
-    }
-    socket_set_nonblock(fd);
-
-    connected = 0;
-    for(;;) {
-        ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
-        if (ret < 0) {
-            err = socket_error();
-            if (err == EINTR || err == EWOULDBLOCK) {
-            } else if (err == EINPROGRESS) {
-                break;
-#ifdef _WIN32
-            } else if (err == WSAEALREADY || err == WSAEINVAL) {
-                break;
-#endif
-            } else {
-                perror("connect");
-                closesocket(fd);
-                return -1;
-            }
-        } else {
-            connected = 1;
-            break;
-        }
+    } else {
+        connected = 1;
     }
     s = net_socket_fd_init(vlan, model, name, fd, connected);
     if (!s)