librnr/sock.c
Socket_T *SocketOpenUdp(int ipPortUdp, const char *sLocalHostName)
{
	int									sd;
	struct sockaddr_in	addrInet;
  Socket_T           *pSocket;

	LOGDIAG4CALL(_TINT(ipPortUdp), _TSTR(sLocalHostName));

	//
	// Create socket in protocal familiy INET (IPv4), of type DateGram (UDP).
	//
	if( (sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0 )
	{
		LOGSYSERROR("socket(%d,%d,%d)", PF_INET, SOCK_DGRAM, IPPROTO_UDP);
		return NULL;
	}

	//
	// Bind this socket to application family INET (IP) at the given port.
	//
	memset((void*)&addrInet, 0, sizeof(addrInet));
  addrInet.sin_family = AF_INET;				          // ip application family
	addrInet.sin_port 	= htons_nowarn((ushort_t)ipPortUdp);
                                                  // listen port number

  
  //
  // Let bind() automatically fill in the IP address of the machine where
  // the calling process is running on.
  // 
  if( sLocalHostName == NULL )
  {
	  addrInet.sin_addr.s_addr = htonl(INADDR_ANY);
  }

  //
  // Bind to a specific local address
  //
  else if( SockResolveHostName(sLocalHostName, &(addrInet.sin_addr)) < 0 )
  {
    LOGERROR("SockResolveHostName() failed");
    close(sd);
    return NULL;
  }

	//
	// Bind socket to the address.
	//
	if( bind(sd, (struct sockaddr *)&addrInet, (socklen_t)sizeof(addrInet)) < 0 )
	{
		LOGSYSERROR("bind(%d, ...)", sd);
		close(sd);
		return NULL;
	}

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

  SocketAttrSetSd(pSocket, sd);
  SocketAttrSetFlavor(pSocket, 
      SockFlavorDomainIPv4|SockFlavorProtocolUdp);
  SocketAttrSetLocalName(pSocket, NULL);
  SocketAttrSetRemoteName(pSocket, NULL, SockStrAnyHost);

  LOGDIAG4("Opened UDP Socket %s", SocketAttrGetLocalName(pSocket));

	return pSocket;
}
/*!
 * \brief Create and open a new UDP/IP connectionless socket.
 * port.
 *
 * \param ipPortUdp       Binding UDP port number.
 * \param sLocalHostName  String name of local host to bind to. If NULL, then
 *                        this host will automatically choose the IP address.
 *
 * \return
 *  Returns a new UDP Socket_T pointer on success, NULL on failure.
 */
\brief Create and open a new UDP/IP connectionless socket.
port.

\param ipPortUdp       Binding UDP port number.
\param sLocalHostName  String name of local host to bind to. If NULL, then
this host will automatically choose the IP address.

\return
Returns a new UDP Socket_T pointer on success, NULL on failure.
\ brief Create and open a new UDP / IP connectionless socket . port . \ param ipPortUdp Binding UDP port number . \ param sLocalHostName String name of local host to bind to . If NULL then this host will automatically choose the IP address . \ return Returns a new UDP Socket_T pointer on success NULL on failure .
Socket_T *SocketOpenUdp(int ipPortUdp, const char *sLocalHostName)
{
	int									sd;
	struct sockaddr_in	addrInet;
  Socket_T           *pSocket;
	LOGDIAG4CALL(_TINT(ipPortUdp), _TSTR(sLocalHostName));
	 Create socket in protocal familiy INET (IPv4), of type DateGram (UDP).
	if( (sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0 )
	{
		LOGSYSERROR("socket(%d,%d,%d)", PF_INET, SOCK_DGRAM, IPPROTO_UDP);
		return NULL;
	}
	 Bind this socket to application family INET (IP) at the given port.
	memset((void*)&addrInet, 0, sizeof(addrInet));
  addrInet.sin_family = AF_INET;				           ip application family
	addrInet.sin_port 	= htons_nowarn((ushort_t)ipPortUdp);
                                                   listen port number
   Let bind() automatically fill in the IP address of the machine where
   the calling process is running on.
  if( sLocalHostName == NULL )
  {
	  addrInet.sin_addr.s_addr = htonl(INADDR_ANY);
  }
   Bind to a specific local address
  else if( SockResolveHostName(sLocalHostName, &(addrInet.sin_addr)) < 0 )
  {
    LOGERROR("SockResolveHostName() failed");
    close(sd);
    return NULL;
  }
	 Bind socket to the address.
	if( bind(sd, (struct sockaddr *)&addrInet, (socklen_t)sizeof(addrInet)) < 0 )
	{
		LOGSYSERROR("bind(%d, ...)", sd);
		close(sd);
		return NULL;
	}
   Now create a new socket and set the appropriate attributes
  pSocket = SocketNew();
  SocketAttrSetSd(pSocket, sd);
  SocketAttrSetFlavor(pSocket, 
      SockFlavorDomainIPv4|SockFlavorProtocolUdp);
  SocketAttrSetLocalName(pSocket, NULL);
  SocketAttrSetRemoteName(pSocket, NULL, SockStrAnyHost);
  LOGDIAG4("Opened UDP Socket %s", SocketAttrGetLocalName(pSocket));
	return pSocket;
}
Socket_T * SocketOpenUdp ( int ipPortUdp , const char * sLocalHostName ) { int sd ; struct sockaddr_in addrInet ; Socket_T * pSocket ; LOGDIAG4CALL ( _TINT ( ipPortUdp ) , _TSTR ( sLocalHostName ) ) ; if ( ( sd = socket ( PF_INET , SOCK_DGRAM , IPPROTO_UDP ) ) < 0 ) { LOGSYSERROR ( " " , PF_INET , SOCK_DGRAM , IPPROTO_UDP ) ; return NULL ; } memset ( ( void * ) & addrInet , 0 , sizeof ( addrInet ) ) ; addrInet . sin_family = AF_INET ; addrInet . sin_port = htons_nowarn ( ( ushort_t ) ipPortUdp ) ; if ( sLocalHostName == NULL ) { addrInet . sin_addr . s_addr = htonl ( INADDR_ANY ) ; } else if ( SockResolveHostName ( sLocalHostName , & ( addrInet . sin_addr ) ) < 0 ) { LOGERROR ( " " ) ; close ( sd ) ; return NULL ; } if ( bind ( sd , ( struct sockaddr * ) & addrInet , ( socklen_t ) sizeof ( addrInet ) ) < 0 ) { LOGSYSERROR ( " " , sd ) ; close ( sd ) ; return NULL ; } pSocket = SocketNew ( ) ; SocketAttrSetSd ( pSocket , sd ) ; SocketAttrSetFlavor ( pSocket , SockFlavorDomainIPv4 | SockFlavorProtocolUdp ) ; SocketAttrSetLocalName ( pSocket , NULL ) ; SocketAttrSetRemoteName ( pSocket , NULL , SockStrAnyHost ) ; LOGDIAG4 ( " " , SocketAttrGetLocalName ( pSocket ) ) ; return pSocket ; }
\brief Create and open a new UDP/IP connectionless socket.
\ brief Create and open a new UDP / IP connectionless socket .
// // Create socket in protocal familiy INET (IPv4), of type DateGram (UDP). // // // Bind this socket to application family INET (IP) at the given port. // // ip application family // listen port number // // Let bind() automatically fill in the IP address of the machine where // the calling process is running on. //  // // Bind to a specific local address // // // Bind socket to the address. // // // Now create a new socket and set the appropriate attributes //