From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoWpw-0006wD-6v for qemu-devel@nongnu.org; Tue, 20 Oct 2015 09:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoWps-0006Vn-Na for qemu-devel@nongnu.org; Tue, 20 Oct 2015 09:20:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54343) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoWps-0006Vd-IK for qemu-devel@nongnu.org; Tue, 20 Oct 2015 09:20:16 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 2060A335696 for ; Tue, 20 Oct 2015 13:20:16 +0000 (UTC) Date: Tue, 20 Oct 2015 14:20:12 +0100 From: "Daniel P. Berrange" Message-ID: <20151020132012.GL14616@redhat.com> References: <1444648509-29179-1-git-send-email-berrange@redhat.com> <1444648509-29179-2-git-send-email-berrange@redhat.com> <562563FF.50501@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <562563FF.50501@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 01/16] sockets: add helpers for creating SocketAddress from a socket Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Paolo Bonzini , qemu-devel@nongnu.org, "Dr. David Alan Gilbert" On Mon, Oct 19, 2015 at 03:43:27PM -0600, Eric Blake wrote: > On 10/12/2015 05:14 AM, Daniel P. Berrange wrote: > > Add two helper methods that, given a socket file descriptor, > > can return a populated SocketAddress struct containing either > > the local or remote address information. > > > > Signed-off-by: Daniel P. Berrange > > --- > > include/qemu/sockets.h | 30 ++++++++++++++ > > util/qemu-sockets.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 140 insertions(+) > > > > > +static SocketAddress * > > +socket_sockaddr_to_address_inet(struct sockaddr_storage *sa, > > + socklen_t salen, > > + Error **errp) > > +{ > > + char host[NI_MAXHOST]; > > + char serv[NI_MAXSERV]; > > + SocketAddress *addr; > > + int ret; > > + > > + ret = getnameinfo((struct sockaddr *)sa, salen, > > + host, sizeof(host), > > + serv, sizeof(serv), > > + NI_NUMERICHOST | NI_NUMERICSERV); > > + if (ret != 0) { > > + error_setg(errp, "Cannot format numeric socket address: %s\n", > > + gai_strerror(ret)); > > No trailing \n with error_setg(), please. > > > + return NULL; > > + } > > + > > + addr = g_new0(SocketAddress, 1); > > + addr->kind = SOCKET_ADDRESS_KIND_INET; > > I've got pending qapi patches that rename this to addr->type, > > > + addr->inet = g_new0(InetSocketAddress, 1); > > and this to addr->u.inet. Whoever merges first gets to watch the other > guy rebase :) > > > + addr->inet->host = g_strdup(host); > > + addr->inet->port = g_strdup(serv); > > + if (sa->ss_family == AF_INET) { > > + addr->inet->ipv4 = true; > > + } else { > > + addr->inet->ipv6 = true; > > + } > > Don't we also need to set has_ipv4 and has_ipv6 appropriately? Yes, we do. 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 :|