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 <berra...@redhat.com> > > --- > > 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 :|