This page was last modified 11:43, 24 August 2007.
TSS000462 - Retrieving WLAN MAC address
From Forum Nokia Wiki
Subject:
| Retrieving WLAN MAC address
| TSS000462
|
| Platform(s):
| Device(s), SW version(s):
|
| S60 3rd Edition, S60 3rd Edition FP1
|
|
Category:
| Symbian C++
|
Subcategory:
| -
|
Description:
| The following code demonstrates how to list all network interfaces and retrieve the hardware (MAC) address for a WLAN interface, if one is found. //------------------------------------------------------------------------------ #include <in_sock.h> // link against insock.lib, esock.lib // Connect to the socket server RSocketServ socketServ; User::LeaveIfError(socketServ.Connect()); CleanupClosePushL(socketServ); // Open a socket RSocket socket; User::LeaveIfError(socket.Open(socketServ, KAfInet, KSockStream, KProtocolInetTcp)); CleanupClosePushL(socket); // Start enumerating the interfaces TPckgBuf<TSoInetInterfaceInfo> info; socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
TBuf<32> macAddr; while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info) == KErrNone) { if(info().iName.FindF(_L("Wlan")) == KErrNotFound) { continue; }
macAddr.Zero(); for( TUint i = sizeof(SSockAddr) ; i < sizeof(SSockAddr) + 6 ; i++ ) { if(i < (TUint)info().iHwAddr.Length()) { macAddr.AppendFormat(_L("%02X:"), info().iHwAddr[i]); } }
if(macAddr.Length()) // remove trailing ’:’ { macAddr.Delete(macAddr.Length()-1, 1); } } CleanupStack::PopAndDestroy(2); // socket, socketServ
// macAddr now contains the WLAN MAC address, // (empty if no WLAN interface is found)
//------------------------------------------------------------------------------
|
Creation date:
| November 22, 2006
|
Last modified:
| -
|