* netutils.c: various network functions
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: netutils.c,v 1.67 2002/06/01 12:32:01 sam Exp $
+ * $Id: netutils.c,v 1.80 2003/03/03 14:21:08 gbazin Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Benoit Steiner <benny@via.ecp.fr>
* Xavier Marchesini <xav@alarue.net>
* Christophe Massiot <massiot@via.ecp.fr>
* Samuel Hocevar <sam@via.ecp.fr>
+ * Jon Lech Johansen <jon-vl@nanocrew.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Preamble
*****************************************************************************/
#include <stdlib.h> /* free(), realloc(), atoi() */
-#include <errno.h> /* errno() */
#include <string.h> /* memset() */
#include <vlc/vlc.h>
+#ifdef HAVE_ERRNO_H
+# include <errno.h> /* errno() */
+#endif
+
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* gethostname() */
-#elif defined( _MSC_VER ) && defined( _WIN32 )
+#elif defined( WIN32 ) && !defined( UNDER_CE )
# include <io.h>
#endif
#include <sys/time.h> /* gettimeofday */
#endif
-#ifdef WIN32
+#if defined( UNDER_CE )
+ /* No real network support (FIXME: use winsock1?) */
+#elif defined( WIN32 )
# include <winsock2.h>
#else
# include <netdb.h> /* hostent ... */
#include <sys/ioctl.h> /* ioctl() */
#endif
-#if defined( WIN32 ) /* tools to get the MAC adress from */
-#include <windows.h> /* the interface under Windows */
-#include <stdio.h>
-#include <nb30.h>
+#ifdef SYS_DARWIN
+#include <IOKit/IOKitLib.h>
+#include <IOKit/network/IOEthernetInterface.h>
+#include <IOKit/network/IOEthernetController.h>
+#endif
+
+#if defined( WIN32 ) && !defined( UNDER_CE )
+ /* tools to get the MAC adress from the interface under Windows */
+# include <windows.h>
+# include <stdio.h>
+# include <nb30.h>
#endif
#ifdef HAVE_NET_IF_H
#endif
#include "netutils.h"
+#include "vlc_playlist.h"
#include "network.h"
* as it depends on the VideoLAN channel server, which isn't frozen for
* the time being.
*****************************************************************************/
-struct input_channel_s
+struct input_channel_t
{
int i_channel; /* current channel number */
mtime_t last_change; /* last change date */
* Local prototypes
*****************************************************************************/
static int GetMacAddress ( vlc_object_t *, int i_fd, char *psz_mac );
-#ifdef WIN32
+#ifdef SYS_DARWIN
+static int GetNetIntfCtrl ( const char *psz_interface,
+ io_object_t *ctrl_service );
+#elif defined( WIN32 ) && !defined( UNDER_CE )
static int GetAdapterInfo ( int i_adapter, char *psz_string );
#endif
* once before any input thread is created or any call to other
* input_Channel*() function is attempted.
*****************************************************************************/
-int network_ChannelCreate( vlc_object_t *p_this )
+int __network_ChannelCreate( vlc_object_t *p_this )
{
-#if !defined( SYS_LINUX ) && !defined( WIN32 )
- msg_Err( p_this, "VLAN-based channels are not supported "
- "on this architecture" );
+#if !defined( SYS_LINUX ) && !( defined( WIN32 ) && !defined( UNDER_CE ) )
+ msg_Warn( p_this, "VLAN-based channels are not supported "
+ "on this architecture" );
#endif
/* Allocate structure */
* should be unlocked using input_ChannelLeave().
* Non 0 will be returned in case of error.
*****************************************************************************/
-int network_ChannelJoin( vlc_object_t *p_this, int i_channel )
+int __network_ChannelJoin( vlc_object_t *p_this, int i_channel )
{
#define VLCS_VERSION 13
#define MESSAGE_LENGTH 256
+#if defined( SYS_LINUX ) || ( defined( WIN32 ) && !defined( UNDER_CE ) )
module_t * p_network;
char * psz_network = NULL;
network_socket_t socket_desc;
struct timeval delay;
fd_set fds;
+ 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"
return -1;
}
- /* If last change is too recent, wait a while */
-// if( mdate() - p_this->p_vlc->p_channel->last_change
-// < INPUT_CHANNEL_CHANGE_DELAY )
-// {
-// msg_Warn( p_this, "waiting before changing channel" );
- /* XXX Isn't this completely brain-damaged ??? -- Sam */
- /* Yes it is. I don't think this is still justified with the new
- * vlanserver --Meuuh */
-// mwait( p_this->p_vlc->p_channel->last_change
-// + INPUT_CHANNEL_CHANGE_DELAY );
-// }
-
if( config_GetInt( p_this, "ipv4" ) )
{
psz_network = "ipv4";
socket_desc.i_server_port = i_port;
/* Find an appropriate network module */
- p_network = module_Need( p_this, MODULE_CAPABILITY_NETWORK, psz_network,
- &socket_desc );
+ 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_network );
+ module_Unneed( p_this, p_network );
free( psz_vlcs ); /* Do we really need this ? -- Meuuh */
i_fd = socket_desc.i_handle;
{
msg_Dbg( p_this, "vlcs said '%s'", psz_mess + 2 );
}
- else /* We got something to play ! FIXME: not very nice */
+ else
{
-#if 0
-# define p_item (&p_this->p_vlc->p_playlist->p_item \
- [ p_this->p_vlc->p_playlist->i_index + 1])
- vlc_mutex_lock( &p_this->p_vlc->p_playlist->change_lock );
- if( p_item )
- {
- free( p_item->psz_name );
- p_item->psz_name = strdup( psz_mess );
- /* Unlock _afterwards_ */
- vlc_mutex_unlock( &p_this->p_vlc->p_playlist->change_lock );
- }
- else
+ /* We got something to play ! */
+ playlist_t *p_playlist;
+ p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
+ FIND_ANYWHERE );
+ if( p_playlist != NULL )
{
- /* Unlock _before_ */
- vlc_mutex_unlock( &p_this->p_vlc->p_playlist->change_lock );
- intf_PlaylistAdd( p_this->p_vlc->p_playlist, 0, psz_mess );
+ playlist_Add( p_playlist, psz_mess,
+ PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
+ vlc_object_release( p_playlist );
}
-#endif
}
/* Close the socket and return nicely */
-#ifndef WIN32
- close( i_fd );
-#else
+# if defined( WIN32 )
closesocket( i_fd );
-#endif
+# else
+ close( i_fd );
+# endif
+#endif
return 0;
}
return( 0 );
-#elif defined( WIN32 )
+#elif defined( SYS_DARWIN )
+ char *psz_interface;
+ io_object_t ctrl_service;
+ CFTypeRef cfd_mac_address;
+ UInt8 ui_mac_address[kIOEthernetAddressSize];
+
+ if( !(psz_interface = config_GetPsz( p_this, "iface" )) )
+ {
+ msg_Err( p_this, "configuration variable iface empty" );
+ return( -1 );
+ }
+
+ if( GetNetIntfCtrl( psz_interface, &ctrl_service ) )
+ {
+ msg_Err( p_this, "GetNetIntfCtrl failed" );
+ return( -1 );
+ }
+
+ cfd_mac_address = IORegistryEntryCreateCFProperty( ctrl_service,
+ CFSTR(kIOMACAddress),
+ kCFAllocatorDefault,
+ 0 );
+ IOObjectRelease( ctrl_service );
+ if( cfd_mac_address == NULL )
+ {
+ msg_Err( p_this, "IORegistryEntryCreateCFProperty failed" );
+ return( -1 );
+ }
+
+ CFDataGetBytes( cfd_mac_address,
+ CFRangeMake(0, kIOEthernetAddressSize),
+ ui_mac_address );
+ CFRelease( cfd_mac_address );
+
+ sprintf( psz_mac, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
+ ui_mac_address[0], ui_mac_address[1],
+ ui_mac_address[2], ui_mac_address[3],
+ ui_mac_address[4], ui_mac_address[5] );
+
+ return( 0 );
+
+#elif defined( WIN32 ) && !defined( UNDER_CE )
int i, i_ret = -1;
/* Get adapter list - support for more than one adapter */
#endif
}
-#ifdef WIN32
+#ifdef SYS_DARWIN
+/*****************************************************************************
+ * GetNetIntfCtrl : get parent controller for network interface
+ *****************************************************************************/
+static int GetNetIntfCtrl( const char *psz_interface,
+ io_object_t *ctrl_service )
+{
+ mach_port_t port;
+ kern_return_t ret;
+ io_object_t intf_service;
+ io_iterator_t intf_iterator;
+
+ /* get port for IOKit communication */
+ if( ( ret = IOMasterPort( MACH_PORT_NULL, &port ) ) != KERN_SUCCESS )
+ {
+ return( -1 );
+ }
+
+ /* look up the IOService object for the interface */
+ ret = IOServiceGetMatchingServices( port, IOBSDNameMatching( port, 0,
+ psz_interface ), &intf_iterator );
+ if( ret != KERN_SUCCESS )
+ {
+ return( -1 );
+ }
+
+ intf_service = IOIteratorNext( intf_iterator );
+ if( intf_service == NULL )
+ {
+ return( -1 );
+ }
+
+ ret = IORegistryEntryGetParentEntry( intf_service,
+ kIOServicePlane,
+ ctrl_service );
+ IOObjectRelease( intf_service );
+ if( ret != KERN_SUCCESS )
+ {
+ return( -1 );
+ }
+
+ return( 0 );
+}
+
+#elif defined( WIN32 ) && !defined( UNDER_CE )
/*****************************************************************************
* GetAdapterInfo : gets some informations about the interface using NETBIOS
*****************************************************************************/