示例#1
0
int cg_bittorrent_propertymgr_getintegervalue(CgBittorrentPropertyMgr *propMgr, char *category, char *key, int defaultValue)
{
	char buf[CG_STRING_INTEGER_BUFLEN];

	if (!propMgr)
		return defaultValue;

	if (propMgr->getValueFunc) {
		if (propMgr->getValueFunc(propMgr, category, key, buf, (sizeof(buf)-1)))
			return cg_str2int(buf);
	}

	return defaultValue;
}
示例#2
0
ssize_t cg_socket_recv(CgSocket *sock, CgDatagramPacket *dgmPkt)
{
	ssize_t recvLen = 0;
	char recvBuf[CG_NET_SOCKET_DGRAM_RECV_BUFSIZE+1];
	char remoteAddr[CG_NET_SOCKET_MAXHOST];
	char remotePort[CG_NET_SOCKET_MAXSERV];
	char *localAddr;

#if defined(BTRON) || (defined(TENGINE) && !defined(CG_TENGINE_NET_KASAGO))
	struct sockaddr_in from;
	W fromLen = sizeof(from);
	recvLen = so_recvfrom(sock->id, recvBuf, sizeof(recvBuf)-1, 0, (struct sockaddr *)&from, &fromLen);
#elif defined(TENGINE) && defined(CG_TENGINE_NET_KASAGO)
	struct sockaddr_in from;
	int fromLen = sizeof(from);
	recvLen = ka_recvfrom(sock->id, recvBuf, sizeof(recvBuf)-1, 0, (struct sockaddr *)&from, &fromLen);
#elif defined(ITRON)
	T_IPV4EP remoteHost;
	recvLen = udp_rcv_dat(sock->id, &remoteHost, recvBuf, sizeof(recvBuf)-1, TMO_FEVR);
#else
	struct sockaddr_storage from;
	socklen_t fromLen = sizeof(from);
	recvLen = recvfrom(sock->id, recvBuf, sizeof(recvBuf)-1, 0, (struct sockaddr *)&from, &fromLen);
#endif

	cg_log_debug_l4("Entering...\n");

	if (recvLen <= 0)
		return 0;

	recvBuf[recvLen] = '\0';
	cg_socket_datagram_packet_setdata(dgmPkt, recvBuf);

	cg_socket_datagram_packet_setlocalport(dgmPkt, cg_socket_getport(sock));
	cg_socket_datagram_packet_setremoteaddress(dgmPkt, "");
	cg_socket_datagram_packet_setremoteport(dgmPkt, 0);

#if defined(BTRON) || (defined(TENGINE) && !defined(CG_TENGINE_NET_KASAGO))
	cg_socket_datagram_packet_setlocaladdress(dgmPkt, cg_socket_getaddress(sock));
	cg_socket_datagram_packet_setremoteaddress(dgmPkt, inet_ntoa(from.sin_addr));
	cg_socket_datagram_packet_setremoteport(dgmPkt, ntohl(from.sin_port));
#elif defined(TENGINE) && defined(CG_TENGINE_NET_KASAGO)
	cg_socket_datagram_packet_setlocaladdress(dgmPkt, cg_socket_getaddress(sock));
	ka_tfInetToAscii((unsigned long)from.sin_addr.s_addr, remoteAddr);
	cg_socket_datagram_packet_setremoteaddress(dgmPkt, remoteAddr);
	cg_socket_datagram_packet_setremoteport(dgmPkt, ka_ntohl(from.sin_port));
#elif defined(ITRON)
	cg_socket_datagram_packet_setlocaladdress(dgmPkt, cg_socket_getaddress(sock));
	ipaddr_to_ascii(remoteAddr, remoteHost.ipaddr);
	cg_socket_datagram_packet_setremoteaddress(dgmPkt, remoteAddr);
	cg_socket_datagram_packet_setremoteport(dgmPkt, ntohs(remoteHost.portno));
#else

	if (getnameinfo((struct sockaddr *)&from, fromLen, remoteAddr, sizeof(remoteAddr), remotePort, sizeof(remotePort), NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
		cg_socket_datagram_packet_setremoteaddress(dgmPkt, remoteAddr);
		cg_socket_datagram_packet_setremoteport(dgmPkt, cg_str2int(remotePort));
	}

	cg_log_debug_s("From pointer %p\n", &from);
	localAddr = cg_net_selectaddr((struct sockaddr *)&from);
	cg_socket_datagram_packet_setlocaladdress(dgmPkt, localAddr);
	free(localAddr);

#endif

	cg_log_debug_l4("Leaving...\n");

	return recvLen;
}