void UIGlobalSettingsNetwork::appendCacheItem(const CHostNetworkInterface &iface) { /* Get DHCP server (create if necessary): */ CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName()); if (dhcp.isNull()) { vboxGlobal().virtualBox().CreateDHCPServer(iface.GetNetworkName()); dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName()); } AssertMsg(!dhcp.isNull(), ("DHCP server creation failed!\n")); /* Prepare cache item: */ UIHostNetworkData data; /* Host-only interface settings */ data.m_interface.m_strName = iface.GetName(); data.m_interface.m_fDhcpClientEnabled = iface.GetDHCPEnabled(); data.m_interface.m_strInterfaceAddress = iface.GetIPAddress(); data.m_interface.m_strInterfaceMask = iface.GetNetworkMask(); data.m_interface.m_fIpv6Supported = iface.GetIPV6Supported(); data.m_interface.m_strInterfaceAddress6 = iface.GetIPV6Address(); data.m_interface.m_strInterfaceMaskLength6 = QString::number(iface.GetIPV6NetworkMaskPrefixLength()); /* DHCP server settings: */ data.m_dhcpserver.m_fDhcpServerEnabled = dhcp.GetEnabled(); data.m_dhcpserver.m_strDhcpServerAddress = dhcp.GetIPAddress(); data.m_dhcpserver.m_strDhcpServerMask = dhcp.GetNetworkMask(); data.m_dhcpserver.m_strDhcpLowerAddress = dhcp.GetLowerIP(); data.m_dhcpserver.m_strDhcpUpperAddress = dhcp.GetUpperIP(); /* Append cache item: */ m_cache.m_items << data; }
void UIHostNetworkManagerWidget::loadHostNetwork(const CHostNetworkInterface &comInterface, UIDataHostNetwork &data) { /* Gather interface settings: */ if (comInterface.isOk()) data.m_interface.m_strName = comInterface.GetName(); if (comInterface.isOk()) data.m_interface.m_fDHCPEnabled = comInterface.GetDHCPEnabled(); if (comInterface.isOk()) data.m_interface.m_strAddress = comInterface.GetIPAddress(); if (comInterface.isOk()) data.m_interface.m_strMask = comInterface.GetNetworkMask(); if (comInterface.isOk()) data.m_interface.m_fSupportedIPv6 = comInterface.GetIPV6Supported(); if (comInterface.isOk()) data.m_interface.m_strAddress6 = comInterface.GetIPV6Address(); if (comInterface.isOk()) data.m_interface.m_strPrefixLength6 = QString::number(comInterface.GetIPV6NetworkMaskPrefixLength()); /* Get host interface network name for further activities: */ QString strNetworkName; if (comInterface.isOk()) strNetworkName = comInterface.GetNetworkName(); /* Show error message if necessary: */ if (!comInterface.isOk()) msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); /* Get VBox for further activities: */ CVirtualBox comVBox = vboxGlobal().virtualBox(); /* Find corresponding DHCP server (create if necessary): */ CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); if (!comVBox.isOk() || comServer.isNull()) comServer = comVBox.CreateDHCPServer(strNetworkName); /* Show error message if necessary: */ if (!comVBox.isOk() || comServer.isNull()) msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this); else { /* Gather DHCP server settings: */ if (comServer.isOk()) data.m_dhcpserver.m_fEnabled = comServer.GetEnabled(); if (comServer.isOk()) data.m_dhcpserver.m_strAddress = comServer.GetIPAddress(); if (comServer.isOk()) data.m_dhcpserver.m_strMask = comServer.GetNetworkMask(); if (comServer.isOk()) data.m_dhcpserver.m_strLowerAddress = comServer.GetLowerIP(); if (comServer.isOk()) data.m_dhcpserver.m_strUpperAddress = comServer.GetUpperIP(); /* Show error message if necessary: */ if (!comServer.isOk()) return msgCenter().cannotAcquireDHCPServerParameter(comServer, this); } }