[Player-cvs] hxclientkit/src/hxrecordengine mac-unix.pcf, NONE, 1.1.4.2 CHXClientRecordFile.cpp, 1.2.2.1, 1.2.2.2

[Player-cvs] hxclientkit/src/hxrecordengine mac-unix.pcf, NONE, 1.1.4.2 CHXClientRecordFile.cpp, 1.2.2.1, 1.2.2.2

bobclark at helixcommunity.org bobclark at helixcommunity.org
Fri May 28 17:55:36 PST 2010


Update of /cvsroot/player/hxclientkit/src/hxrecordengine
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv30954

Modified Files:
      Tag: hxclient_3_1_0_atlas
	CHXClientRecordFile.cpp 
Added Files:
      Tag: hxclient_3_1_0_atlas
	mac-unix.pcf 
Log Message:
merge 150 Mac-specific changes into 310Atlas

Index: CHXClientRecordFile.cpp
===================================================================
RCS file: /cvsroot/player/hxclientkit/src/hxrecordengine/CHXClientRecordFile.cpp,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -d -r1.2.2.1 -r1.2.2.2
--- CHXClientRecordFile.cpp	29 Feb 2008 22:41:50 -0000	1.2.2.1
+++ CHXClientRecordFile.cpp	29 May 2010 01:55:33 -0000	1.2.2.2
@@ -71,6 +71,141 @@
 
 #include "hlxclib/limits.h"
 
+#if defined(_MAC_UNIX)
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <IOKit/IOKitLib.h>
+#include <IOKit/network/IOEthernetInterface.h>
+#include <IOKit/network/IONetworkInterface.h>
+#include <IOKit/network/IOEthernetController.h>
+
+// see http://developer.apple.com/samplecode/GetPrimaryMACAddress/listing1.html
+
+static kern_return_t FindEthernetInterfaces(io_iterator_t *matchingServices)
+{
+    kern_return_t    kernResult; 
+    mach_port_t      masterPort;
+    CFMutableDictionaryRef  matchingDict;
+    CFMutableDictionaryRef  propertyMatchDict;
+    
+    kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
+    if (KERN_SUCCESS != kernResult)
+    {
+        printf("IOMasterPort returned %d\n", kernResult);
+        return kernResult;
+    }
+    
+    matchingDict = IOServiceMatching(kIOEthernetInterfaceClass);
+    
+    // Note that another option here would be:
+    // matchingDict = IOBSDMatching("en0");
+    
+    if (matchingDict)
+    {
+        // Each IONetworkInterface object has a Boolean property with the key kIOPrimaryInterface. Only the
+        // primary (built-in) interface has this property set to TRUE.
+        
+        // IOServiceGetMatchingServices uses the default matching criteria defined by IOService. This considers
+        // only the following properties plus any family-specific matching in this order of precedence 
+        // (see IOService::passiveMatch):
+        //
+        // kIOProviderClassKey (IOServiceMatching)
+        // kIONameMatchKey (IOServiceNameMatching)
+        // kIOPropertyMatchKey
+        // kIOPathMatchKey
+        // kIOMatchedServiceCountKey
+        // family-specific matching
+        // kIOBSDNameKey (IOBSDNameMatching)
+        // kIOLocationMatchKey
+        
+        // The IONetworkingFamily does not define any family-specific matching. This means that in            
+        // order to have IOServiceGetMatchingServices consider the kIOPrimaryInterface property, we must
+        // add that property to a separate dictionary and then add that to our matching dictionary
+        // specifying kIOPropertyMatchKey.
+        
+        propertyMatchDict = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
+                                                      &kCFTypeDictionaryKeyCallBacks,
+                                                      &kCFTypeDictionaryValueCallBacks);
+        
+        if (NULL == propertyMatchDict)
+        {
+            printf("CFDictionaryCreateMutable returned a NULL dictionary.\n");
+        }
+        else {
+            // Set the value in the dictionary of the property with the given key, or add the key 
+            // to the dictionary if it doesn't exist. This call retains the value object passed in.
+            CFDictionarySetValue(propertyMatchDict, CFSTR(kIOPrimaryInterface), kCFBooleanTrue); 
+            
+            // Now add the dictionary containing the matching value for kIOPrimaryInterface to our main
+            // matching dictionary. This call will retain propertyMatchDict, so we can release our reference 
+            // on propertyMatchDict after adding it to matchingDict.
+            CFDictionarySetValue(matchingDict, CFSTR(kIOPropertyMatchKey), propertyMatchDict);
+            CFRelease(propertyMatchDict);
+        }
+    }
+    
+    // IOServiceGetMatchingServices retains the returned iterator, so release the iterator when we're done with it.
+    // IOServiceGetMatchingServices also consumes a reference on the matching dictionary so we don't need to release
+    // the dictionary explicitly.
+    kernResult = IOServiceGetMatchingServices(masterPort, matchingDict, matchingServices);    
+    
+    return kernResult;
+}
+
+static kern_return_t MacGetEnetMACAddress( unsigned char* MACAddress, UINT32* ioBufferSize, INT32 inetInterface )
+{
+    io_iterator_t  intfIterator;
+    
+    io_object_t    intfService;
+    io_object_t    controllerService;
+    kern_return_t  kernResult = KERN_FAILURE;
+    
+    kernResult = FindEthernetInterfaces(&intfIterator);
+    
+    // Initialize the returned address
+    bzero(MACAddress, kIOEthernetAddressSize);
+    
+    // IOIteratorNext retains the returned object, so release it when we're done with it.
+    while ((intfService = IOIteratorNext(intfIterator)))
+    {
+        CFDataRef  MACAddressAsCFData;        
+        
+        // IONetworkControllers can't be found directly by the IOServiceGetMatchingServices call, 
+        // since they are hardware nubs and do not participate in driver matching. In other words,
+        // registerService() is never called on them. So we've found the IONetworkInterface and will 
+        // get its parent controller by asking for it specifically.
+        
+        // IORegistryEntryGetParentEntry retains the returned object, so release it when we're done with it.
+        kernResult = IORegistryEntryGetParentEntry( intfService,
+                                                   kIOServicePlane,
+                                                   &controllerService );
+        
+        if (KERN_SUCCESS == kernResult)
+        {
+            // Retrieve the MAC address property from the I/O Registry in the form of a CFData
+            MACAddressAsCFData = (CFDataRef)IORegistryEntryCreateCFProperty( controllerService,
+                                                                            CFSTR(kIOMACAddress),
+                                                                            kCFAllocatorDefault,
+                                                                            0);
+            if (MACAddressAsCFData)
+            {
+                // Get the raw bytes of the MAC address from the CFData
+                CFDataGetBytes(MACAddressAsCFData, CFRangeMake(0, kIOEthernetAddressSize), MACAddress);
+                CFRelease(MACAddressAsCFData);
+            }
+            
+            // Done with the parent Ethernet controller object so we release it.
+            (void) IOObjectRelease(controllerService);
+        }
+        
+        // Done with the Ethernet interface object so we release it.
+        (void) IOObjectRelease(intfService);
+    }
+    
+    return kernResult;
+}
+#endif
+
 #define MAX_NODISKIO_BUFFERING          7000
 #define PROGRESS_REPORTING_INTERVAL     1000
 // #define HXR_SEC_INVALID_ENCRYPTPERIOD   MAKE_HX_RESULT( 1, SS_SEC, 10 )
