468,457 Members | 1,608 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

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

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

Aug 19 '06 #1
7 8813
ma******@gmail.com 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
}
Aug 19 '06 #2
ma******@gmail.com 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
Aug 19 '06 #3
jmcgill wrote:
ma******@gmail.com 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,
Aug 19 '06 #4
goose wrote:
jmcgill wrote:
>ma******@gmail.com 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.

Aug 19 '06 #5
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 :-)
Aug 19 '06 #6
jmcgill <jm*****@email.arizona.eduwrites:
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) ks***@mib.org <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.
Aug 19 '06 #7
On Fri, 18 Aug 2006 18:54:04 -0700, jmcgill
<jm*****@email.arizona.eduwrote:
>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
Aug 20 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by johny smith | last post: by
1 post views Thread by Steve Guidos | last post: by
24 posts views Thread by Daniel Crespo | last post: by
13 posts views Thread by Gilles Ganault | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.