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


C++ ThreadInfo::GetHostAddress方法代码示例

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


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

示例1: getShares

int32 getShares(void *data)
{
	bt_request request;
	bt_resource resource;
	struct sockaddr_in ourAddr, toAddr, fromAddr;
	char buffer[8192];
	int sock, addrLen, bytes, bufPos = 0;

	ThreadInfo *info = (ThreadInfo *) data;
	unsigned int serverIP = ntohl(info->GetHostAddress());

	memset(&toAddr, 0, sizeof(toAddr));
	toAddr.sin_family = AF_INET;
	toAddr.sin_port = htons(BT_QUERYHOST_PORT);
	toAddr.sin_addr.s_addr = htonl(serverIP);

	sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (sock == INVALID_SOCKET)
		return 0;

	memset(&ourAddr, 0, sizeof(ourAddr));
	ourAddr.sin_family = AF_INET;
	ourAddr.sin_port = htons(BT_QUERYHOST_PORT);
	ourAddr.sin_addr.s_addr = htonl(INADDR_ANY);

	if (bind(sock, (struct sockaddr *) &ourAddr, sizeof(ourAddr)))
		if (errno != EADDRINUSE)
		{
			closesocket(sock);
			return 0;
		}

	strcpy(request.signature, BT_RPC_SIGNATURE);
	request.command = BT_REQ_SHARE_PROBE;
	sendto(sock, (char *) &request, sizeof(request), 0, (struct sockaddr *) &toAddr, sizeof(toAddr));

	signal(SIGALRM, recvAlarm);
	alarm(4);

	addrLen = sizeof(fromAddr);
	bytes = recvfrom(sock, buffer, sizeof(buffer) - 1, 0, (struct sockaddr *) &fromAddr, &addrLen);
	if (bytes > 0)
		if (strncmp(buffer, BT_RPC_SIGNATURE, strlen(BT_RPC_SIGNATURE)) != 0)
		{
			info->GetColumnListView()->LockLooper();

			while (bufPos < bytes)
			{
				memcpy(&resource, buffer + bufPos, sizeof(bt_resource));
				resource.type = B_LENDIAN_TO_HOST_INT32(resource.type);
				resource.subType = B_LENDIAN_TO_HOST_INT32(resource.subType);
				if (resource.type == BT_SHARED_NULL)
					break;

				bufPos += sizeof(bt_resource);
				info->GetColumnListView()->AddItem(new ResourceItem(resource.name, resource.type));
			}

			info->GetColumnListView()->UnlockLooper();
		}

	alarm(0);
	signal(SIGALRM, SIG_DFL);
	closesocket(sock);
	return 1;
}
开发者ID:HaikuArchives,项目名称:BeServed,代码行数:66,代码来源:MyNetView.cpp


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