@@ -91,16 +226,14 @@
     {
 #if defined(_MAC_UNIX) || defined(_UNIX)
         // replace some of the key bytes with the computer's MAC address
-        const SInt32 kMotherboardInterface = 0;
-        InetInterfaceInfo inetInterfaceInfo;
-        OSStatus status = OTInetGetInterfaceInfo( &inetInterfaceInfo, kMotherboardInterface );
-        if ( status != noErr )
-        {
-            status = OTInetGetInterfaceInfo( &inetInterfaceInfo, kDefaultInetInterface );
-        }
-        if ( status == noErr )
+        unsigned char MACAddress[6];
+        UINT32 bufferSize = 6;
+        
+        kern_return_t status = MacGetEnetMACAddress( MACAddress, &bufferSize, 0 );
+        
+        if (status == noErr)
         {
-            BlockMoveData( inetInterfaceInfo.fHWAddr, &actualKey[ 4 ], 6 );
+            BlockMoveData( MACAddress, &actualKey[ 4 ], 6 );
         }
 #else
         // make the key bytes reasonably machine-unique here for this platform

--- NEW FILE: mac-unix.pcf ---
# ***** BEGIN LICENSE BLOCK *****
# Source last modified: $Id: mac-unix.pcf,v 1.1.4.2 2010/05/29 01:55:33 bobclark Exp $
# 
# Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
# 
# The contents of this file, and the files included with this file,
# are subject to the current version of the RealNetworks Public
# Source License (the "RPSL") available at
# http://www.helixcommunity.org/content/rpsl unless you have licensed
# the file under the current version of the RealNetworks Community
# Source License (the "RCSL") available at
# http://www.helixcommunity.org/content/rcsl, in which case the RCSL
# will apply. You may also obtain the license terms directly from
# RealNetworks.  You may not use this file except in compliance with
# the RPSL or, if you have a valid RCSL with RealNetworks applicable
# to this file, the RCSL.  Please see the applicable RPSL or RCSL for
# the rights, obligations and limitations governing use of the
# contents of the file.
# 
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL") in which case the provisions of the GPL are applicable
# instead of those above. If you wish to allow use of your version of
# this file only under the terms of the GPL, and not to allow others
# to use your version of this file under the terms of either the RPSL
# or RCSL, indicate your decision by deleting the provisions above
# and replace them with the notice and other provisions required by
# the GPL. If you do not delete the provisions above, a recipient may
# use your version of this file under the terms of any one of the
# RPSL, the RCSL or the GPL.
# 
# This file is part of the Helix DNA Technology. RealNetworks is the
# developer of the Original Code and owns the copyrights in the
# portions it created.
# 
# This file, and the files included with this file, is distributed
# and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
# KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
# ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
# ENJOYMENT OR NON-INFRINGEMENT.
# 
# Technology Compatibility Kit Test Suite(s) Location:
#    http://www.helixcommunity.org/content/tck
# 
# Contributor(s):
# 
# ***** END LICENSE BLOCK *****
# 

project.AddSystemFrameworks("/System/Library/Frameworks/IOKit.framework")





More information about the Player-cvs mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.