Commit 14c73097 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Remove dead code

parent a1fe3a13
...@@ -173,17 +173,14 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -173,17 +173,14 @@ static int OpenUDP( vlc_object_t * p_this )
/* Build the local socket */ /* Build the local socket */
if( BuildAddr( p_this, &sock, psz_bind_addr, i_bind_port ) == -1 ) if( BuildAddr( p_this, &sock, psz_bind_addr, i_bind_port ) == -1 )
{ return VLC_EGENERIC;
msg_Dbg( p_this, "cannot build local address" );
return 0;
}
/* Open a SOCK_DGRAM (UDP) socket, in the AF_INET domain, automatic (0) /* Open a SOCK_DGRAM (UDP) socket, in the AF_INET domain, automatic (0)
* protocol */ * protocol */
if( (i_handle = socket( AF_INET, SOCK_DGRAM, 0 )) == -1 ) if( (i_handle = socket( AF_INET, SOCK_DGRAM, 0 )) == -1 )
{ {
msg_Err( p_this, "cannot create socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot create socket (%s)", strerror(errno) );
return 0; return VLC_EGENERIC;
} }
/* We may want to reuse an already used socket */ /* We may want to reuse an already used socket */
...@@ -226,9 +223,8 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -226,9 +223,8 @@ static int OpenUDP( vlc_object_t * p_this )
if( bind( i_handle, (struct sockaddr *)&stupid, sizeof( stupid ) ) < 0 ) if( bind( i_handle, (struct sockaddr *)&stupid, sizeof( stupid ) ) < 0 )
{ {
msg_Warn( p_this, "cannot bind socket (%d)", WSAGetLastError() ); msg_Err( p_this, "cannot bind socket (%d)", WSAGetLastError() );
close( i_handle ); goto error;
return 0;
} }
} }
else else
...@@ -236,9 +232,8 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -236,9 +232,8 @@ static int OpenUDP( vlc_object_t * p_this )
/* Bind it */ /* Bind it */
if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 ) if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 )
{ {
msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot bind socket (%s)", strerror(errno) );
close( i_handle ); goto error;
return 0;
} }
#if !defined( SYS_BEOS ) #if !defined( SYS_BEOS )
...@@ -253,153 +248,63 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -253,153 +248,63 @@ static int OpenUDP( vlc_object_t * p_this )
} }
#endif #endif
#if !defined( SYS_BEOS ) #ifdef IP_ADD_SOURCE_MEMBERSHIP
/* Join the multicast group if the socket is a multicast address */ /* Join the multicast group if the socket is a multicast address */
if( IN_MULTICAST( ntohl(sock.sin_addr.s_addr) ) ) if( IN_MULTICAST( ntohl(sock.sin_addr.s_addr) ) )
{ {
/* Determine interface to be used for multicast */ /* Determine interface to be used for multicast */
char * psz_if_addr = config_GetPsz( p_this, "miface-addr" ); char * psz_if_addr = config_GetPsz( p_this, "miface-addr" );
#ifdef IP_ADD_SOURCE_MEMBERSHIP
/* If we have a source address, we use IP_ADD_SOURCE_MEMBERSHIP /* If we have a source address, we use IP_ADD_SOURCE_MEMBERSHIP
so that IGMPv3 aware OSes running on IGMPv3 aware networks so that IGMPv3 aware OSes running on IGMPv3 aware networks
will do an IGMPv3 query on the network */ will do an IGMPv3 query on the network */
if( *psz_server_addr ) struct ip_mreq_source imr =
{
struct ip_mreq_source imr;
imr.imr_multiaddr.s_addr = sock.sin_addr.s_addr;
imr.imr_sourceaddr.s_addr = inet_addr(psz_server_addr);
if( psz_if_addr != NULL && *psz_if_addr
&& inet_addr(psz_if_addr) != INADDR_NONE )
imr.imr_interface.s_addr = inet_addr(psz_if_addr);
else
imr.imr_interface.s_addr = INADDR_ANY;
if( psz_if_addr != NULL )
free( psz_if_addr );
msg_Dbg( p_this, "IP_ADD_SOURCE_MEMBERSHIP multicast request" );
/* Join Multicast group with source filter */
if( setsockopt( i_handle, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP,
(char*)&imr,
sizeof(struct ip_mreq_source) ) == -1 )
{
msg_Warn( p_this, "Source specific multicast failed (%s) -"
"check if your OS really supports IGMPv3",
strerror(errno) );
goto igmpv2;
}
}
/* If there is no source address, we use IP_ADD_MEMBERSHIP */
else
#endif
{ {
struct ip_mreq imr; .imr_multiaddr.s_addr = sock.sin_addr.s_addr,
.imr_sourceaddr.s_addr = inet_addr(psz_server_addr)
igmpv2: };
if( psz_if_addr != NULL && *psz_if_addr
&& inet_addr(psz_if_addr) != INADDR_NONE )
imr.imr_interface.s_addr = inet_addr(psz_if_addr);
else
imr.imr_interface.s_addr = INADDR_ANY; imr.imr_interface.s_addr = INADDR_ANY;
imr.imr_multiaddr.s_addr = sock.sin_addr.s_addr;
if( psz_if_addr != NULL && *psz_if_addr
&& inet_addr(psz_if_addr) != INADDR_NONE )
{
imr.imr_interface.s_addr = inet_addr(psz_if_addr);
}
#if defined (WIN32) || defined (UNDER_CE)
else
{
typedef DWORD (CALLBACK * GETBESTINTERFACE) ( IPAddr, PDWORD );
typedef DWORD (CALLBACK * GETIPADDRTABLE) ( PMIB_IPADDRTABLE, PULONG, BOOL );
GETBESTINTERFACE OurGetBestInterface;
GETIPADDRTABLE OurGetIpAddrTable;
HINSTANCE hiphlpapi = LoadLibrary(_T("Iphlpapi.dll"));
DWORD i_index;
if( hiphlpapi )
{
OurGetBestInterface =
(void *)GetProcAddress( hiphlpapi,
_T("GetBestInterface") );
OurGetIpAddrTable =
(void *)GetProcAddress( hiphlpapi,
_T("GetIpAddrTable") );
}
if( hiphlpapi && OurGetBestInterface && OurGetIpAddrTable && if( psz_if_addr != NULL )
OurGetBestInterface( sock.sin_addr.s_addr, free( psz_if_addr );
&i_index ) == NO_ERROR )
{
PMIB_IPADDRTABLE p_table;
DWORD i = 0;
msg_Dbg( p_this, "Winsock best interface is %lu",
(unsigned long)i_index );
OurGetIpAddrTable( NULL, &i, 0 );
p_table = (PMIB_IPADDRTABLE)malloc( i );
if( p_table != NULL )
{
if( OurGetIpAddrTable( p_table, &i, 0 ) == NO_ERROR )
{
for( i = 0; i < p_table->dwNumEntries; i-- )
{
if( p_table->table[i].dwIndex == i_index )
{
imr.imr_interface.s_addr =
p_table->table[i].dwAddr;
msg_Dbg( p_this, "using interface 0x%08x",
p_table->table[i].dwAddr );
}
}
}
else msg_Warn( p_this, "GetIpAddrTable failed" );
free( p_table );
}
}
else msg_Dbg( p_this, "GetBestInterface failed" );
if( hiphlpapi ) FreeLibrary( hiphlpapi ); msg_Dbg( p_this, "IP_ADD_SOURCE_MEMBERSHIP multicast request" );
}
#endif
if( psz_if_addr != NULL ) free( psz_if_addr );
msg_Dbg( p_this, "IP_ADD_MEMBERSHIP multicast request" ); /* Join Multicast group with source filter */
/* Join Multicast group without source filter */ if( setsockopt( i_handle, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP,
if( setsockopt( i_handle, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void*)&imr,
(char*)&imr, sizeof(struct ip_mreq) ) == -1 ) sizeof(struct ip_mreq_source) ) == -1 )
{ {
msg_Err( p_this, "failed to join IP multicast group (%s)", msg_Err( p_this, "Source specific multicast failed (%s) -"
strerror(errno) ); "check if your OS really supports IGMPv3",
close( i_handle ); strerror(errno) );
return 0; goto error;
}
} }
} }
else else
#endif #endif
if( *psz_server_addr )
{ {
/* Build socket for remote connection */ /* Build socket for remote connection */
if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) == -1 ) if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) == -1 )
{ {
msg_Warn( p_this, "cannot build remote address" ); msg_Err( p_this, "cannot build remote address" );
close( i_handle ); goto error;
return 0;
} }
/* Connect the socket */ /* Connect the socket */
if( connect( i_handle, (struct sockaddr *) &sock, if( connect( i_handle, (struct sockaddr *) &sock,
sizeof( sock ) ) == (-1) ) sizeof( sock ) ) == (-1) )
{ {
msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot connect socket (%s)", strerror(errno) );
close( i_handle ); goto error;
return 0;
} }
#if !defined( SYS_BEOS ) #ifdef IP_MULTICAST_IF
if( IN_MULTICAST( ntohl(inet_addr(psz_server_addr) ) ) ) if( IN_MULTICAST( ntohl(inet_addr(psz_server_addr) ) ) )
{ {
/* set the time-to-live */ /* set the time-to-live */
...@@ -416,9 +321,8 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -416,9 +321,8 @@ static int OpenUDP( vlc_object_t * p_this )
if( setsockopt( i_handle, IPPROTO_IP, IP_MULTICAST_IF, if( setsockopt( i_handle, IPPROTO_IP, IP_MULTICAST_IF,
&intf, sizeof( intf ) ) < 0 ) &intf, sizeof( intf ) ) < 0 )
{ {
msg_Dbg( p_this, "failed to set multicast interface (%s).", strerror(errno) ); msg_Err( p_this, "failed to set multicast interface (%s).", strerror(errno) );
close( i_handle ); goto error;
return 0;
} }
} }
...@@ -443,8 +347,7 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -443,8 +347,7 @@ static int OpenUDP( vlc_object_t * p_this )
{ {
msg_Err( p_this, "failed to set ttl (%s)", msg_Err( p_this, "failed to set ttl (%s)",
strerror(errno) ); strerror(errno) );
close( i_handle ); goto error;
return 0;
} }
} }
} }
...@@ -462,4 +365,8 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -462,4 +365,8 @@ static int OpenUDP( vlc_object_t * p_this )
p_socket->i_mtu = val.i_int; p_socket->i_mtu = val.i_int;
return 0; return 0;
error:
close (i_handle);
return VLC_EGENERIC;
} }
...@@ -162,15 +162,15 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -162,15 +162,15 @@ static int OpenUDP( vlc_object_t * p_this )
p_socket->i_handle = -1; p_socket->i_handle = -1;
/* Build the local socket */ /* Build the local socket */
if ( BuildAddr( p_this, &sock, psz_bind_addr, i_bind_port ) == -1 ) if ( BuildAddr( p_this, &sock, psz_bind_addr, i_bind_port ) == -1 )
return 0; return VLC_EGENERIC;
/* Open a SOCK_DGRAM (UDP) socket, in the AF_INET6 domain, automatic (0) /* Open a SOCK_DGRAM (UDP) socket, in the AF_INET6 domain, automatic (0)
* protocol */ * protocol */
if( (i_handle = socket( AF_INET6, SOCK_DGRAM, 0 )) == -1 ) if( (i_handle = socket( AF_INET6, SOCK_DGRAM, 0 )) == -1 )
{ {
msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot create socket (%s)", strerror(errno) );
return 0; return VLC_EGENERIC;
} }
#ifdef IPV6_PROTECTION_LEVEL #ifdef IPV6_PROTECTION_LEVEL
...@@ -179,15 +179,8 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -179,15 +179,8 @@ static int OpenUDP( vlc_object_t * p_this )
#endif #endif
/* We may want to reuse an already used socket */ /* We may want to reuse an already used socket */
i_opt = 1; setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR,
if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR, (void *) &i_opt, sizeof( i_opt ) );
(void *) &i_opt, sizeof( i_opt ) ) == -1 )
{
msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR: %s)",
strerror(errno) );
close( i_handle );
return 0;
}
/* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
* packet loss caused by scheduling problems */ * packet loss caused by scheduling problems */
...@@ -211,8 +204,7 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -211,8 +204,7 @@ static int OpenUDP( vlc_object_t * p_this )
if( bind( i_handle, (struct sockaddr *)&sockany, sizeof( sock ) ) < 0 ) if( bind( i_handle, (struct sockaddr *)&sockany, sizeof( sock ) ) < 0 )
{ {
msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) ); msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) );
close( i_handle ); goto errror;
return 0;
} }
} }
else else
...@@ -221,73 +213,47 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -221,73 +213,47 @@ static int OpenUDP( vlc_object_t * p_this )
if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 ) if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 )
{ {
msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) ); msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) );
close( i_handle ); goto error;
return 0;
} }
/* Join the multicast group if the socket is a multicast address */ /* Join the multicast group if the socket is a multicast address */
if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) ) if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) )
{ {
if(*psz_server_addr) #ifndef MCAST_JOIN_SOURCE_GROUP
{ errno = ENOSYS;
#ifdef MCAST_JOIN_SOURCE_GROUP #else
struct group_source_req imr; struct group_source_req imr;
struct sockaddr_in6 *p_sin6; struct sockaddr_in6 *p_sin6;
imr.gsr_interface = 0;
imr.gsr_group.ss_family = AF_INET6;
imr.gsr_source.ss_family = AF_INET6;
p_sin6 = (struct sockaddr_in6 *)&imr.gsr_group;
p_sin6->sin6_addr = sock.sin6_addr;
/* Build socket for remote connection */
msg_Dbg( p_this, "psz_server_addr : %s", psz_server_addr);
if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) ) imr.gsr_interface = 0;
{ imr.gsr_group.ss_family = AF_INET6;
msg_Warn( p_this, "cannot build remote address" ); imr.gsr_source.ss_family = AF_INET6;
close( i_handle ); p_sin6 = (struct sockaddr_in6 *)&imr.gsr_group;
return 0; p_sin6->sin6_addr = sock.sin6_addr;
}
p_sin6 = (struct sockaddr_in6 *)&imr.gsr_source;
p_sin6->sin6_addr = sock.sin6_addr;
msg_Dbg( p_this, "MCAST_JOIN_SOURCE_GROUP multicast request" ); /* Build socket for remote connection */
if( setsockopt( i_handle, IPPROTO_IPV6, MCAST_JOIN_SOURCE_GROUP, msg_Dbg( p_this, "psz_server_addr : %s", psz_server_addr);
(char *)&imr, sizeof(struct group_source_req) ) == -1 )
#else
errno = ENOSYS;
#endif
{
msg_Err( p_this, "Source specific multicast failed (%s) -" if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) )
" check if your OS really supports MLDv2",
strerror(errno) );
}
}
else
{ {
struct ipv6_mreq imr; msg_Warn( p_this, "cannot build remote address" );
int res; goto error;
}
p_sin6 = (struct sockaddr_in6 *)&imr.gsr_source;
p_sin6->sin6_addr = sock.sin6_addr;
imr.ipv6mr_interface = sock.sin6_scope_id; msg_Dbg( p_this, "MCAST_JOIN_SOURCE_GROUP multicast request" );
imr.ipv6mr_multiaddr = sock.sin6_addr; if( setsockopt( i_handle, IPPROTO_IPV6, MCAST_JOIN_SOURCE_GROUP,
msg_Dbg( p_this, "IPV6_JOIN_GROUP multicast request" ); (char *)&imr, sizeof(struct group_source_req) ) == -1 )
res = setsockopt(i_handle, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void*) &imr,
#if defined(WIN32)
sizeof(imr) + 4); /* Doesn't work without this */
#else
sizeof(imr));
#endif #endif
{
if( res == -1 ) msg_Err( p_this, "Source specific multicast failed (%s) -"
{ " check if your OS really supports MLDv2",
msg_Err( p_this, "cannot join multicast group" ); strerror(errno) );
} goto error;
} }
} }
else else
if( *psz_server_addr )
{ {
int ttl; int ttl;
...@@ -295,8 +261,7 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -295,8 +261,7 @@ static int OpenUDP( vlc_object_t * p_this )
if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) == -1 ) if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) == -1 )
{ {
msg_Warn( p_this, "cannot build remote address" ); msg_Warn( p_this, "cannot build remote address" );
close( i_handle ); goto error;
return 0;
} }
/* Connect the socket */ /* Connect the socket */
...@@ -304,41 +269,31 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -304,41 +269,31 @@ static int OpenUDP( vlc_object_t * p_this )
sizeof( sock ) ) == (-1) ) sizeof( sock ) ) == (-1) )
{ {
msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) ); msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) );
close( i_handle ); goto error;
return 0;
} }
/* Set the time-to-live */ /* Set the time-to-live */
ttl = p_socket->i_ttl; ttl = p_socket->i_ttl;
if( ttl <= 0 ) if( ttl <= 0 )
ttl = config_GetInt( p_this, "ttl" ); ttl = var_CreateGetInteger( p_this, "ttl" );
if( ttl > 0 ) if( ttl >= 0 )
{ {
if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) ) int cmd = IN6_IS_ADDR_MULTICAST(&sock.sin6_addr)
{ ? IPV6_MULTICAST_HOPS : IPV6_UNICAST_HOPS;
if( setsockopt( i_handle, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, if( setsockopt( i_handle, IPPROTO_IPV6, cmd,
(void *)&ttl, sizeof( ttl ) ) < 0 ) (void *)&ttl, sizeof( ttl ) ) < 0 )
{
msg_Err( p_this, "failed to set multicast ttl (%s)",
strerror(errno) );
}
}
else
{ {
if( setsockopt( i_handle, IPPROTO_IPV6, IPV6_UNICAST_HOPS, msg_Err( p_this, "failed to set multicast ttl (%s)",
(void *)&ttl, sizeof( ttl ) ) < 0 ) strerror(errno) );
{ goto error;
msg_Err( p_this, "failed to set unicast ttl (%s)",
strerror(errno) );
}
} }
} }
/* Set multicast output interface */ /* Set multicast output interface */
if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) ) if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) )
{ {
char *psz_mif = config_GetPsz( p_this, "miface" ); char *psz_mif = var_CreateGetString( p_this, "miface" );
if( psz_mif != NULL ) if( psz_mif != NULL )
{ {
int intf = if_nametoindex( psz_mif ); int intf = if_nametoindex( psz_mif );
...@@ -351,16 +306,14 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -351,16 +306,14 @@ static int OpenUDP( vlc_object_t * p_this )
{ {
msg_Err( p_this, "%s as multicast interface: %s", msg_Err( p_this, "%s as multicast interface: %s",
psz_mif, strerror(errno) ); psz_mif, strerror(errno) );
close( i_handle ); goto error;
return 0;
} }
} }
else else
{ {
msg_Err( p_this, "%s: bad IPv6 interface specification", msg_Err( p_this, "%s: bad IPv6 interface specification",
psz_mif ); psz_mif );
close( i_handle ); goto error;
return 0;
} }
} }
} }
...@@ -373,4 +326,8 @@ static int OpenUDP( vlc_object_t * p_this ) ...@@ -373,4 +326,8 @@ static int OpenUDP( vlc_object_t * p_this )
p_socket->i_mtu = val.i_int; p_socket->i_mtu = val.i_int;
return 0; return 0;
error:
close (i_handle);
return VLC_EGENERIC;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment