Categories: S60 | Symbian C++ | Connectivity | WLAN | How To | Code Examples
This page was last modified 16:47, 23 June 2008.
How to get MAC address of a WLAN device
From Forum Nokia Wiki
The MAC address of a WLAN device can be retrieved by the code *#MAC0WLAN# on the standby screen (that's same as *#62209526#).
We can get the MAC address of a S60 WLAN device programmatically as well. This can be done by the following code snippet.
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]);
CEikonEnv::InfoWinL(_L("MAC address"),macAddr);
}
}
if(macAddr.Length()) // remove trailing ':'
{
macAddr.Delete(macAddr.Length()-1, 1);
}
}
CleanupStack::PopAndDestroy(2);
However, the above MAC address retrieval code works only when your phone is connected to a WLAN. To find out the MAC address even with WLAN turned off, see the below alternative solution (applies to all S60 3rd Edition devices and S60 3rd Edition Feature Pack 1 devices):
This alternatively method uses the Publish & Subscribe keys to retrieve the MAC address when the WLAN is turned off.
WLAN Info API, a part of the Extensions plug-in package for S60 3rd Edition, Feature Pack 1 SDK, contains Publish & Subscribe keys with a MAC address for the WLAN interface.
The wlaninternalpskeys.h header file contains the required Publish & Subscribe category and key information:
const TUid KPSUidWlan = { 0x101f8ec5 }; const TUint KPSWlanMacAddress = 0x00000001; const RProperty::TType KPSWlanMacAddressType = RProperty::EByteArray;
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can I get the BT address after listen for connection from a remote device | terry11 | Bluetooth Technology | 2 | 2004-07-27 07:28 |
| WLAN connection in offline mode | Dipakbaviskar | Symbian Networking & Messaging | 5 | 2007-08-09 05:49 |
| accessing localhost without wlan connection | kabuff | General Discussion | 0 | 2006-10-26 02:07 |
| Help with WLAN, Snapshot and File Read Access | tempdisj | Mobile Java General | 8 | 2007-01-18 06:08 |
| how could I find a unique code ? | jason_rency | General Discussion | 0 | 2004-03-29 15:51 |
