Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 09:51, 25 January 2008.

如何获取WLAN MAC地址

From Forum Nokia Wiki

  • 开发伙伴平台:

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)
 
    
 
//------------------------------------------------------------------------------
Related Discussions
Thread Thread Starter Forum Replies Last Post
Nokia论坛技术资料Symbian解决方案-中文版 hoolee Symbian 438 Yesterday 04:37
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZwlanQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX