From patchwork Thu May 12 17:03:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9084441 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C6BD9BF29F for ; Thu, 12 May 2016 17:03:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1670E20211 for ; Thu, 12 May 2016 17:03:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C891201F5 for ; Thu, 12 May 2016 17:03:44 +0000 (UTC) Received: from localhost ([::1]:58863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0u1X-0001SW-2o for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 May 2016 13:03:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0u1O-0001Os-Qs for qemu-devel@nongnu.org; Thu, 12 May 2016 13:03:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0u1L-0000rB-GK for qemu-devel@nongnu.org; Thu, 12 May 2016 13:03:34 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:36758) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0u1L-0000qw-7h for qemu-devel@nongnu.org; Thu, 12 May 2016 13:03:31 -0400 Received: by mail-pf0-x241.google.com with SMTP id g132so7042239pfb.3 for ; Thu, 12 May 2016 10:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=NObJ3mPLi5HxL/VDuCxZzCXPL1T4hzOPoSVjhKv0vWg=; b=iXyZumbjfQ4iRkgq9/SK0zDD7Y/j+oHp1AQ+0cN/bnq8yaQFzx3t7nb/x2yPM5yZI4 F+gAbmlWK6VmYQIT2PTBGuEtoRZZ9F6UtxMbzgLQ5L7hTB8DGPZ3qq+lL3O/nWGqbY27 y1OrY6LIfv87KovmoWWHPvKV6uKdOforJQegIGG99soH+DHOs6fAdmO/xn4Fx6eKUSPs IY0r2mgPXWSxhqkEDxB3OnhF+R1p36DbMe4kSws0LcFo3ZJPKGQ0ocdEWZOSAtOgfs3B frWOGmgSv8sSBWKt7DZ13ZUqMT4/fTEe2wBcIS1vreN7fcsgJEQIHYRRwIsloGqcnuEJ 52Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NObJ3mPLi5HxL/VDuCxZzCXPL1T4hzOPoSVjhKv0vWg=; b=dwsYEmLg+ycqd6WtrHN0Tn7nzncIa0JeZ9AaLUu3e2YQwX2RmWg7Ta680tLDWuZa0k wIPSenLkUuHU2gR11FTaDXSwcPXKhtJkWpVUtKz6KsKQHWDWCX7ly0upLetOaeym6/sP /KkwNZJhaj4Ymziuh61Cbyps9JyRR8TP47ycb7Btiy/0cJ44Ev10Uo9vMudU0P58Rk3Y Q4UagSfom+u5ZEKTn4Ks6KEzDvoQv/4XNBzSTfK/t6By2u+Y8MSmdTEw8yWyfQ1in+zu ODA9DL+NmwHrQbcPaV78icPBPV6ftbCP8+4Se61veg9BBfNMK/9OSIVPlb+ERl58Pf7w kmfA== X-Gm-Message-State: AOPr4FXcD2kay6HB+sZit8MeG0bJPxAlXanIpaguiuaSh4Z/Vt3o/vZy9k/fQ5Ab1pAKWQ== X-Received: by 10.98.41.70 with SMTP id p67mr15494270pfp.93.1463072610435; Thu, 12 May 2016 10:03:30 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.194]) by smtp.gmail.com with ESMTPSA id 194sm21193195pfv.8.2016.05.12.10.03.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 May 2016 10:03:29 -0700 (PDT) From: Ashijeet Acharya To: jasowang@redhat.com Date: Thu, 12 May 2016 22:33:05 +0530 Message-Id: <1463072585-10566-1-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH] Modify net/socket.c to use socket_* functions from include/qemu/sockets.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Ashijeet Acharya Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Changed the listen(),connect(),parse_host_port() in net/socket.c with the socket_*()functions in include/qemu/sockets.h. Signed-off-by: Ashijeet Acharya --- net/socket.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/net/socket.c b/net/socket.c index 9fa2cd8..b6e2f3e 100644 --- a/net/socket.c +++ b/net/socket.c @@ -522,10 +522,12 @@ static int net_socket_listen_init(NetClientState *peer, { NetClientState *nc; NetSocketState *s; - struct sockaddr_in saddr; + SocketAddress *saddr; int fd, ret; + Error *local_error = NULL; + saddr = g_new0(SocketAddress, 1); - if (parse_host_port(&saddr, host_str) < 0) + if (socket_parse(host_str, &local_error) < 0) return -1; fd = qemu_socket(PF_INET, SOCK_STREAM, 0); @@ -536,14 +538,9 @@ static int net_socket_listen_init(NetClientState *peer, qemu_set_nonblock(fd); socket_set_fast_reuse(fd); + saddr = socket_local_address(fd, &local_error); - ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)); - if (ret < 0) { - perror("bind"); - closesocket(fd); - return -1; - } - ret = listen(fd, 0); + ret = socket_listen(saddr, &local_error); if (ret < 0) { perror("listen"); closesocket(fd); @@ -557,6 +554,7 @@ static int net_socket_listen_init(NetClientState *peer, s->nc.link_down = true; qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); + g_free(saddr); return 0; } @@ -567,9 +565,11 @@ static int net_socket_connect_init(NetClientState *peer, { NetSocketState *s; int fd, connected, ret; - struct sockaddr_in saddr; + SocketAddress *saddr; + Error *local_error = NULL; + saddr = g_new0(SocketAddress, 1); - if (parse_host_port(&saddr, host_str) < 0) + if (socket_parse(host_str, &local_error) < 0) return -1; fd = qemu_socket(PF_INET, SOCK_STREAM, 0); @@ -578,10 +578,10 @@ static int net_socket_connect_init(NetClientState *peer, return -1; } qemu_set_nonblock(fd); - + saddr = socket_local_address(fd, &local_error); connected = 0; for(;;) { - ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)); + ret = socket_connect(saddr, &local_error, NULL, NULL); if (ret < 0) { if (errno == EINTR || errno == EWOULDBLOCK) { /* continue */ @@ -602,9 +602,7 @@ static int net_socket_connect_init(NetClientState *peer, s = net_socket_fd_init(peer, model, name, fd, connected); if (!s) return -1; - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: connect to %s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); + g_free(saddr); return 0; } @@ -618,8 +616,9 @@ static int net_socket_mcast_init(NetClientState *peer, int fd; struct sockaddr_in saddr; struct in_addr localaddr, *param_localaddr; + Error *local_error = NULL; - if (parse_host_port(&saddr, host_str) < 0) + if (socket_parse(host_str, &local_error) < 0) return -1; if (localaddr_str != NULL) { @@ -656,12 +655,13 @@ static int net_socket_udp_init(NetClientState *peer, NetSocketState *s; int fd, ret; struct sockaddr_in laddr, raddr; + Error *local_error = NULL; - if (parse_host_port(&laddr, lhost) < 0) { + if (socket_parse(lhost, &local_error) < 0) { return -1; } - if (parse_host_port(&raddr, rhost) < 0) { + if (socket_parse(rhost, &local_error) < 0) { return -1; }