+ if( p_this->p_vlc->p_channel == NULL )
+ {
+ msg_Warn( p_this, "channels not initialized" );
+ return 0;
+ }
+
+ if( p_this->p_vlc->p_channel->i_channel == i_channel )
+ {
+ return 0;
+ }
+
+ if( !config_GetInt( p_this, "network-channel" ) )
+ {
+ msg_Err( p_this, "channels disabled, to enable them, use the"
+ " --channels option" );
+ return -1;
+ }
+
+ if( config_GetInt( p_this, "ipv4" ) )
+ {
+ psz_network = "ipv4";
+ }
+ if( config_GetInt( p_this, "ipv6" ) )
+ {
+ psz_network = "ipv6";
+ }
+
+ /* Getting information about the channel server */
+ if( !(psz_vlcs = config_GetPsz( p_this, "channel-server" )) )
+ {
+ msg_Err( p_this, "configuration variable channel-server empty" );
+ return -1;
+ }
+
+ i_port = config_GetInt( p_this, "channel-port" );
+
+ msg_Dbg( p_this, "connecting to %s:%d", psz_vlcs, i_port );
+
+ /* Prepare the network_socket_t structure */
+ socket_desc.i_type = NETWORK_UDP;
+ socket_desc.psz_bind_addr = "";
+ socket_desc.i_bind_port = 4321;
+ socket_desc.psz_server_addr = psz_vlcs;
+ socket_desc.i_server_port = i_port;
+
+ /* Find an appropriate network module */
+ p_this->p_private = (void*) &socket_desc;
+ p_network = module_Need( p_this, "network", psz_network/*, &socket_desc*/ );
+ if( p_network == NULL )
+ {
+ return( -1 );
+ }
+ module_Unneed( p_this, p_network );
+
+ free( psz_vlcs ); /* Do we really need this ? -- Meuuh */
+ i_fd = socket_desc.i_handle;
+
+ /* Look for the interface MAC address */
+ if( GetMacAddress( p_this, i_fd, psz_mac ) )
+ {
+ msg_Err( p_this, "failed getting MAC address" );
+ close( i_fd );
+ return -1;
+ }
+
+ msg_Dbg( p_this, "MAC address is %s", psz_mac );
+
+ /* Build the message */
+ sprintf( psz_mess, "%d %u %lu %s \n", i_channel, VLCS_VERSION,
+ (unsigned long)(mdate() / (u64)1000000),
+ psz_mac );
+
+ /* Send the message */
+ send( i_fd, psz_mess, MESSAGE_LENGTH, 0 );
+
+ msg_Dbg( p_this, "attempting to join channel %d", i_channel );
+
+ /* We have changed channels ! (or at least, we tried) */
+ p_this->p_vlc->p_channel->last_change = mdate();
+ p_this->p_vlc->p_channel->i_channel = i_channel;
+
+ /* Wait 5 sec for an answer from the server */
+ delay.tv_sec = 5;
+ delay.tv_usec = 0;
+ FD_ZERO( &fds );
+ FD_SET( i_fd, &fds );
+
+ switch( select( i_fd + 1, &fds, NULL, NULL, &delay ) )
+ {
+ case 0:
+ msg_Err( p_this, "no answer from vlcs" );
+ close( i_fd );
+ return -1;
+
+ case -1:
+ msg_Err( p_this, "error while listening to vlcs" );
+ close( i_fd );
+ return -1;
+ }
+
+ recv( i_fd, psz_mess, MESSAGE_LENGTH, 0 );
+ psz_mess[ MESSAGE_LENGTH - 1 ] = '\0';
+
+ if( !strncasecmp( psz_mess, "E:", 2 ) )
+ {
+ msg_Err( p_this, "vlcs said '%s'", psz_mess + 2 );
+ close( i_fd );
+ return -1;
+ }
+ else if( !strncasecmp( psz_mess, "I:", 2 ) )
+ {
+ msg_Dbg( p_this, "vlcs said '%s'", psz_mess + 2 );