
2010/4/21 Eric Blake <eblake@redhat.com>:
The user probably doesn't care what the gai error numbers are, as much as what the failed conversion IP address was.
* src/remote/remote_driver.c (addrToString): Mention which address could not be converted. * daemon/remote.c (addrToString): Likewise. ---
Changes in v2: Remove magic numbers in remote.c's array sizing Use correct offset for IP addresses
daemon/remote.c | 30 ++++++++++++++++++++++-------- src/remote/remote_driver.c | 26 ++++++++++++++++++++------ 2 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c index 149176f..b753a4a 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1,7 +1,7 @@ /* * remote.c: handlers for RPC method calls * - * Copyright (C) 2007, 2008, 2009 Red Hat, Inc. + * Copyright (C) 2007-2010 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -41,6 +41,7 @@ #include <string.h> #include <errno.h> #include <fnmatch.h> +#include <arpa/inet.h> #include "virterror_internal.h"
#if HAVE_POLKIT0 @@ -3169,21 +3170,34 @@ remoteDispatchAuthList (struct qemud_server *server,
#if HAVE_SASL /* - * NB, keep in sync with similar method in src/remote_internal.c + * NB, keep in sync with similar method in src/remote/remote_driver.c */ static char *addrToString(remote_error *rerr, - struct sockaddr_storage *sa, socklen_t salen) { - char host[1024], port[20]; + struct sockaddr_storage *ss, socklen_t salen) { + char host[NI_MAXHOST], port[NI_MAXSERV]; char *addr; int err; + struct sockaddr *sa = (struct sockaddr *)ss;
- if ((err = getnameinfo((struct sockaddr *)sa, salen, + if ((err = getnameinfo(sa, salen, host, sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { - remoteDispatchFormatError(rerr, - _("Cannot resolve address %d: %s"), - err, gai_strerror(err)); + char ip[INET6_ADDRSTRLEN]; + + if (inet_ntop(sa->sa_family, + (sa->sa_family == AF_INET + ? (void *)&((struct sockaddr_in *)sa)->sin_addr + : (void *)&((struct sockaddr_in6 *)sa)->sin6_addr),
Could we avoid this void * cast? The same cast is in src/remote/remote_driver.c too.
+ ip, sizeof ip)) { + remoteDispatchFormatError(rerr, + _("Cannot resolve address %s: %s"), + ip, gai_strerror(err)); + } else { + remoteDispatchFormatError(rerr, + _("Cannot resolve address: %s"), + gai_strerror(err)); + } return NULL; }
ACK. Matthias