From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG0v0-000164-Qt for qemu-devel@nongnu.org; Thu, 23 Jun 2016 05:27:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bG0uu-0006H9-K8 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 05:27:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51946) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG0uu-0006H3-EH for qemu-devel@nongnu.org; Thu, 23 Jun 2016 05:27:20 -0400 Date: Thu, 23 Jun 2016 10:27:13 +0100 From: "Daniel P. Berrange" Message-ID: <20160623092713.GH17868@redhat.com> Reply-To: "Daniel P. Berrange" References: <1466072448-16388-1-git-send-email-ashijeetacharya@gmail.com> <1466236442-11513-1-git-send-email-ashijeetacharya@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1466236442-11513-1-git-send-email-ashijeetacharya@gmail.com> Subject: Re: [Qemu-devel] [PATCH v2] Change net/socket.c to use socket_*() functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ashijeet Acharya Cc: kraxel@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org On Sat, Jun 18, 2016 at 01:24:02PM +0530, Ashijeet Acharya wrote: > Use socket_*() functions from include/qemu/sockets.h instead of listen()/bind()/ connect()/parse_host_port(). socket_*() fucntions are QAPI based and this patch performs this api conversion since everything will be using QAPI based sockets in the future. Also add a helper function socket_address_to_string() in util/qemu-sockets.c which returns the string representation of socket address. Thetask was listed on http://wiki.qemu.org/BiteSizedTasks page. > > Signed-off-by: Ashijeet Acharya > --- > include/qemu/sockets.h | 16 ++++++++++++++- > net/socket.c | 55 +++++++++++++++++++++++++------------------------- > util/qemu-sockets.c | 36 +++++++++++++++++++++++++++++++++ > 3 files changed, 78 insertions(+), 29 deletions(-) > > diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c > index 0d6cd1f..771b7db 100644 > --- a/util/qemu-sockets.c > +++ b/util/qemu-sockets.c > @@ -1151,3 +1151,39 @@ void qapi_copy_SocketAddress(SocketAddress **p_dest, > qmp_input_visitor_cleanup(qiv); > qobject_decref(obj); > } > + > +char *socket_address_to_string(struct SocketAddress *addr, Error **errp) > +{ > + char *buf; > + InetSocketAddress *inet; > + char host_port[INET6_ADDRSTRLEN + 5 + 4]; > + > + switch (addr->type) { > + case SOCKET_ADDRESS_KIND_INET: > + inet = addr->u.inet.data; > + if (strchr(inet->host, ':') == NULL) { > + snprintf(host_port, sizeof(host_port), "%s:%s", inet->host, > + inet->port); > + buf = g_strdup(host_port); > + } else { > + snprintf(host_port, sizeof(host_port), "[%s]:%s", inet->host, > + inet->port); > + buf = g_strdup(host_port); I see the patch is already queued, but really this should be changed to not use a preallocated buffer. It should instead use g_strdup_printf() Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|