librnr/sock.c
Socket_T *SocketOpenTcpConnection(const char *sRemoteHostName, int ipPortRemote)
{
	int									sd;
	struct sockaddr_in	addrInet;
  Socket_T           *pSocket;

	//
	// Create socket in protocal familiy INET (IPv4), of type STREAM (TCP).
	//
	if( (sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0 )
	{
		LOGSYSERROR("socket(%d,%d,%d)", PF_INET, SOCK_STREAM, IPPROTO_TCP);
		return NULL;
	}

  //
  // Set IPv4 address of remote 
  //
  addrInet.sin_family = AF_INET;				            // ip application family
	addrInet.sin_port 	= htons_nowarn((ushort_t)ipPortRemote);
                                                    // remote port number

  if( SockResolveHostName(sRemoteHostName, &(addrInet.sin_addr)) < 0 )
  {
    LOGERROR("SockResolveHostName() failed");
    close(sd);
    return NULL;
  }

  //
  // Connect to remote end
  //
	if(connect(sd, (struct sockaddr *)&addrInet, (socklen_t)sizeof(addrInet)) < 0)
	{
		LOGSYSERROR("connect(%d, ...)", sd);
		close(sd);
		return NULL;
	}

  //
  // Now create a new socket and set the appropriate attributes
  //
  pSocket = SocketNew();

  SocketAttrSetSd(pSocket, sd);
  SocketAttrSetFlavor(pSocket, 
      SockFlavorDomainIPv4|SockFlavorProtocolTcp|SockFlavorFuncConnection);
  SocketAttrSetLocalName(pSocket, NULL);
  SocketAttrSetRemoteName(pSocket, (struct sockaddr *)&addrInet, 
                          sRemoteHostName);

  LOGDIAG4("Opened Connection %s", SocketAttrGetRemoteName(pSocket));

	return pSocket;
}
/*!
 * \brief Create and open a new TCP/IP socket to the given remote host and
 * port.
 *
 * \param sRemoteHostName   Dotted address or network name.
 * \param ipPortRemote      Remote port number.
 *
 * \return
 *  Returns a new TCP Socket_T pointer on success, NULL on failure.
 */
\brief Create and open a new TCP/IP socket to the given remote host and
port.

\param sRemoteHostName   Dotted address or network name.
\param ipPortRemote      Remote port number.

\return
Returns a new TCP Socket_T pointer on success, NULL on failure.
\ brief Create and open a new TCP / IP socket to the given remote host and port . \ param sRemoteHostName Dotted address or network name . \ param ipPortRemote Remote port number . \ return Returns a new TCP Socket_T pointer on success NULL on failure .
Socket_T *SocketOpenTcpConnection(const char *sRemoteHostName, int ipPortRemote)
{
	int									sd;
	struct sockaddr_in	addrInet;
  Socket_T           *pSocket;
	 Create socket in protocal familiy INET (IPv4), of type STREAM (TCP).
	if( (sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0 )
	{
		LOGSYSERROR("socket(%d,%d,%d)", PF_INET, SOCK_STREAM, IPPROTO_TCP);
		return NULL;
	}
   Set IPv4 address of remote 
  addrInet.sin_family = AF_INET;				             ip application family
	addrInet.sin_port 	= htons_nowarn((ushort_t)ipPortRemote);
                                                     remote port number
  if( SockResolveHostName(sRemoteHostName, &(addrInet.sin_addr)) < 0 )
  {
    LOGERROR("SockResolveHostName() failed");
    close(sd);
    return NULL;
  }
   Connect to remote end
	if(connect(sd, (struct sockaddr *)&addrInet, (socklen_t)sizeof(addrInet)) < 0)
	{
		LOGSYSERROR("connect(%d, ...)", sd);
		close(sd);
		return NULL;
	}
   Now create a new socket and set the appropriate attributes
  pSocket = SocketNew();
  SocketAttrSetSd(pSocket, sd);
  SocketAttrSetFlavor(pSocket, 
      SockFlavorDomainIPv4|SockFlavorProtocolTcp|SockFlavorFuncConnection);
  SocketAttrSetLocalName(pSocket, NULL);
  SocketAttrSetRemoteName(pSocket, (struct sockaddr *)&addrInet, 
                          sRemoteHostName);
  LOGDIAG4("Opened Connection %s", SocketAttrGetRemoteName(pSocket));
	return pSocket;
}
Socket_T * SocketOpenTcpConnection ( const char * sRemoteHostName , int ipPortRemote ) { int sd ; struct sockaddr_in addrInet ; Socket_T * pSocket ; if ( ( sd = socket ( PF_INET , SOCK_STREAM , IPPROTO_TCP ) ) < 0 ) { LOGSYSERROR ( " " , PF_INET , SOCK_STREAM , IPPROTO_TCP ) ; return NULL ; } addrInet . sin_family = AF_INET ; addrInet . sin_port = htons_nowarn ( ( ushort_t ) ipPortRemote ) ; if ( SockResolveHostName ( sRemoteHostName , & ( addrInet . sin_addr ) ) < 0 ) { LOGERROR ( " " ) ; close ( sd ) ; return NULL ; } if ( connect ( sd , ( struct sockaddr * ) & addrInet , ( socklen_t ) sizeof ( addrInet ) ) < 0 ) { LOGSYSERROR ( " " , sd ) ; close ( sd ) ; return NULL ; } pSocket = SocketNew ( ) ; SocketAttrSetSd ( pSocket , sd ) ; SocketAttrSetFlavor ( pSocket , SockFlavorDomainIPv4 | SockFlavorProtocolTcp | SockFlavorFuncConnection ) ; SocketAttrSetLocalName ( pSocket , NULL ) ; SocketAttrSetRemoteName ( pSocket , ( struct sockaddr * ) & addrInet , sRemoteHostName ) ; LOGDIAG4 ( " " , SocketAttrGetRemoteName ( pSocket ) ) ; return pSocket ; }
\brief Create and open a new TCP/IP socket to the given remote host and
 port.
\ brief Create and open a new TCP / IP socket to the given remote host and port .
// // Create socket in protocal familiy INET (IPv4), of type STREAM (TCP). // // // Set IPv4 address of remote  // // ip application family // remote port number // // Connect to remote end // // // Now create a new socket and set the appropriate attributes //