×
Namespaces

Variants
Actions

如何获取WLAN MAC地址

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
huwell 在 25 Jan 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑
  • 开发伙伴平台:

S60 3rd Edition, S60 3rd Edition FP1


  • 详细描述

下列代码演示了如何列出所有的网络接口,并获得一个WLAN接口的硬件(MAC)地址:

//------------------------------------------------------------------------------
 
#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)
 
 
 
//------------------------------------------------------------------------------
This page was last modified on 15 December 2011, at 09:44.
151 page views in the last 30 days.
×