Return from C to Blitzmax

BlitzMax Forums/BlitzMax Programming/Return from C to Blitzmax

MacSven(Posted 2010) [#1]
I im rewritting m modul to get the MAC Address of a selected EthernetCard
This is a part of the C Source

void GetMAC(enx)
 {
  io_iterator_t intfIterator;
  kern_return_t kernResult = KERN_FAILURE;
  
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

  // NSLog(@"Detecting Network Interfaces...");
  
  kernResult = FindNetworkInterfaces( &intfIterator );
  if( KERN_SUCCESS != kernResult ) {
    return ( "findNetworkInterfaces failed\n" );

  } else {

    /* NSLog( @"Found one of more valid interfaces. Extracting MAC addresses..." );*/

    NSDictionary* intfDictionary = GetMACAddresses( intfIterator );

   /* ADDED !!! */
   /* more portable code than: for( id key in intfDictionary ) { ... */

   NSArray* keys = [[intfDictionary allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

   int num = [keys count];
   int i;
   for (i = 0; i < num; i++) 
   {
      // NSLog( @"  %@  =>  %@", [keys objectAtIndex: i], [intfDictionary objectForKey: [keys objectAtIndex: i]] );
	if (i==enx){
	printf("%s\n",[[intfDictionary objectForKey: [keys objectAtIndex: i]] UTF8String]);
	//printf("%s %s\n",[[keys objectAtIndex: i] UTF8String],[[intfDictionary objectForKey: [keys objectAtIndex: i]] UTF8String]);
	//printf( "%s %s\n",[keys objectAtIndex: i], [intfDictionary objectForKey: [keys objectAtIndex: i]]);
	return [[intfDictionary objectForKey: [keys objectAtIndex: i]] UTF8String];
	}
   }

//	return [[intfDictionary objectForKey: [keys objectAtIndex: i]] UTF8String];
    IOObjectRelease( intfIterator );
  }
  
  /* [pool drain]; */
  [pool release];

  return 0;
}


This is the Funtion of my module:


		Function GetMAC(enx:Int)


I Have now the problem what i return [[intfDictionary objectForKey: [keys objectAtIndex: i]] UTF8String];
this shows my any int but not the string itself. What is wrong with my Code.
I i use printf("%s\n",[[intfDictionary objectForKey: [keys objectAtIndex: i]] UTF8String]); it show me the MAC Address.


Brucey(Posted 2010) [#2]
If you define your function as "void", I'm surprised the compiler lets you "return" anything.

My BaH.inet module uses the BSD apis to retrieve the mac address, although it gets much more information about the network interfaces than just that...
Interface   : en0
            : UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST
IP Address  : 192.168.2.1
Netmask     : 255.255.255.0
Broadcast   : 192.168.2.255
MAC Address : xx:xx:xx:xx:xx:xx


Local inet:TInet = GetInetInterface("en0")
... etc...


Oh, and if you return stuff *before* you release memory, how will the memory be released?


MacSven(Posted 2010) [#3]
Hi Brucey,

How can i download it, this will save much more time for me.


rs22(Posted 2010) [#4]
It's downloadable from http://maxmods.googlecode.com You'll need an SVN client to download it.


Brucey(Posted 2010) [#5]
I've made a release, so it's now available to download directly.