* ipv6.c: IPv6 network abstraction layer
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: ipv6.c,v 1.12 2003/06/13 12:08:13 gbazin Exp $
+ * $Id: ipv6.c,v 1.16 2004/02/15 22:20:56 gbazin Exp $
*
* Authors: Alexis Guillard <alexis.guillard@bt.com>
* Christophe Massiot <massiot@via.ecp.fr>
}
if( !_getaddrinfo || !_freeaddrinfo )
{
- msg_Err( p_this, "no IPv6 stack installed" );
+ msg_Warn( p_this, "no IPv6 stack installed" );
if( wship6_dll ) FreeLibrary( wship6_dll );
free( psz_backup );
return( -1 );
psz_multicast_interface );
/* now convert that interface name to an index */
-#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
- p_socket->sin6_scope_id = if_nametoindex(psz_multicast_interface);
-#elif defined( WIN32 )
+#if defined( WIN32 )
/* FIXME ?? */
p_socket->sin6_scope_id = atol(psz_multicast_interface);
+#elif defined( HAVE_IF_NAMETOINDEX )
+ p_socket->sin6_scope_id = if_nametoindex(psz_multicast_interface);
#endif
msg_Dbg( p_this, " = #%i", p_socket->sin6_scope_id );
}
#else
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET6;
- hints.ai_flags = AI_NUMERICHOST;
- if( _getaddrinfo( psz_address, NULL, &hints, &res ) )
+ if( _getaddrinfo( psz_address, NULL, &hints, &res ) != 0 )
{
FreeLibrary( wship6_dll );
free( psz_backup );
/* We have a fqdn, try to find its address */
if ( (p_hostent = gethostbyname2( psz_address, AF_INET6 )) == NULL )
{
- msg_Err( p_this, "ipv6 error: unknown host %s", psz_address );
+ msg_Warn( p_this, "IPv6 error: unknown host %s", psz_address );
free( psz_backup );
return( -1 );
}
p_hostent->h_length );
#elif defined(WIN32)
- if( _getaddrinfo( psz_address, NULL, &hints, &res ) )
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET6;
+
+ if( _getaddrinfo( psz_address, NULL, &hints, &res ) != 0 )
{
FreeLibrary( wship6_dll );
free( psz_backup );
_freeaddrinfo( res );
#else
- msg_Err( p_this, "ipv6 error: IPv6 address %s is invalid",
+ msg_Warn( p_this, "IPv6 error: IPv6 address %s is invalid",
psz_address );
free( psz_backup );
return( -1 );
* protocol */
if( (i_handle = socket( AF_INET6, SOCK_DGRAM, 0 )) == -1 )
{
- msg_Err( p_this, "cannot create socket (%s)", strerror(errno) );
+ msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) );
return( -1 );
}
if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR,
(void *) &i_opt, sizeof( i_opt ) ) == -1 )
{
- msg_Err( p_this, "cannot configure socket (SO_REUSEADDR: %s)",
+ msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR: %s)",
strerror(errno) );
close( i_handle );
return( -1 );
}
else if( i_opt < 0x80000 )
{
- msg_Warn( p_this, "socket buffer size is 0x%x instead of 0x%x",
+ msg_Warn( p_this, "Socket buffer size is 0x%x instead of 0x%x",
i_opt, 0x80000 );
}
/* Bind it */
if( bind( i_handle, (struct sockaddr *)&sockany, sizeof( sock ) ) < 0 )
{
- msg_Err( p_this, "cannot bind socket (%s)", strerror(errno) );
+ msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) );
close( i_handle );
return( -1 );
}
/* Bind it */
if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 )
{
- msg_Err( p_this, "cannot bind socket (%s)", strerror(errno) );
+ msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) );
close( i_handle );
return( -1 );
}
if( setsockopt( i_handle, SOL_SOCKET, SO_BROADCAST,
(void*) &i_opt, sizeof( i_opt ) ) == -1 )
{
- msg_Warn( p_this, "ipv6 warning: cannot configure socket "
+ msg_Warn( p_this, "IPv6 warning: cannot configure socket "
"(SO_BROADCAST: %s)", strerror(errno) );
}
}
/* Join the multicast group if the socket is a multicast address */
-#if defined(WIN32) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
+#if defined( WIN32 ) || defined( HAVE_IF_NAMETOINDEX )
if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) )
{
struct ipv6_mreq imr;
if( res == -1 )
{
- msg_Err( p_this, "setsockopt JOIN_GROUP failed" );
+ msg_Err( p_this, "cannot join multicast group" );
}
}
#else
- msg_Warn( p_this, "setsockopt JOIN_GROUP not supported with glibc < 2.2" );
+ msg_Warn( p_this, "Multicast IPv6 is not supported on your OS" );
#endif
if( *psz_server_addr )
{
- int ttl = config_GetInt( p_this, "ttl" );
+ int ttl = p_socket->i_ttl;
+ if( ttl < 1 )
+ {
+ ttl = config_GetInt( p_this, "ttl" );
+ }
if( ttl < 1 ) ttl = 1;
/* Build socket for remote connection */
if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) == -1 )
{
- msg_Err( p_this, "cannot build remote address" );
+ msg_Warn( p_this, "cannot build remote address" );
close( i_handle );
return( -1 );
}
if( connect( i_handle, (struct sockaddr *) &sock,
sizeof( sock ) ) == (-1) )
{
- msg_Err( p_this, "cannot connect socket (%s)", strerror(errno) );
+ msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) );
close( i_handle );
return( -1 );
}
/* Set the time-to-live */
if( ttl > 1 )
{
-#if defined(WIN32) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
+#if defined( WIN32 ) || defined( HAVE_IF_NAMETOINDEX )
if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) )
{
if( setsockopt( i_handle, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
(void *)&ttl, sizeof( ttl ) ) < 0 )
{
#ifdef HAVE_ERRNO_H
- msg_Warn( p_this, "failed to set multicast ttl (%s)",
- strerror(errno) );
+ msg_Err( p_this, "failed to set multicast ttl (%s)",
+ strerror(errno) );
#else
- msg_Warn( p_this, "failed to set multicast ttl" );
+ msg_Err( p_this, "failed to set multicast ttl" );
#endif
}
}
else
+#endif
{
if( setsockopt( i_handle, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
(void *)&ttl, sizeof( ttl ) ) < 0 )
{
#ifdef HAVE_ERRNO_H
- msg_Warn( p_this, "failed to set unicast ttl (%s)",
+ msg_Err( p_this, "failed to set unicast ttl (%s)",
strerror(errno) );
#else
- msg_Warn( p_this, "failed to set unicast ttl" );
+ msg_Err( p_this, "failed to set unicast ttl" );
#endif
}
}
-#endif
}
}
* protocol */
if( (i_handle = socket( AF_INET6, SOCK_STREAM, 0 )) == -1 )
{
- msg_Err( p_this, "cannot create socket (%s)", strerror(errno) );
+ msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) );
return( -1 );
}
if( connect( i_handle, (struct sockaddr *) &sock,
sizeof( sock ) ) == (-1) )
{
- msg_Err( p_this, "cannot connect socket (%s)", strerror(errno) );
+ msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) );
close( i_handle );
return( -1 );
}