Esempio n. 1
0
// Cribbed from directConnectToSockAddr().  Could probably just call it
// between SetSyscalls(), but I don't know that SO_KEEPALIVE doesn't matter.
int open_tcp_stream( const condor_sockaddr & sa ) {
	int scm = SetSyscalls( SYS_LOCAL | SYS_UNMAPPED );

	int fd = socket( sa.get_aftype(), SOCK_STREAM, 0 );
	assert( fd != -1 );

	int rv = _condor_local_bind( TRUE, fd );
	if( rv != TRUE ) {
		close( fd );
		SetSyscalls( scm );
		return -1;
	}

	// condor_connect ends up pulling in param() via ip6_get_scope_id(),
	// which we can't allow, since this function is linked into standard
	// universe jobs.
	// rv = condor_connect( fd, sa );
	rv = connect( fd, sa.to_sockaddr(), sa.get_socklen() );
	if( rv != 0 ) {
		dprintf( D_ALWAYS, "condor_connect() failed - errno = %d (rv %d)\n", errno, rv );
		close( fd );
		SetSyscalls( scm );
		return -1;
	}

	SetSyscalls( scm );
	return fd;
}
Esempio n. 2
0
/*
  Open a TCP connection at the given hostname and port number.  This
  will result in a file descriptor where we can read or write the
  file.  N.B. both the IP address and the port number are given in host
  byte order.
*/
int
open_tcp_stream( unsigned int ip_addr, unsigned short port )
{
	struct sockaddr_in	sa_in;
	int		fd;
	int		status;
	int		scm;

	scm = SetSyscalls( SYS_LOCAL | SYS_UNMAPPED );

		/* generate a socket */
	fd = socket( AF_INET, SOCK_STREAM, 0 );
	assert( fd >= 0 );
	dprintf( D_FULLDEBUG, "Generated a data socket - fd = %d\n", fd );
		
		/* Now we need to bind to the right interface. */
	if( ! _condor_local_bind(TRUE, fd) ) {
			/* error in bind() */
		close(fd);
		SetSyscalls( scm );
		return -1;
	}

		/* Now, set the remote address. */
	ip_addr = htonl( ip_addr );
	memset( &sa_in, '\0', sizeof sa_in );
	memcpy( &sa_in.sin_addr, &ip_addr, sizeof(ip_addr) );
	sa_in.sin_family = AF_INET;
	sa_in.sin_port = htons( port );
	dprintf( D_FULLDEBUG, "Internet address structure set up\n" );
	status = connect( fd, (struct sockaddr *)&sa_in, sizeof(sa_in) );
	if( status < 0 ) {
		dprintf( D_ALWAYS, "connect() failed - errno = %d\n", errno );
		close(fd);
		SetSyscalls( scm );
		return -1;
	}
	dprintf( D_FULLDEBUG, "Connection completed - returning fd %d\n", fd );

	SetSyscalls( scm );

	return fd;
}