Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How do I get the mac address/es in C for Windows XP?

Reply
Thread Tools

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

 
 
marccruz@gmail.com
Guest
Posts: n/a
 
      08-19-2006
Is there an API where I can get the mac address/es of a computer using
C for Windows XP?

 
Reply With Quote
 
 
 
 
jmcgill
Guest
Posts: n/a
 
      08-19-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
}
 
Reply With Quote
 
 
 
 
jmcgill
Guest
Posts: n/a
 
      08-19-2006
(E-Mail Removed) wrote:
> Is there an API where I can get the mac address/es of a computer using
> C for Windows XP?
>


This is a more contemporary, and I expect, canonical method:

http://support.microsoft.com/default...b;en-us;118623
 
Reply With Quote
 
jmcgill
Guest
Posts: n/a
 
      08-19-2006
goose wrote:
> jmcgill wrote:
>> (E-Mail Removed) 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.

 
Reply With Quote
 
goose
Guest
Posts: n/a
 
      08-19-2006
jmcgill wrote:
> (E-Mail Removed) 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,
 
Reply With Quote
 
jmcgill
Guest
Posts: n/a
 
      08-19-2006
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
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-19-2006
jmcgill <(E-Mail Removed)> 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) (E-Mail Removed) <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.
 
Reply With Quote
 
Al Balmer
Guest
Posts: n/a
 
      08-20-2006
On Fri, 18 Aug 2006 18:54:04 -0700, jmcgill
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to triple-boot Mac OS X, Linux, and Windows XP on an Apple Mac Au79 Computer Support 0 06-21-2006 05:58 PM
How do you get or save a file from/to a client (button on web page) once they are authenticated? The client could be Mac, Linux or Windows. jake ASP .Net 6 07-07-2004 07:48 PM



Advertisments