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 <[email protected]> > --- > 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?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
