Ejemplo n.º 1
0
static int connect_host(struct proxyinfo *pi, const char *host)
{
	int fd;
	char portbuf[40];
	int errcode;
	struct addrinfo hints, *res, *p;

	if (checkhostname(host))
		return (0);

	sprintf(portbuf, "%d", pi->port);
	memset(&hints, 0, sizeof(hints));
	hints.ai_family=PF_UNSPEC;
	hints.ai_socktype=SOCK_STREAM;

	errcode=getaddrinfo(host, portbuf, &hints, &res);

	if (errcode)
	{
		courier_authdebug_printf
			("getaddrinfo on proxyhost %s failed: %s",
			 pi->host, gai_strerror(errcode));
		return (-1);
	}

	for (p=res; p; p=p->ai_next)
	{
		if ((fd=proxyconnect(pi, p->ai_family,
				     p->ai_addr,
				     p->ai_addrlen))
		    >= 0)
		{
			if ((*pi->connected_func)(fd, host,
						  pi->void_arg))
			{
				close(fd);
				courier_authdebug_printf
					("Failed: %s.", strerror(errno));
				continue;
			}
			freeaddrinfo(res);
			return fd;
		}
	}
	freeaddrinfo(res);
	courier_authdebug_printf
		("Connection to proxyhost %s failed.", host);
	return (-1);
}
Ejemplo n.º 2
0
bool retreiver::getdevices(RETREIVER_DATA *msg) {
	// db's connect is a blocking call so false means no more data
	// not a failure to connect, unless access/pswd is incorrect
	if(m_devices_db.get_devices() == false) // open db and get next record
		return false;

	if(m_devices_db.m_deviceid < 1) // invalid so skipping
		return true;

	if(checkhostname() == true) {
		msg->ip = m_devices_db.m_deviceip;
		msg->dnsname = m_devices_db.m_dnsname;
		msg->hostname = m_devices_db.m_hostname;

		msg->deviceid = m_devices_db.m_deviceid;
		LOG4CXX_DEBUG("got device record from db for " << msg->dnsname);
	} else {
		LOG4CXX_INFO("NOT PING-ABLE " << m_devices_db.m_dnsname);
	}
	return true;
}
Ejemplo n.º 3
0
static int connect_host(struct proxyinfo *pi, const char *host)
{
	struct hostent *he;
	int i;
	int fd;

	if (checkhostname(host))
		return (0);

	he=gethostbyname(host);

	if (he == NULL)
	{
		courier_authdebug_printf
			("gethostbyname on proxyhost %s failed.",
			 host);
		return (-1);
	}

	for (i=0; he->h_addr_list[i]; i++)
	{
		switch (he->h_addrtype) {
		case AF_INET:
			{
				struct sockaddr_in sin;

				memset(&sin, 0, sizeof(sin));

				sin.sin_family=AF_INET;

				memcpy(&sin.sin_addr, he->h_addr_list[i],
				       sizeof(sin.sin_addr));
				sin.sin_port=htons(pi->port);

				fd=proxyconnect(pi, PF_INET, &sin,
						sizeof(sin));
			}
			break;
#ifdef AF_INET6
		case AF_INET6:
			{
				struct sockaddr_in6 sin6;

				memset(&sin6, 0, sizeof(sin6));

				sin6.sin6_family=AF_INET6;

				memcpy(&sin6.sin6_addr, he->h_addr_list[i],
				       sizeof(sin6.sin6_addr));

				sin6.sin6_port=htons(pi->port);
				fd=proxyconnect(pi, PF_INET6, &sin6,
						sizeof(sin6));
			}
			break;
#endif
		default:
			courier_authdebug_printf
				("Unknown address family type %d",
				 he->h_addrtype);
			continue;
		}

		if (fd >= 0)
		{
			if ((*pi->connected_func)(fd, host,
						  pi->void_arg))
			{
				close(fd);
				courier_authdebug_printf
					("Failed: %s.", strerror(errno));
				continue;
			}
			return fd;
		}
	}
	courier_authdebug_printf
		("Connection to proxyhost %s failed.", host);
	return (-1);
}