Example #1
0
sizeint GetIpAddrList(string_v& vsOutIpAddrList)
{
	START_FUNCTION();
	string_v vsIpAddrList;

	string sHostName;
	if (!GetHostName(sHostName)) {
		break;
	}

	struct hostent *pheHostEntry = gethostbyname(sHostName.c_str());
	if (!pheHostEntry) {
		break;
	}

	struct in_addr addr;
	for (int idx = 0; pheHostEntry->h_addr_list[idx] != 0; ++idx) 
	{
		memcpy(&addr, pheHostEntry->h_addr_list[idx], sizeof(struct in_addr));
		vsIpAddrList.push_back(inet_ntoa(addr));
	}

	vsOutIpAddrList.swap(vsIpAddrList);
	END_FUNCTION_RET(vsOutIpAddrList.size());
}
Example #2
0
void CreateCommandLineParamsVactor(int argc, char *argv[], string_v &vsOutParams)
{
	ASSERTE(argv && argc);
	string_v vsParams;

	for (int idx = 0; idx < argc; ++idx)
	{
		vsParams.push_back(argv[idx]);
	}

	vsOutParams.swap(vsParams);
}
Example #3
0
void CreateCommandLineParamsVactor(char *szCommandLine, string_v &vsOutParams)
{
	ASSERTE(szCommandLine);
	string_v vsParams;

	bool bInQuotes = false;

	sizeint siCommandLineLen = strlen(szCommandLine);
	char *pszStartPos = const_cast<char *>(szCommandLine);

	for (sizeint siIndex = 0; siIndex < siCommandLineLen; ++siIndex)
	{
		if (szCommandLine[siIndex] == QUOTE)
		{
			bInQuotes = !bInQuotes;
		}

		if (!bInQuotes && (szCommandLine[siIndex] == SPACE || szCommandLine[siIndex] == TAB))
		{
			if (pszStartPos == szCommandLine + siIndex)
			{
				++pszStartPos;
			}
			else
			{
				szCommandLine[siIndex] = 0;

				vsParams.push_back(pszStartPos);
				pszStartPos = szCommandLine + siIndex + 1;
			}
		}
	}

	if (strlen(pszStartPos))
	{
		vsParams.push_back(pszStartPos);
	}

	vsOutParams.swap(vsParams);
}