obtaining MAC address? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
jdbrown
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Sep 19, 2006 9:10 pm

obtaining MAC address?

Post by jdbrown » Tue Sep 19, 2006 9:25 pm

Hello all,
I'm new to the wxWidgets scene and have a couple projects I'm starting to work on that I'm attempting to develop for at least linux and windows. One thing I'd like to be able to do is obtain the MAC address inside the program. Is there a straightforward way to go about this? My google searches have primarily turned up platform-dependent solutions such as the windows method "GetAdaptersInfo." I've gone through the documentation a bit, though my experience with wxWidgets is essentially nill so far. Can anyone tell me if the socket library provides this functionality, or if there is another way to go about obtaining the information I'm looking for?

Thanks,
Jeremy Brown

User avatar
doublemax
Moderator
Moderator
Posts: 14281
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Tue Sep 19, 2006 10:40 pm

AFAIK there is no "wxWidgets" way to do that. You will need platform specific code for that.
Use the source, Luke!

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: obtaining MAC address?

Post by upCASE » Wed Sep 20, 2006 7:45 am

Hi!
jdbrown wrote:Can anyone tell me if the socket library provides this functionality, or if there is another way to go about obtaining the information I'm looking for?
I'm afraid doublemax is right. The MAC address is not related to sockets, but to the specific adapters installed in your system. wxWidgets offer no way to obtain these.

I'd suggest that you write a simple function prototype for all platforms, so that you can use it anywhere and implement the platform dependent stuff by using ifdefs for the specific platform.
See here for the "windows"-ways of doing this ( GetAdapteraInfo would be the best IMHO ): http://www.codeguru.com/Cpp/I-N/network ... .php/c5451
Here's a hint how to do it using Linux: http://cplus.kompf.de/artikel/macaddr.html
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

jdbrown
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Sep 19, 2006 9:10 pm

Post by jdbrown » Wed Sep 20, 2006 9:02 pm

That's what I was afraid of. Thanks for the help though!

JB

aaaaaaaaatchoum!
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Aug 10, 2007 10:37 pm

Post by aaaaaaaaatchoum! » Wed Nov 19, 2008 10:56 am

On windows with wxWidgets 2.8.8 i tried the example on the link above, with no success. The keywords are not recognized "IP_ADAPTER_INFO", "AdapterInfo", "GetAdaptersInfo" and so on, even if i include <windows.h>.

Any ideas?

Grrr
Earned some good credits
Earned some good credits
Posts: 126
Joined: Fri Apr 11, 2008 8:48 am
Location: Netherlands

Post by Grrr » Wed Nov 19, 2008 1:15 pm

They are in iphlpapi.h. A quick search through the standard include files usually does the trick ;).

aaaaaaaaatchoum!
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Aug 10, 2007 10:37 pm

Post by aaaaaaaaatchoum! » Thu Nov 20, 2008 2:54 am

Thanks, i searched before posting, but with no success.

vsp
Knows some wx things
Knows some wx things
Posts: 35
Joined: Mon Feb 21, 2005 12:52 pm

Post by vsp » Fri Nov 21, 2008 12:13 pm

Its working fine for me

I have used the code project code directly in windows.

Code: Select all

int main(int argc, char **argv){

    wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");

    wxInitializer initializer;
    if ( !initializer )
    {
        fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");

        return -1;
    }

	GetMACaddress();
	GetMACNetBiosAddress();
	GetMACAdapterAddress();

	return 0;
}
[/code]

Post Reply