mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
addrToString: give better error message
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.
This commit is contained in:
parent
2a82a33ee4
commit
3022375da3
@ -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,36 @@ 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) {
|
||||
char ip[INET6_ADDRSTRLEN];
|
||||
void *rawaddr;
|
||||
|
||||
if (sa->sa_family == AF_INET)
|
||||
rawaddr = &((struct sockaddr_in *)sa)->sin_addr;
|
||||
else
|
||||
rawaddr = &((struct sockaddr_in6 *)sa)->sin6_addr;
|
||||
|
||||
if (inet_ntop(sa->sa_family, rawaddr, ip, sizeof ip)) {
|
||||
remoteDispatchFormatError(rerr,
|
||||
_("Cannot resolve address %d: %s"),
|
||||
err, gai_strerror(err));
|
||||
_("Cannot resolve address %s: %s"),
|
||||
ip, gai_strerror(err));
|
||||
} else {
|
||||
remoteDispatchFormatError(rerr,
|
||||
_("Cannot resolve address: %s"),
|
||||
gai_strerror(err));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
/* Windows socket compatibility functions. */
|
||||
#include <errno.h>
|
||||
@ -6570,21 +6571,36 @@ remoteAuthenticate (virConnectPtr conn, struct private_data *priv,
|
||||
|
||||
#if HAVE_SASL
|
||||
/*
|
||||
* NB, keep in sync with similar method in remote/remote.c
|
||||
* NB, keep in sync with similar method in daemon/remote.c
|
||||
*/
|
||||
static char *addrToString(struct sockaddr_storage *sa, socklen_t salen)
|
||||
static char *addrToString(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) {
|
||||
char ip[INET6_ADDRSTRLEN];
|
||||
void *rawaddr;
|
||||
|
||||
if (sa->sa_family == AF_INET)
|
||||
rawaddr = &((struct sockaddr_in *)sa)->sin_addr;
|
||||
else
|
||||
rawaddr = &((struct sockaddr_in6 *)sa)->sin6_addr;
|
||||
|
||||
if (inet_ntop(sa->sa_family, rawaddr, ip, sizeof ip)) {
|
||||
remoteError(VIR_ERR_UNKNOWN_HOST,
|
||||
_("Cannot resolve address %d: %s"),
|
||||
err, gai_strerror(err));
|
||||
_("Cannot resolve address %s: %s"),
|
||||
ip, gai_strerror(err));
|
||||
} else {
|
||||
remoteError(VIR_ERR_UNKNOWN_HOST,
|
||||
_("Cannot resolve address: %s"),
|
||||
gai_strerror(err));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user