• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: local ip address?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: local ip address?


  • Subject: Re: local ip address?
  • From: Julien Jalon <email@hidden>
  • Date: Thu, 22 Nov 2001 22:26:09 +0100

Le mercredi 21 novembre 2001, ` 11:37 PM, Tom Waters a icrit :

Thanks Carl!

I hacked your source up so that it only returned the ip addresses (since that's all I needed!) and returned them in an Objective-C dictionary, with the interface as the key and the dotted string representation of the ip address as the values.

I added this to Steven Frank's SmallSockets classes in my own copy as a static method on Socket.

I've attached the implementation if Steven or anyone else wants to incorporate it.
[...]

A much more MacOS X way to do this: use the System Configuration framework.

Here is the code:
#import <Cocoa/Cocoa.h>

#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SystemConfiguration.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
SCDynamicStoreRef dynRef=SCDynamicStoreCreate(kCFAllocatorSystemDefault, (CFStringRef)@"Whatever you want", NULL, NULL);
// Get all available interfaces IPv4 addresses
NSArray *interfaceList=(NSArray *)SCDynamicStoreCopyKeyList(dynRef,(CFStringRef)@"State:/Network/Interface/
.*/IPv4");
NSEnumerator *interfaceEnumerator=[interfaceList objectEnumerator];
NSString *interface;

NSLog(@"Interfaces: %@",interfaceList);

while(interface=[interfaceEnumerator nextObject]) {
NSDictionary *interfaceEntry=(NSDictionary *)SCDynamicStoreCopyValue(dynRef,(CFStringRef)interface);
NSArray *adList=[interfaceEntry objectForKey:@"Addresses"];

NSLog(@"%@ -> addresses: %@",interface,adList);

[interfaceEntry release]; // must be released
}

[interfaceList release]; // must be released
[pool release];

return 0;
}


You can do many things with this framework... very interesting.
For more information, look at the headers and at:
<http://developer.apple.com/techpubs/macosx/Networking/SysConfigOverview926/
index.html>
You will find there every key to look at for the System Configuration.

Julien Jalon
<http://mapage.noos.fr/jalon>


References: 
 >Re: local ip address? (From: Tom Waters <email@hidden>)

  • Prev by Date: Re: Mutability
  • Next by Date: Printing PDF even/odd pages - was Re: Text Editor
  • Previous by thread: Re: local ip address?
  • Next by thread: Notifications and exceptions
  • Index(es):
    • Date
    • Thread