mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
util: add helper API for getting UNIX path from socket address
Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
cfd955b03a
commit
a767af1a7c
@ -2887,6 +2887,7 @@ virSocketAddrFormat;
|
|||||||
virSocketAddrFormatFull;
|
virSocketAddrFormatFull;
|
||||||
virSocketAddrGetIPPrefix;
|
virSocketAddrGetIPPrefix;
|
||||||
virSocketAddrGetNumNetmaskBits;
|
virSocketAddrGetNumNetmaskBits;
|
||||||
|
virSocketAddrGetPath;
|
||||||
virSocketAddrGetPort;
|
virSocketAddrGetPort;
|
||||||
virSocketAddrGetRange;
|
virSocketAddrGetRange;
|
||||||
virSocketAddrIsNetmask;
|
virSocketAddrIsNetmask;
|
||||||
|
@ -522,6 +522,47 @@ virSocketAddrGetPort(virSocketAddrPtr addr)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* virSocketGetPath:
|
||||||
|
* @addr: an initialized virSocketAddrPtr
|
||||||
|
*
|
||||||
|
* Returns the UNIX socket path of the given virtSocketAddr
|
||||||
|
*
|
||||||
|
* Returns -1 if @addr is invalid or does not refer to an
|
||||||
|
* address of type AF_UNIX;
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
virSocketAddrGetPath(virSocketAddrPtr addr ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
#ifndef WIN32
|
||||||
|
char *path = NULL;
|
||||||
|
if (addr == NULL) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("No socket address provided"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addr->data.sa.sa_family != AF_UNIX) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("UNIX socket address is required"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_STRNDUP(path,
|
||||||
|
addr->data.un.sun_path,
|
||||||
|
sizeof(addr->data.un.sun_path)) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return path;
|
||||||
|
#else
|
||||||
|
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
||||||
|
_("UNIX sockets not supported on this platform"));
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virSocketAddrIsNetmask:
|
* virSocketAddrIsNetmask:
|
||||||
* @netmask: the netmask address
|
* @netmask: the netmask address
|
||||||
|
@ -108,6 +108,8 @@ char *virSocketAddrFormatFull(const virSocketAddr *addr,
|
|||||||
bool withService,
|
bool withService,
|
||||||
const char *separator);
|
const char *separator);
|
||||||
|
|
||||||
|
char *virSocketAddrGetPath(virSocketAddrPtr addr);
|
||||||
|
|
||||||
int virSocketAddrSetPort(virSocketAddrPtr addr, int port);
|
int virSocketAddrSetPort(virSocketAddrPtr addr, int port);
|
||||||
|
|
||||||
int virSocketAddrGetPort(virSocketAddrPtr addr);
|
int virSocketAddrGetPort(virSocketAddrPtr addr);
|
||||||
|
Loading…
Reference in New Issue
Block a user