How do I get the mac address/es in C for Windows XP?

Discussion in 'C Programming' started by marccruz@gmail.com, Aug 19, 2006.

  1. Guest

    Is there an API where I can get the mac address/es of a computer using
    C for Windows XP?
    , Aug 19, 2006
    #1
    1. Advertising

  2. jmcgill Guest

    wrote:
    > Is there an API where I can get the mac address/es of a computer using
    > C for Windows XP?
    >


    Before you get flamed for asking a not-strictly-on-topic question,
    ponder this (from an old MSDN source). I'm a Unix systems programmer
    that rarely touches windows, so you get the usual money back guarantee
    on this:

    // Fetches the MAC addresses and prints them
    static void GetMACaddress(void)
    {
    IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information
    // for up to 16 NICs
    DWORD dwBufLen = sizeof(AdapterInfo); // Save memory size of buffer

    DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo
    AdapterInfo, // [out] buffer to receive data
    &dwBufLen); // [in] size of receive data buffer
    assert(dwStatus == ERROR_SUCCESS); // Verify return value is
    // valid, no buffer overflow

    PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
    // current adapter info
    do {
    PrintMACaddress(pAdapterInfo->Address); // Print MAC address
    pAdapterInfo = pAdapterInfo->Next; // Progress through
    // linked list
    }
    while(pAdapterInfo); // Terminate if last adapter
    }
    jmcgill, Aug 19, 2006
    #2
    1. Advertising

  3. jmcgill Guest

    jmcgill, Aug 19, 2006
    #3
  4. jmcgill Guest

    goose wrote:
    > jmcgill wrote:
    >> wrote:
    >>
    >>> Is there an API where I can get the mac address/es of a computer using
    >>> C for Windows XP?
    >>>

    >>
    >> Before you get flamed for asking a not-strictly-on-topic question,

    >
    > You mean that you'd rather get flamed instead of OP? How odd.


    Sure, no problem. I honestly want to help, and I have very thick
    asbestos and kevlar skin.
    jmcgill, Aug 19, 2006
    #4
  5. goose Guest

    jmcgill wrote:
    > wrote:
    >
    >> Is there an API where I can get the mac address/es of a computer using
    >> C for Windows XP?
    >>

    >
    > Before you get flamed for asking a not-strictly-on-topic question,


    You mean that you'd rather get flamed instead of OP? How odd.

    > ponder this (from an old MSDN source). I'm a Unix systems programmer
    > that rarely touches windows, so you get the usual money back guarantee
    > on this:
    >
    > // Fetches the MAC addresses and prints them
    > static void GetMACaddress(void)
    > {
    > IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information


    IP_ADAPTER_INFO is not a known type.

    > // for up to 16 NICs
    > DWORD dwBufLen = sizeof(AdapterInfo); // Save memory size of buffer


    instead of that use
    sizeof AdapterInfo[0];
    >
    > DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo


    DWORD? Whats that?
    > AdapterInfo, // [out] buffer to receive data
    > &dwBufLen); // [in] size of receive data buffer
    > assert(dwStatus == ERROR_SUCCESS); // Verify return value is
    > // valid, no buffer overflow
    >
    > PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to


    PIP_ADAPTER_INFO also not know at this point.
    > // current adapter info
    > do {
    > PrintMACaddress(pAdapterInfo->Address); // Print MAC address


    'nother unknown function.
    > pAdapterInfo = pAdapterInfo->Next; // Progress through
    > // linked list
    > }
    > while(pAdapterInfo); // Terminate if last adapter
    > }


    Sadly, even if there was a trivial error in the above
    code, I would not ahve picked it up, as I am not a windows
    developer (for example, I cannot understand why an array
    is needed if the data is stored in a linked list).

    That is a good reason to send the people asking platform
    specific questions to the proper newsgroup, where experts
    will attend to their questions. Answering badly here serves
    two purposes:
    1. The answer is not going to be verified as a good answer.
    2. The newsgroup starts attracting so many platform questions
    that the signal/noise ratio is going to put off people with
    legitimate questions.

    So, I urge you to direct the poster to the appropriate
    newsgroup: clc is not the newsgroup for this question.

    regards
    goose,
    goose, Aug 19, 2006
    #5
  6. jmcgill Guest

    goose wrote:

    > IP_ADAPTER_INFO is not a known type.
    > DWORD? Whats that?
    > PIP_ADAPTER_INFO also not know at this point.


    #include <windows.h>
    #include <winsock2.h>
    #include <stdio.h>
    #include <iphlpapi.h>


    I'll try to refrain from answering any more windows programming
    questions from now on. Just trying to help. Sheesh :)
    jmcgill, Aug 19, 2006
    #6
  7. jmcgill <> writes:
    > goose wrote:
    >
    >> IP_ADAPTER_INFO is not a known type.
    > > DWORD? Whats that?
    > > PIP_ADAPTER_INFO also not know at this point.

    >
    > #include <windows.h>
    > #include <winsock2.h>
    > #include <stdio.h>
    > #include <iphlpapi.h>
    >
    >
    > I'll try to refrain from answering any more windows programming
    > questions from now on. Just trying to help. Sheesh :)


    Thank you. I know you're trying to help, and I can certainly
    understand the temptation, but really, the best help you can offer is
    to redirect the questioner to some newsgroup that's full of actual
    experts on the topic. (You may be an expert on this yourself, but
    most of the rest of us aren't.)

    Think about it. Suppose someone posted something like this to a
    Windows programming group:

    I need to allocate a 3-dimensional array in my C program, with the
    length of each dimension determined at run time. What's the best
    way to do this? (I'm programming in Windows, but I'd like the
    code to be portable to other systems.)

    Which would be more helpful, answering the question yourself in the
    Windows group, or telling the poster about this other newsgroup that's
    chock full of C geeks who will fall over themselves to give the best
    possible advice for a portable solution?

    (Or you could just point to question 6.16 of the comp.lang.c FAQ, but
    let's pretend that it's something the FAQ doesn't address.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Aug 19, 2006
    #7
  8. Al Balmer Guest

    On Fri, 18 Aug 2006 18:54:04 -0700, jmcgill
    <> wrote:

    >I'll try to refrain from answering any more windows programming
    >questions from now on. Just trying to help. Sheesh :)


    The best help you can give is directing the OP to a newsgroup where he
    can get the *correct* information, vetted by other readers who know
    the subject.

    What you did was not "help."

    --
    Al Balmer
    Sun City, AZ
    Al Balmer, Aug 20, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron

    Get MAC Address

    Aaron, May 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,018
    Aaron
    May 18, 2004
  2. SJ

    MAC Address/Physical Address?

    SJ, Jan 7, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    524
  3. Phil Hanna
    Replies:
    6
    Views:
    30,004
    Roedy Green
    Jul 5, 2003
  4. olivier Ravard

    How to get my MAC address with python ?

    olivier Ravard, Feb 2, 2004, in forum: Python
    Replies:
    4
    Views:
    16,767
    Josiah Carlson
    Feb 2, 2004
  5. Tim Golden
    Replies:
    0
    Views:
    460
    Tim Golden
    Feb 2, 2004
Loading...

Share This Page