void host_object::test<7>()
	{
		const char* str = "192.168.1.1";
		U32 port = 8080, ip;
		LLHost host;
		host.set(str,port);
		ip = ip_string_to_u32(str);
		ensure("IP address is invalid", (ip == host.getAddress()));
		ensure("Port Number is invalid", (port == host.getPort()));
		
		str = "64.233.187.99";
		ip = ip_string_to_u32(str);
		host.setAddress(str);
		ensure("IP address is invalid", (ip == host.getAddress()));

		ip = 0xc098017b;
		host.setAddress(ip);
		ensure("IP address is invalid", (ip == host.getAddress()));
		// should still use the old port
		ensure("Port Number is invalid", (port == host.getPort()));

		port = 8084;
		host.setPort(port);
		ensure("Port Number is invalid", (port == host.getPort()));
		// should still use the old address
		ensure("IP address is invalid", (ip == host.getAddress()));
	}
Example #2
0
BOOL LLPacketRing::sendPacketImpl(int h_socket, const char * send_buffer, S32 buf_size, LLHost host)
{
	
	if (!LLProxy::isSOCKSProxyEnabled())
	{
		return send_packet(h_socket, send_buffer, buf_size, host.getAddress(), host.getPort());
	}

	char headered_send_buffer[NET_BUFFER_SIZE + SOCKS_HEADER_SIZE];

	proxywrap_t *socks_header = static_cast<proxywrap_t*>(static_cast<void*>(&headered_send_buffer));
	socks_header->rsv   = 0;
	socks_header->addr  = host.getAddress();
	socks_header->port  = htons(host.getPort());
	socks_header->atype = ADDRESS_IPV4;
	socks_header->frag  = 0;

	memcpy(headered_send_buffer + SOCKS_HEADER_SIZE, send_buffer, buf_size);

	return send_packet(	h_socket,
						headered_send_buffer,
						buf_size + SOCKS_HEADER_SIZE,
						LLProxy::getInstance()->getUDPProxy().getAddress(),
						LLProxy::getInstance()->getUDPProxy().getPort());
}
	void host_object::test<6>()
	{
		U32 ip = 0xc098017d, port = 8080;
		LLHost host;
		host.set(ip,port);
		ensure("IP address is invalid", (ip == host.getAddress()));
		ensure("Port Number is invalid", (port == host.getPort()));
	}
