Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-10-2008, 05:57 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 6
Question iPhone MAC-Address ???

How can i get the iPhones (Wi-Fi) MAC-Address ?

in "SystemConfiguration.framework" is a Function that seems to tell the MAC but has the "__IPHONE_NA" -> Not Available >>>>
CFStringRef
SCNetworkInterfaceGetHardwareAddressString (SCNetworkInterfaceRef interface) __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_NA);

"<IOKit/network/IOEthernetController.h>" isn't available on iPhone, too.

Please help me...
md582 is offline   Reply With Quote
Old 10-10-2008, 09:02 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 288
Default

Quote:
Originally Posted by md582 View Post
How can i get the iPhones (Wi-Fi) MAC-Address ?

in "SystemConfiguration.framework" is a Function that seems to tell the MAC but has the "__IPHONE_NA" -> Not Available >>>>
CFStringRef
SCNetworkInterfaceGetHardwareAddressString (SCNetworkInterfaceRef interface) __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_NA);

"<IOKit/network/IOEthernetController.h>" isn't available on iPhone, too.

Please help me...
My router gave me mine.. but I guess you want it programatically?
Kenrik is offline   Reply With Quote
Old 10-10-2008, 07:45 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 6
Default

yes, programatically !!!
i see it @*preferences > general > info ! But i need it in my program !!!
md582 is offline   Reply With Quote
Old 10-10-2008, 08:07 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

I think it's buried deep in some network data structures. Look at the code in this post. It will run under the SDK. I think you can find the MAC address in the data structures that it queries.

How to get IPv6 address using getifaddrs and which version of glibc supports
PhoneyDeveloper is offline   Reply With Quote
Old 10-12-2008, 07:43 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 6
Default

I think the iPhone doesn't have a IPv6 Address ? I only get the IPv4 with this code ! And IPv6 is not the MAC-Address !?
I thought i can use the <in.h> like this >>
...
struct ifreq ifr;
...
a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
printf("%02x:%02x:%02x:%02x:%02x:%02x\n", a[0],a[1],a[2],a[3],a[4],a[5]);
...
but the <in.h> hasn't the "ifr_hwaddr" like Linux has !! ??


see this >> from my Mac !!!
struct ifreq {
#ifndef IFNAMSIZ
#define IFNAMSIZ IF_NAMESIZE
#endif
char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
union {
struct sockaddr ifru_addr;
struct sockaddr ifru_dstaddr;
struct sockaddr ifru_broadaddr;
short ifru_flags;
int ifru_metric;
int ifru_mtu;
int ifru_phys;
int ifru_media;
int ifru_intval;
caddr_t ifru_data;
struct ifdevmtu ifru_devmtu;
struct ifkpi ifru_kpi;
} ifr_ifru;

and this from Linux >>>
166 union {
167 struct sockaddr ifru_addr;
168 struct sockaddr ifru_dstaddr;
169 struct sockaddr ifru_broadaddr;
170 struct sockaddr ifru_netmask;
171 struct sockaddr ifru_hwaddr;
172 short ifru_flags;
173 int ifru_ivalue;
174 int ifru_mtu;
175 struct ifmap ifru_map;
176 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
177 char ifru_newname[IFNAMSIZ];
178 void __user * ifru_data;
179 struct if_settings ifru_settings;
180 } ifr_ifru;

on my MAC (and iPhone) i'm missing the "ifr_hwaddr" !!
md582 is offline   Reply With Quote
Old 10-12-2008, 11:44 AM   #6 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Yes, the phone has no IPv6 address, and the IPv6 address isn't the MAC address.

One other thought. On the Mac ifconfig can figure out the Mac address. The ifconfig source is opensource as part of Darwin. You can get it from this page:

Apple - Public Source - Darwin - Projects

It's in a project called network_cmds.

Of course the sources on that page aren't necessarily sources that will work on the phone.
PhoneyDeveloper is offline   Reply With Quote
Old 10-12-2008, 01:18 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 6
Default

i have downloaded this and it seems that it uses "ioctl" for this....

but i can't get it working...
md582 is offline   Reply With Quote
Old 10-12-2008, 02:07 PM   #8 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

I guess it's possible that ioctl is disabled as part of the sandbox.

Why do you want the machine's MAC address?

Maybe you need to use up one of your support incidents to figure this out.

Some time in the next week or so the NDA should be officially lifted by Apple and it should be possible to ask this kind of question on the Apple networking list and get an answer.
PhoneyDeveloper is offline   Reply With Quote
Old 10-25-2008, 01:59 PM   #9 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 6
Default the code

If someone else needs it :
This is the code > (i got help from devforums.apple.com)

Quote:
#if ! defined(IFT_ETHER)
#define IFT_ETHER 0x6/* Ethernet CSMACD */
#endif

- (IBAction)testActionid)sender
{
#pragma unused(sender)
BOOL &nb sp; &nbsp ; success;
struct ifaddrs * addrs;
const struct ifaddrs * cursor;
const struct sockaddr_dl * dlAddr;
const uint8_t * base;
int &nbs p; i;

success = getifaddrs(&addrs) == 0;
if (success) {
cursor = addrs;
while (cursor != NULL) {
& nbsp; fprintf(stderr, "%s\n", cursor->ifa_name);
& nbsp; if ( (cursor->ifa_addr->sa_family == AF_LINK)
& nbsp; && (((const struct sockaddr_dl *) cursor->ifa_addr)->sdl_type == IFT_ETHER) ) {
& nbsp; dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
& nbsp; fprintf(stderr, " sdl_nlen = %d\n", dlAddr->sdl_nlen);
& nbsp; fprintf(stderr, " sdl_alen = %d\n", dlAddr->sdl_alen);
& nbsp; base = (const uint8_t *) &dlAddr->sdl_data[dlAddr->sdl_nlen];
& nbsp; fprintf(stderr, " ");
& nbsp; for (i = 0; i < dlAddr->sdl_alen; i++) {
& nbsp; if (i != 0) {
& nbsp; fprintf(stderr, ":");
& nbsp; }
& nbsp; fprintf(stderr, "%02x", base[i]);
& nbsp; }
& nbsp; fprintf(stderr, "\n");
& nbsp; }
& nbsp; cursor = cursor->ifa_next;
}

freeifaddrs(addrs);
}
}
of course ignore the "&NBSP;"s !
md582 is offline   Reply With Quote
Old 12-17-2009, 08:04 AM   #10 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 58
Default

