mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Rename ifaceGetIPAddress to virNetDevGetIPv4Address
To match up with the existing virNetDevSetIPv4Address, rename ifaceGetIPAddress to virNetDevGetIPv4Address * util/interface.h, util/interface.c: Rename API * network/bridge_driver.c: Update for API rename
This commit is contained in:
parent
00bba08d24
commit
50f190856d
@ -577,7 +577,7 @@ virHookPresent;
|
|||||||
# interface.h
|
# interface.h
|
||||||
ifaceCheck;
|
ifaceCheck;
|
||||||
virNetDevGetIndex;
|
virNetDevGetIndex;
|
||||||
ifaceGetIPAddress;
|
virNetDevGetIPv4Address;
|
||||||
ifaceGetNthParent;
|
ifaceGetNthParent;
|
||||||
ifaceGetPhysicalFunction;
|
ifaceGetPhysicalFunction;
|
||||||
ifaceGetVirtualFunctionIndex;
|
ifaceGetVirtualFunctionIndex;
|
||||||
|
@ -3148,13 +3148,10 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dev_name) {
|
if (dev_name) {
|
||||||
if (ifaceGetIPAddress(dev_name, &addr)) {
|
if (virNetDevGetIPv4Address(dev_name, &addr) < 0)
|
||||||
virReportSystemError(errno,
|
goto cleanup;
|
||||||
_("Failed to get IP address for '%s' (network '%s')"),
|
|
||||||
dev_name, netdef->name);
|
addrptr = &addr;
|
||||||
} else {
|
|
||||||
addrptr = &addr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addrptr &&
|
if (addrptr &&
|
||||||
|
@ -142,60 +142,64 @@ ifaceCheck(bool reportError ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ifaceGetIPAddress:
|
* virNetDevGetIPv4Address:
|
||||||
* @ifname: name of the interface whose IP address we want
|
* @ifname: name of the interface whose IP address we want
|
||||||
* @macaddr: MAC address (VIR_MAC_BUFLEN in size)
|
* @addr: filled with the IPv4 address
|
||||||
*
|
*
|
||||||
* This function gets the @macaddr for a given interface @ifname.
|
* This function gets the IPv4 address for the interface @ifname
|
||||||
|
* and stores it in @addr
|
||||||
*
|
*
|
||||||
* Returns 0 on success, -errno on failure.
|
* Returns 0 on success, -errno on failure.
|
||||||
*/
|
*/
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
int
|
int virNetDevGetIPv4Address(const char *ifname,
|
||||||
ifaceGetIPAddress(const char *ifname,
|
virSocketAddrPtr addr)
|
||||||
virSocketAddrPtr addr)
|
|
||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int fd;
|
int fd;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (!ifname || !addr)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
memset (addr, 0, sizeof(*addr));
|
memset (addr, 0, sizeof(*addr));
|
||||||
addr->data.stor.ss_family = AF_UNSPEC;
|
addr->data.stor.ss_family = AF_UNSPEC;
|
||||||
|
|
||||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
return -errno;
|
virReportSystemError(errno, "%s",
|
||||||
|
_("Unable to open control socket"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(struct ifreq));
|
memset(&ifr, 0, sizeof(struct ifreq));
|
||||||
if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL) {
|
if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL) {
|
||||||
rc = -EINVAL;
|
virReportSystemError(ERANGE,
|
||||||
goto err_exit;
|
_("invalid interface name %s"),
|
||||||
|
ifname);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) != 0) {
|
if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
|
||||||
rc = -errno;
|
virReportSystemError(errno,
|
||||||
goto err_exit;
|
_("Unable to get IPv4 address for interface %s"), ifname);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr->data.stor.ss_family = AF_INET;
|
addr->data.stor.ss_family = AF_INET;
|
||||||
addr->len = sizeof(addr->data.inet4);
|
addr->len = sizeof(addr->data.inet4);
|
||||||
memcpy(&addr->data.inet4, &ifr.ifr_addr, addr->len);
|
memcpy(&addr->data.inet4, &ifr.ifr_addr, addr->len);
|
||||||
|
|
||||||
err_exit:
|
cleanup:
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int
|
int virNetDevGetIPv4Address(const char *ifname ATTRIBUTE_UNUSED,
|
||||||
ifaceGetIPAddress(const char *ifname ATTRIBUTE_UNUSED,
|
virSocketAddrPtr addr ATTRIBUTE_UNUSED)
|
||||||
virSocketAddrPtr addr ATTRIBUTE_UNUSED)
|
|
||||||
{
|
{
|
||||||
return -ENOSYS;
|
virReportSystemError(ENOSYS, "%s",
|
||||||
|
_("Unable to get IPv4 address on this platform"));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
|
@ -33,7 +33,8 @@ struct nlattr;
|
|||||||
int ifaceCheck(bool reportError, const char *ifname,
|
int ifaceCheck(bool reportError, const char *ifname,
|
||||||
const unsigned char *macaddr, int ifindex);
|
const unsigned char *macaddr, int ifindex);
|
||||||
|
|
||||||
int ifaceGetIPAddress(const char *ifname, virSocketAddrPtr addr);
|
int virNetDevGetIPv4Address(const char *ifname, virSocketAddrPtr addr)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int ifaceMacvtapLinkDump(bool nltarget_kernel, const char *ifname, int ifindex,
|
int ifaceMacvtapLinkDump(bool nltarget_kernel, const char *ifname, int ifindex,
|
||||||
struct nlattr **tb, unsigned char **recvbuf,
|
struct nlattr **tb, unsigned char **recvbuf,
|
||||||
|
Loading…
Reference in New Issue
Block a user