chromecast.cpp
// establish connection to the ChromeCast device, m_init is set to indicate that
// the protocol needs to be bootstrapped.
establish connection to the ChromeCast device, m_init is set to indicate that
the protocol needs to be bootstrapped.
establish connection to the ChromeCast device m_init is set to indicate that the protocol needs to be bootstrapped .
bool ChromeCast::connect()
{
	m_s = socket(PF_INET, SOCK_STREAM, 0);
	if (m_s == -1) {
		syslog(LOG_CRIT, "socket() failed: %m");
		return false;
	}
	struct sockaddr_in inaddr;
	memset(&inaddr, 0, sizeof inaddr);
	inaddr.sin_family = AF_INET;
	inaddr.sin_port = htons(8009);
	inaddr.sin_addr.s_addr = inet_addr(m_ip.c_str());
	if (::connect(m_s, (const struct sockaddr *)&inaddr,
				sizeof inaddr) != 0) {
		syslog(LOG_CRIT, "connect() failed: %m");
		close(m_s);
		m_s = -1;
		return false;
	}
	OSStatus s;
	s = SSLNewContext(false, &m_ssl);
	s = SSLSetSessionOption(m_ssl, kSSLSessionOptionBreakOnServerAuth, true);
	s = SSLSetIOFuncs(m_ssl, CDSAReadFunc, CDSAWriteFunc);
	s = SSLSetConnection(m_ssl, (SSLConnectionRef)(intptr_t)m_s);
	s = SSLHandshake(m_ssl);
	s = SSLHandshake(m_ssl);
	if (s) {
		syslog(LOG_CRIT, "SSL_connect() failed");
		SSLDisposeContext(m_ssl);
		m_ssl = NULL;
		close(m_s);
		m_s = -1;
		return false;
	}
	m_tread = std::thread(&ChromeCast::_read, this);
	m_init = false;
	return true;
}
bool ChromeCast :: connect ( ) { m_s = socket ( PF_INET , SOCK_STREAM , 0 ) ; if ( m_s == -1 ) { syslog ( LOG_CRIT , " " ) ; return false ; } struct sockaddr_in inaddr ; memset ( & inaddr , 0 , sizeof inaddr ) ; inaddr . sin_family = AF_INET ; inaddr . sin_port = htons ( 8009 ) ; inaddr . sin_addr . s_addr = inet_addr ( m_ip . c_str ( ) ) ; if ( :: connect ( m_s , ( const struct sockaddr * ) & inaddr , sizeof inaddr ) != 0 ) { syslog ( LOG_CRIT , " " ) ; close ( m_s ) ; m_s = -1 ; return false ; } OSStatus s ; s = SSLNewContext ( false , & m_ssl ) ; s = SSLSetSessionOption ( m_ssl , kSSLSessionOptionBreakOnServerAuth , true ) ; s = SSLSetIOFuncs ( m_ssl , CDSAReadFunc , CDSAWriteFunc ) ; s = SSLSetConnection ( m_ssl , ( SSLConnectionRef ) ( intptr_t ) m_s ) ; s = SSLHandshake ( m_ssl ) ; s = SSLHandshake ( m_ssl ) ; if ( s ) { syslog ( LOG_CRIT , " " ) ; SSLDisposeContext ( m_ssl ) ; m_ssl = NULL ; close ( m_s ) ; m_s = -1 ; return false ; } m_tread = std :: thread ( & ChromeCast :: _read , this ) ; m_init = false ; return true ; }
establish connection to the ChromeCast device, m_init is set to indicate that
the protocol needs to be bootstrapped.
establish connection to the ChromeCast device m_init is set to indicate that the protocol needs to be bootstrapped .