Quote:
Originally Posted by md582 View Post
If someone else needs it :
This is the code > (i got help from devforums.apple.com)


of course ignore the "&NBSP;"s !
does it mean that Apple will not reject application using this code?
Becasue it was posted on devforums.apple.com

I need to use parts of this code and I would like to be sure that Apple will not
reject my app because of usage.

Thanks
embedded is offline   Reply With Quote
Old 12-17-2009, 10:09 AM   #11 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 6
Default

Quote:
Originally Posted by embedded View Post
does it mean that Apple will not reject application using this code?
Becasue it was posted on devforums.apple.com

I need to use parts of this code and I would like to be sure that Apple will not
reject my app because of usage.

Thanks
I don't think they would reject it, there is no usage of any private Frameworks.

But posting it on apples devforums wouldn't mean it couldn't be rejected.
md582 is offline   Reply With Quote
Old 12-17-2009, 11:49 AM   #12 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 58
Default

Quote:
Originally Posted by md582 View Post
I don't think they would reject it, there is no usage of any private Frameworks.

But posting it on apples devforums wouldn't mean it couldn't be rejected.
This is what I think.
There is no use of private frameworks, just using standard system library calls.

Please let me know if I'm wrong...

Thanks
embedded is offline   Reply With Quote
Old 12-18-2009, 03:10 AM   #13 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 58
Default

Quote:
Originally Posted by embedded View Post
This is what I think.
There is no use of private frameworks, just using standard system library calls.

Please let me know if I'm wrong...

Thanks
Can anyone confirm or refute my theory?

Thanks
embedded is offline   Reply With Quote
Old 12-18-2009, 08:20 AM   #14 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 169
Default

If you are using inforamation that is not documented in the SDK - that is you have pulled it from a header file instead - then you run the risk of being rejected.

You need to contact Apple diretly if you want an answer to this question.

-t
thewitt is offline   Reply With Quote
Old 12-18-2009, 08:53 AM   #15 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 58
Default

Quote:
Originally Posted by thewitt View Post
If you are using inforamation that is not documented in the SDK - that is you have pulled it from a header file instead - then you run the risk of being rejected.

You need to contact Apple diretly if you want an answer to this question.

-t
Could you provide me with the right email address?

10x
embedded is offline   Reply With Quote
Old 12-18-2009, 09:23 AM   #16 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 169
Default

The only way I know to get an official answer to your question is to submit it to Developer Tech Support as one of your paid tech support requests.

You could ask on the Apple Developer Program Forums and get an unofficial reply from one of the Apple developers who monitor the forums, but I know of no other way to engage Apple officially for an answer to this type of question.

There is no public email address for free software development support requests at Apple that I am aware of, and no one except Apple can really answer your question about rejection over this approach.

If you can find someone who is willing to admit that they have this code running in an approved App, that would be a little more comforting - however it might be that they "slipped through the cracks" as well and simply did not get caught. Admitting in public that they are using an undocumented approach to answering the question might get their application reviewed again...

You could also simply develop the application and submit it for review - hoping it does not violate the Undocumented API portion of your Developer Agreement. I personally would not build an application around an undocumented constant found only in a header file without first getting an official position from Apple, however I know many others who would do so and simply take their chances.

You have to decide how much of a risk this is to you.

-t
thewitt is offline   Reply With Quote
Reply

Bookmarks

Tags
address, iphone, mac, wifi, wlan

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,761
Threads: 89,201
Posts: 380,569
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jam3skn0
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:33 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0