×
Namespaces

Variants
Actions

Archived:Retrieving WLAN MAC address using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Compatibility
Platform(s): S60 3rd Edition, S60 3rd Edition FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)
Article
Keywords: KSoInetEnumInterfaces
Created: User:Technical writer 2 (November 22, 2006, updated October 3, 2008)
Last edited: hamishwillee (14 Jun 2012)

Overview

Retrieving WLAN MAC address

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)


Alternative method:

The WLAN MAC address can be retrieved using above code only when the phone is connected to WLAN.

WLAN Info API, 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. Using these methods, the MAC address can be retrieved even when WLAN is turned off.

const TUid KPSUidWlan = { 0x101f8ec5 };

const TUint KPSWlanMacAddress = 0x00000001;

const RProperty::TType KPSWlanMacAddressType = RProperty::EByteArray;


Displaying WLAN MAC address in phone idle screen:

The WLAN MAC address can be displayed by entering the following sequence in the idle screen:

*#62209526#  (*#MAC0WLAN#)

This page was last modified on 14 June 2012, at 09:41.
55 page views in the last 30 days.
×