473,378 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 9237
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
1
by: Steve Guidos | last post by:
We are writing a set of Windows Services using C#.NET that will run on the same server. One of the developers here said that we should assign each service its own Base Address using the Properties...
10
by: Raffi | last post by:
Hi, I'm looking for a way using JavaScript to determine if the browser window has an address bar. Thanks, Raffi
24
by: Daniel Crespo | last post by:
Hi, I tried: import ctypes import socket import struct def get_macaddress(host): """ Returns the MAC address of a network host, requires >= WIN2K. """
0
by: comp.lang.php | last post by:
I wrote a method that should check if an email address is valid. In another method I've already checked to see if $_POST exists and is well-formed, so those checks are not necessary in this scope....
12
by: greg_chu | last post by:
Hi, I know I can use ipconfig.exe is DOS to get my IP address, the situation is I need to automat this process. I need to write a DOS program which issue a command to run IPCONFIG to get the IP...
12
by: lmcleroy | last post by:
I'm new around here so I'm just hoping I'm in the correct place. Today I installed the latest Python for windows (2.5.1) from python.org. That went well but I lost my internet and home network...
13
by: Gilles Ganault | last post by:
Hello I need to get the local computer's IP address, ie. what's displayed when running "ifconfig" in Linux: # ifconfig eth0 Link encap:Ethernet HWaddr 00:15:58:A1:D5:6F inet...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.