-/*****************************************************************************
- * network_BuildLocalAddr : fill a sockaddr_in structure for local binding
- *****************************************************************************/
-int network_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port,
- char * psz_broadcast )
-{
-
- char psz_hostname[INPUT_MAX_SOURCE_LENGTH];
- struct hostent * p_hostent;
-
-#if defined( SYS_BEOS )
- intf_ErrMsg( "error: channel changing is not yet supported under BeOS" );
- return( 1 );
-#endif
-
- /* Reset struct */
- memset( p_socket, 0, sizeof( struct sockaddr_in ) );
- p_socket->sin_family = AF_INET; /* family */
- p_socket->sin_port = htons( i_port );
- if( psz_broadcast == NULL )
- {
- /* Try to get our own IP */
- if( gethostname( psz_hostname, sizeof(psz_hostname) ) )
- {
- intf_ErrMsg( "BuildLocalAddr : unable to resolve local name : %s",
- strerror( errno ) );
- return( -1 );
- }
-
- }
- else
- {
- /* I didn't manage to make INADDR_ANYT work, even with setsockopt
- * so, as it's kludgy to try and determine the broadcast addr
- * it is passed as an argument in the command line */
- strncpy( psz_hostname, psz_broadcast, INPUT_MAX_SOURCE_LENGTH );
- }
-
- /* Try to convert address directly from in_addr - this will work if
- * psz_in_addr is dotted decimal. */
-#ifdef HAVE_ARPA_INET_H
- if( !inet_aton( psz_hostname, &p_socket->sin_addr) )
-#else
- if( (p_socket->sin_addr.s_addr = inet_addr( psz_hostname )) == -1 )
-#endif
- {
- /* We have a fqdn, try to find its address */
- if ( (p_hostent = gethostbyname( psz_hostname )) == NULL )
- {
- intf_ErrMsg( "BuildLocalAddr: unknown host %s", psz_hostname );
- return( -1 );
- }
-
- /* Copy the first address of the host in the socket address */
- memcpy( &p_socket->sin_addr, p_hostent->h_addr_list[0],
- p_hostent->h_length );
- }
- return( 0 );
-}
-
-/*****************************************************************************
- * network_BuildRemoteAddr : fill a sockaddr_in structure for remote host
- *****************************************************************************/
-int network_BuildRemoteAddr( struct sockaddr_in * p_socket, char * psz_server )
-{
-
- struct hostent * p_hostent;
-
-#if defined( SYS_BEOS )
- intf_ErrMsg( "error: channel changing is not yet supported under BeOS" );
- return( 1 );
-#endif
-
- /* Reset structure */
- memset( p_socket, 0, sizeof( struct sockaddr_in ) );
- p_socket->sin_family = AF_INET; /* family */
- p_socket->sin_port = htons( 0 ); /* This is for remote end */
-
- /* Try to convert address directly from in_addr - this will work if
- * psz_in_addr is dotted decimal. */
-
-#ifdef HAVE_ARPA_INET_H
- if( !inet_aton( psz_server, &p_socket->sin_addr) )
-#else
- if( (p_socket->sin_addr.s_addr = inet_addr( psz_server )) == -1 )
-#endif
- {
- /* We have a fqdn, try to find its address */
- if ( (p_hostent = gethostbyname(psz_server)) == NULL )
- {
- intf_ErrMsg( "BuildRemoteAddr: unknown host %s",
- psz_server );
- return( -1 );
- }
-
- /* Copy the first address of the host in the socket address */
- memcpy( &p_socket->sin_addr, p_hostent->h_addr_list[0],
- p_hostent->h_length );
- }
- return( 0 );
-}
-