]> git.sesse.net Git - vlc/commitdiff
./src/misc/netutils.c: GetMacAddress Darwin support
authorJon Lech Johansen <jlj@videolan.org>
Sat, 5 Oct 2002 19:26:23 +0000 (19:26 +0000)
committerJon Lech Johansen <jlj@videolan.org>
Sat, 5 Oct 2002 19:26:23 +0000 (19:26 +0000)
  ./src/libvlc.h: Default to en0 instead of eth0 under Darwin

ChangeLog
src/libvlc.h
src/misc/netutils.c

index 4f3740510fa64680ded9fa836c83f1e18ef7dde1..9ea6bea03abfefbb3fff4c35f2f6c2a6c31cccbe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 0.5.0
 Not released yet
 
+  * ./src/misc/netutils.c: GetMacAddress Darwin support
+  * ./src/libvlc.h: default to en0 instead of eth0 under Darwin
   * ./plugins/dvdplay/access.c: use dvdplay after it has completed
     initialization.
   * ./configure.in: better detection of IPv6, fixed solaris handling.
index fa169da540c505bc22f59633b4dd6590e90dfc96..5bcc23455e9aabfd56f83bc0dacbc6d3416ac7c0 100644 (file)
@@ -2,7 +2,7 @@
  * libvlc.h: main libvlc header
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: libvlc.h,v 1.17 2002/10/03 18:56:09 sam Exp $
+ * $Id: libvlc.h,v 1.18 2002/10/05 19:26:23 jlj Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -398,7 +398,11 @@ vlc_module_begin();
     add_integer( "channel-port", 6010, NULL,
                  CHAN_PORT_TEXT, CHAN_PORT_LONGTEXT );
     add_integer( "mtu", 1500, NULL, MTU_TEXT, MTU_LONGTEXT );
+#ifdef SYS_DARWIN
+    add_string( "iface", "en0", NULL, IFACE_TEXT, IFACE_LONGTEXT );
+#else
     add_string( "iface", "eth0", NULL, IFACE_TEXT, IFACE_LONGTEXT );
+#endif
     add_string( "iface-addr", "", NULL, IFACE_ADDR_TEXT, IFACE_ADDR_LONGTEXT );
 
     add_integer( "program", 0, NULL,
index 03601ddea0c9bc6c366081439b39ef1a6815ef52..9ad5cf63448b8fcfc286a76a30e710c6247d58e8 100644 (file)
@@ -2,7 +2,7 @@
  * netutils.c: various network functions
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: netutils.c,v 1.73 2002/07/31 20:56:53 sam Exp $
+ * $Id: netutils.c,v 1.74 2002/10/05 19:26:23 jlj Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Benoit Steiner <benny@via.ecp.fr>
@@ -10,6 +10,7 @@
  *          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
 #include <sys/ioctl.h>                                            /* ioctl() */
 #endif
 
+#ifdef SYS_DARWIN
+#include <IOKit/IOKitLib.h>
+#include <IOKit/network/IOEthernetInterface.h>
+#include <IOKit/network/IOEthernetController.h>
+#endif
+
 #if defined( WIN32 )                    /* tools to get the MAC adress from  */
 #include <windows.h>                    /* the interface under Windows       */
 #include <stdio.h>
@@ -97,7 +104,10 @@ struct input_channel_t
  * 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 )
 static int GetAdapterInfo  ( int i_adapter, char *psz_string );
 #endif
 
@@ -329,6 +339,47 @@ static int GetMacAddress( vlc_object_t *p_this, int i_fd, char *psz_mac )
 
     return( 0 );
 
+#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 )
     int i, i_ret = -1;
 
@@ -362,7 +413,51 @@ static int GetMacAddress( vlc_object_t *p_this, int i_fd, char *psz_mac )
 #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 )
 /*****************************************************************************
  * GetAdapterInfo : gets some informations about the interface using NETBIOS
  *****************************************************************************/