当前位置: 首页>>代码示例>>C++>>正文


C++ AStringVector::emplace_back方法代码示例

本文整理汇总了C++中AStringVector::emplace_back方法的典型用法代码示例。如果您正苦于以下问题:C++ AStringVector::emplace_back方法的具体用法?C++ AStringVector::emplace_back怎么用?C++ AStringVector::emplace_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AStringVector的用法示例。


在下文中一共展示了AStringVector::emplace_back方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EnumLocalIPAddresses

AStringVector cNetwork::EnumLocalIPAddresses(void)
{
	AStringVector res;

	#ifdef _WIN32

		// Query the OS for all adapters' addresses:
		char buffer[64 KiB];  // A buffer backing the address list
		PIP_ADAPTER_ADDRESSES pAddresses = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(&buffer);
		ULONG outBufLen = sizeof(buffer);
		DWORD dwRetVal = GetAdaptersAddresses(
			AF_UNSPEC,
			GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME, nullptr,
			pAddresses, &outBufLen
		);
		if (dwRetVal != ERROR_SUCCESS)
		{
			LOG("GetAdaptersAddresses() failed: %u", dwRetVal);
			return res;
		}

		// Enumerate all active adapters
		for (auto pCurrAddresses = pAddresses; pCurrAddresses != nullptr; pCurrAddresses = pCurrAddresses->Next)
		{
			if (pCurrAddresses->OperStatus != IfOperStatusUp)
			{
				// Adapter not active, skip it:
				continue;
			}

			// Collect all IP addresses on this adapter:
			for (auto pUnicast = pCurrAddresses->FirstUnicastAddress; pUnicast != nullptr; pUnicast = pUnicast->Next)
			{
				auto Address = PrintAddress(pUnicast->Address);
				if (!Address.empty())
				{
					res.push_back(Address);
				}
			}  // for pUnicast
		}  // for pCurrAddresses

	#else  // _WIN32

		struct ifaddrs * ifAddrStruct = nullptr;
		getifaddrs(&ifAddrStruct);

		for (auto ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next)
		{
			if (ifa->ifa_addr == nullptr)
			{
				continue;
			}

			auto Address = PrintAddress(ifa);
			if (!Address.empty())
			{
				res.emplace_back(Address);
			}
		}

		if (ifAddrStruct != nullptr)
		{
			freeifaddrs(ifAddrStruct);
		}

	#endif  // else _WIN32

	return res;
}
开发者ID:36451,项目名称:MCServer,代码行数:69,代码来源:NetworkInterfaceEnum.cpp


注:本文中的AStringVector::emplace_back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。