Example #4
0
BOOL LLPacketRing::doSendPacket(int h_socket, const char * send_buffer, S32 buf_size, LLHost host)
{
	
	if (!LLSocks::isEnabled())
	{
		return send_packet(h_socket, send_buffer, buf_size, host.getAddress(), host.getPort());
	}

	proxywrap_t *socks_header = (proxywrap_t *)&mProxyWrappedSendBuffer;
	socks_header->rsv   = 0;
	socks_header->addr  = host.getAddress();
	socks_header->port  = htons(host.getPort());
	socks_header->atype = ADDRESS_IPV4;
	socks_header->frag  = 0;

	memcpy(mProxyWrappedSendBuffer+10, send_buffer, buf_size);

	return send_packet(h_socket,(const char*) mProxyWrappedSendBuffer, buf_size+10, LLSocks::getInstance()->getUDPPproxy().getAddress(), LLSocks::getInstance()->getUDPPproxy().getPort());
}
Example #5
0
S32 tcp_open_channel(LLHost host)
{
    // Open a TCP channel
    // Jump through some hoops to ensure that if the request hosts is down
    // or not reachable connect() does not block

    S32 handle;
    handle = socket(AF_INET, SOCK_STREAM, 0);
    if (!handle)
    {
        llwarns << "Error opening TCP control socket, socket() returned " << handle << llendl;
        return -1;
    }

    struct sockaddr_in address;
    address.sin_port        = htons(host.getPort());
    address.sin_family      = AF_INET;
    address.sin_addr.s_addr = host.getAddress();

    // Non blocking
    WSAEVENT hEvent=WSACreateEvent();
    WSAEventSelect(handle, hEvent, FD_CONNECT) ;
    connect(handle, (struct sockaddr*)&address, sizeof(address)) ;
    // Wait fot 5 seconds, if we can't get a TCP channel open in this
    // time frame then there is something badly wrong.
    WaitForSingleObject(hEvent, 1000*5); // 5 seconds time out

    WSANETWORKEVENTS netevents;
    WSAEnumNetworkEvents(handle,hEvent,&netevents);

    // Check the async event status to see if we connected
    if ((netevents.lNetworkEvents & FD_CONNECT) == FD_CONNECT)
    {
        if (netevents.iErrorCode[FD_CONNECT_BIT] != 0)
        {
            llwarns << "Unable to open TCP channel, WSA returned an error code of " << netevents.iErrorCode[FD_CONNECT_BIT] << llendl;
            WSACloseEvent(hEvent);
            return -1;
        }

        // Now we are connected disable non blocking
        // we don't need support an async interface as
        // currently our only consumer (socks5) will make one round
        // of packets then just hold the connection open
        WSAEventSelect(handle, hEvent, NULL) ;
        unsigned long NonBlock = 0;
        ioctlsocket(handle, FIONBIO, &NonBlock);

        return handle;
    }

    llwarns << "Unable to open TCP channel, Timeout is the host up?" << netevents.iErrorCode[FD_CONNECT_BIT] << llendl;
    return -1;
}
Example #6
0
S32 tcp_open_channel(LLHost host)
{
    S32 handle;
    handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (!handle)
    {
        llwarns << "Error opening TCP control socket, socket() returned " << handle << llendl;
        return -1;
    }

    struct sockaddr_in address;
    address.sin_port        = htons(host.getPort());
    address.sin_family      = AF_INET;
    address.sin_addr.s_addr = host.getAddress();

    // Set the socket to non blocking for the connect()
    int flags = fcntl(handle, F_GETFL, 0);
    fcntl(handle, F_SETFL, flags | O_NONBLOCK);

    S32 error = connect(handle, (sockaddr*)&address, sizeof(address));
    if (error && (errno != EINPROGRESS))
    {
        llwarns << "Unable to open TCP channel, error code: " << errno << llendl;
        return -1;
    }

    struct timeval timeout;
    timeout.tv_sec  = 5; // Maximum time to wait for the connect() to complete
    timeout.tv_usec = 0;
    fd_set fds;
    FD_ZERO(&fds);
    FD_SET(handle, &fds);

    // See if we have connectde or time out after 5 seconds
    U32 rc = select(sizeof(fds)*8, NULL, &fds, NULL, &timeout);

    if (rc != 1) // we require exactly one descriptor to be set
    {
        llwarns << "Unable to open TCP channel" << llendl;
        return -1;
    }

    // Return the socket to blocking operations
    fcntl(handle, F_SETFL, flags);

    return handle;
}
bool LLSocket::blockingConnect(const LLHost& host)
{
	if(!mSocket) return false;
	apr_sockaddr_t* sa = NULL;
	std::string ip_address;
	ip_address = host.getIPString();
	if(ll_apr_warn_status(apr_sockaddr_info_get(
		&sa,
		ip_address.c_str(),
		APR_UNSPEC,
		host.getPort(),
		0,
		mPool())))
	{
		return false;
	}
	setBlocking(1000);
	ll_debug_socket("Blocking connect", mSocket);
	if(ll_apr_warn_status(apr_socket_connect(mSocket, sa))) return false;
	setNonBlocking();
	return true;
}
	void host_object::test<1>()
	{
		LLHost host;
		ensure("IP address is not NULL", (0 == host.getAddress()) && (0 == host.getPort()) && !host.isOk());
	}
Example #9
0
BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LLHost host)
{
	BOOL status = TRUE;
	if (!mUseOutThrottle)
	{
		return send_packet(h_socket, send_buffer, buf_size, host.getAddress(), host.getPort() );
	}
	else
	{
		mActualBitsOut += buf_size * 8;
		LLPacketBuffer *packetp = NULL;
		// See if we've got enough throttle to send a packet.
		while (!mOutThrottle.checkOverflow(0.f))
		{
			// While we have enough bandwidth, send a packet from the queue or the current packet

			S32 packet_size = 0;
			if (!mSendQueue.empty())
			{
				// Send a packet off of the queue
				LLPacketBuffer *packetp = mSendQueue.front();
				mSendQueue.pop();

				mOutBufferLength -= packetp->getSize();
				packet_size = packetp->getSize();

				status = send_packet(h_socket, packetp->getData(), packet_size, packetp->getHost().getAddress(), packetp->getHost().getPort());
				
				delete packetp;
				// Update the throttle
				mOutThrottle.throttleOverflow(packet_size * 8.f);
			}
			else
			{
				// If the queue's empty, we can just send this packet right away.
				status = send_packet(h_socket, send_buffer, buf_size, host.getAddress(), host.getPort() );
				packet_size = buf_size;

				// Update the throttle
				mOutThrottle.throttleOverflow(packet_size * 8.f);

				// This was the packet we're sending now, there are no other packets
				// that we need to send
				return status;
			}

		}

		// We haven't sent the incoming packet, add it to the queue
		if (mOutBufferLength + buf_size > mMaxBufferLength)
		{
			// Nuke this packet, we overflowed the buffer.
			// Toss it.
			llwarns << "Throwing away outbound packet, overflowing buffer" << llendl;
		}
		else
		{
			static LLTimer queue_timer;
			if ((mOutBufferLength > 4192) && queue_timer.getElapsedTimeF32() > 1.f)
			{
				// Add it to the queue
				llinfos << "Outbound packet queue " << mOutBufferLength << " bytes" << llendl;
				queue_timer.reset();
			}
			packetp = new LLPacketBuffer(host, send_buffer, buf_size);

			mOutBufferLength += packetp->getSize();
			mSendQueue.push(packetp);
		}
	}

	return status;
}