Professional Web Applications Themes

How to retrieve MAC address - Mac Programming

I need to know how to get MAC addresses from interfaces using C/C++ and not Carbon. I've tried using ioctl but no address is returned. Using SIOCGIFHWADDR works on Linux and Solaris does not on Mac (OS X 10.3). It (SIOCGIFHWADDR ) does not even exist on Mac. Is there an equivalent or another way to get the address? Thanks, Marc...

  1. #1

    Default How to retrieve MAC address

    I need to know how to get MAC addresses from interfaces using C/C++ and not
    Carbon. I've tried using ioctl but no address is returned. Using
    SIOCGIFHWADDR works on Linux and Solaris does not on Mac (OS X 10.3). It
    (SIOCGIFHWADDR ) does not even exist on Mac. Is there an equivalent or
    another way to get the address?

    Thanks,
    Marc




    Marc Guest

  2. #2

    Default Re: How to retrieve MAC address

    In article <ca>,
    "Marc Vachon" <com> wrote:
     

    1. There is no 'the MAC address'. Many Macintoshes have more than one.
    2. You need to use IOKitLib. see

    <http://developer.apple.com/samplecode/Sample_Code/Networking/GetMACAddre
    ssSample.htm>

    Reinder
    Reinder Guest

  3. #3

    Default Re: How to retrieve MAC address

    Reinder Verlinde <invalid> wrote in message news:<wxs.nl>... 
    >
    > 1. There is no 'the MAC address'. Many Macintoshes have more than one.
    > 2. You need to use IOKitLib. see
    >
    > <http://developer.apple.com/samplecode/Sample_Code/Networking/GetMACAddre
    > ssSample.htm>
    >
    > Reinder[/ref]

    Or in a totally resource intensive way...

    fflush(stdin);
    fp = popen("/sbin/ifconfig | grep \"ether\"","r");
    if( fp != NULL )
    {
    if( fgets(in,256,fp) != NULL )
    {
    sscanf(in,"%*s %s ",mac);

    // MAC Address
    printf(out,"MAC_ADDR=%s",mac);
    }

    pclose(fp);
    }

    --jim
    Jim Guest

  4. #4

    Default Re: How to retrieve MAC address

    In article <google.com>,
    net (Jim Schimpf) wrote:
     
    > >
    > > 1. There is no 'the MAC address'. Many Macintoshes have more than one.
    > > 2. You need to use IOKitLib. see
    > >
    > > <http://developer.apple.com/samplecode/Sample_Code/Networking/GetMACAddre
    > > ssSample.htm>
    > >
    > > Reinder[/ref]
    >
    > Or in a totally resource intensive way...
    >
    > fflush(stdin);
    > fp = popen("/sbin/ifconfig | grep \"ether\"","r");
    > if( fp != NULL )
    > {
    > if( fgets(in,256,fp) != NULL )
    > {
    > sscanf(in,"%*s %s ",mac);
    >
    > // MAC Address
    > printf(out,"MAC_ADDR=%s",mac);
    > }
    >
    > pclose(fp);
    > }[/ref]

    *Please* don't do that. Really. Not only is it horrifically slow, it's
    not at all guaranteed to return the answer you want.

    -Eric

    --
    Eric Albert stanford.edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

  5. #5

    Default Re: How to retrieve MAC address

    "Marc Vachon" <com> wrote in message news:<ca>... 

    I used Open Transport. I guess that would only be advantageous though
    if you needed code that worked both in OS 9 and OS X. Let me know if
    you're interested, and I can give you more details.

    Kaydell
    Kaydell Guest

  6. #6

    Default Re: How to retrieve MAC address


    Jim Schimpf wrote in message
    http://groups.google.com/groups?selm=5d6ed6b4.0401171515.5f534f02%40posting .google.com
     
    > >
    > > 1. There is no 'the MAC address'. Many Macintoshes have more than one.
    > > 2. You need to use IOKitLib. see
    > >
    > > <http://developer.apple.com/samplecode/Sample_Code/Networking/GetMACAddre
    > > ssSample.htm>
    > >
    > > Reinder[/ref]
    >
    > Or in a totally resource intensive way...
    >
    > fflush(stdin);
    > fp = popen("/sbin/ifconfig | grep \"ether\"","r");
    > if( fp != NULL )
    > {
    > if( fgets(in,256,fp) != NULL )
    > {
    > sscanf(in,"%*s %s ",mac);
    >
    > // MAC Address
    > printf(out,"MAC_ADDR=%s",mac);
    > }
    >
    > pclose(fp);
    > }
    >
    > --jim[/ref]

    See programs for getting info about network interfaces within C++-program on Windows 2000 at
    http://alexvn.freeservers.com/s1/getmac.html


    --
    Alex Vinokur
    http://mathforum.org/library/view/10978.html
    http://sourceforge.net/users/alexvn








    Alex Guest

Similar Threads

  1. Retrieve e-mail address from Active Directory
    By mg in forum ASP.NET Security
    Replies: 0
    Last Post: February 5th, 09:31 PM
  2. Attach IP address to MAC address in Airport Extreme
    By Gnarlodious in forum Mac Networking
    Replies: 6
    Last Post: January 23rd, 05:34 AM
  3. Replies: 1
    Last Post: August 10th, 05:33 PM
  4. copy billing address to delivery address fields
    By khinester in forum Microsoft Access
    Replies: 4
    Last Post: August 4th, 09:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139