Unix Programming - get mac address...

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2007 > get mac address...





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author get mac address...
SpreadTooThin

2007-06-08, 7:20 pm

On Mac OS X, in C++
I want to get the hardware mac address of the machine... (First device
if more than one.)

I've seen example that do a pipe ifcongif and grep for the mac
address... but surely there is a direct api to get the mac address.

TIA
B.

Walter Roberson

2007-06-09, 1:28 am

In article <1181343568.380112.146240@j4g2000prf.googlegroups.com>,
SpreadTooThin <bjobrien62@gmail.com> wrote:
>On Mac OS X, in C++
>I want to get the hardware mac address of the machine... (First device
>if more than one.)


What does it mean for a particular device to be "first" ?
If I have a built in ethernet, and a built in wireless and
a firewall connection and a series of USB devices some of which happen
to have MACs, then which is the -first-? Especially when it comes
to the USB devices: they are likely to be on a different list
than the built-in ethernet varieties, so "first" would depend on
where you looked first.

Does it matter for your purpose whether the "first" mac is associated
with a device which is active? (If not, then you're probably trying to
use the Mac as a machine serial number, which has various associated
problems.) Does it matter for your purpose whether the "first" mac
is associated with a removable (and likely to be removed) device?
sail0r

2007-06-09, 1:28 am

SpreadTooThin wrote:
> On Mac OS X, in C++
> I want to get the hardware mac address of the machine... (First device
> if more than one.)
>
> I've seen example that do a pipe ifcongif and grep for the mac
> address... but surely there is a direct api to get the mac address.
>
> TIA
> B.

The short answer is to get the MAC address from the I/O Registry.
If you go to this link you can download a zip file which contains
an example showing the correct system calls to make.
http://developer.apple.com/sampleco...ress/index.html
SpreadTooThin

2007-06-14, 7:22 pm

On Jun 8, 6:33 pm, sail0r <sai...@creepjoint.net> wrote:
> SpreadTooThin wrote:
>
>
>
> The short answer is to get the MAC address from the I/O Registry.
> If you go to this link you can download a zip file which contains
> an example showing the correct system calls to make.http://developer.apple.com/sampleco...ress/index.html


Isn't there a more 'generic' unix method? This seems really apple
specific...
Like can I send a udp packet to myself or something.....

Jonny Zuhälter

2007-06-14, 7:22 pm

On Jun 14, 5:04 pm, SpreadTooThin <bjobrie...@gmail.com> wrote:
> On Jun 8, 6:33 pm, sail0r <sai...@creepjoint.net> wrote:
>
>
>
>
>
> Isn't there a more 'generic' unix method? This seems really apple
> specific...
> Like can I send a udp packet to myself or something.....


I remember from my old C++ class, an identifier called UUID that
provides classes for MAC functions. Google UUID and Linux and there
should be some examples. Theres gotta be a man page out there too.

SpreadTooThin

2007-06-15, 1:21 am

On Jun 14, 3:17 pm, Jonny Zuh=E4lter <zuhal...@gmail.com> wrote:
> On Jun 14, 5:04 pm, SpreadTooThin <bjobrie...@gmail.com> wrote:
>
>
>
>
>
>
ice[vbcol=seagreen]
>
>
>
apple.com/samplecode/GetPrimaryMACAddress/index.html[vbcol=seagreen]
>
>
> I remember from my old C++ class, an identifier called UUID that
> provides classes for MAC functions. Google UUID and Linux and there
> should be some examples. Theres gotta be a man page out there too.- Hide =

quoted text -
>
> - Show quoted text -


Guess what?! It is a UUID that I'm trying to produce!
I believe there is a program called uuidgen but my google searches for
uuidgen.c don't seem to be pointing me to the code..
Anyone got a pointer to the source?

TIA.
B=2E

PerfectReign

2007-06-15, 1:21 am

On Thu, 14 Jun 2007 19:11:55 -0700, SpreadTooThin wrote:

> On Jun 14, 3:17 pm, Jonny Zuhälter <zuhal...@gmail.com> wrote:
index.html[vbcol=seagreen]
>
> Guess what?! It is a UUID that I'm trying to produce! I believe there
> is a program called uuidgen but my google searches for uuidgen.c don't
> seem to be pointing me to the code.. Anyone got a pointer to the source?


Geez! It is easy to get a Mac Address. You just go to Rev's house, and
look at his door. I'm sure the address is right there.

Sigh...


--
k
www.perfectreign.com

making the impossible happen
ahead of schedule
Rev Turd Fredericks

2007-06-15, 1:21 am

PerfectReign wrote:
> On Thu, 14 Jun 2007 19:11:55 -0700, SpreadTooThin wrote:
>
> index.html
>
> Geez! It is easy to get a Mac Address. You just go to Rev's house, and
> look at his door. I'm sure the address is right there.
>
> Sigh...
>
>

Heh. Probably half the computers in my neighborhood are Macs so how
would he know it's me :-)

--
I got a fever and the only prescription is more cowbell!
-Christopher Walken SNL ð
sail0r@creepjoint.net

2007-06-15, 7:27 pm

SpreadTooThin wrote:
> On Jun 8, 6:33 pm, sail0r <sai...@creepjoint.net> wrote:
>
> Isn't there a more 'generic' unix method? This seems really apple
> specific...

re-read you original post!
You specifically mentioned Mac OS X!!
*rage burns deep inside*
> Like can I send a udp packet to myself or something.....

Yeah, you probably can...
Then again, I think you need to be WAY MORE XXXXING CLEAR IN YOUR POSTS.
The only reason I am helping you at all is that I am bored as all hell.
Be grateful I hate my job. ;)
Anyway, and you better be real XXXXing thankful for this,
go to this link and you should be all set.
http://forum.java.sun.com/thread.js...4804&tstart=195


John Maline

2007-06-15, 7:27 pm

SpreadTooThin wrote:
> On Jun 8, 6:33 pm, sail0r <sai...@creepjoint.net> wrote:
>
> Isn't there a more 'generic' unix method? This seems really apple
> specific...
> Like can I send a udp packet to myself or something.....


Google siocgifconf. It's the socket ioctl() that'll return a big buffer
that you pick through. It'll give you info on interfaces (IP address
and IP properties) and links (MAC addresses and so on). The interface
is complex enough that it'd be worthwhile to search around for some
example code.

The output of "netstat -in" maps pretty closely to what you'll get from
that programmatically. I think that includes the link info - not at my
mac now.

Here's an interesting search result. The 1993 date on this man page
worries me, but the basics look right. Way old versions didn't return
link information, just interfaces.
http://developer.apple.com/DOCUMENT...netintro.4.html

Good luck,
John
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com