This page was last modified 09:43, 28 May 2008.
LocalDeviceIpAddress
From Forum Nokia Wiki
This Function retrives the LocalIpAddress of the device. Tested on the S60 3rd Edition device Nokia E60.
int GetlocalIPAdressL() { RSocketServ socketServ; TInetAddr aAddr; RSocket sock; TBuf8<20> aIP8; TBuf<20> aIP; User::LeaveIfError(sock.Open(socketServ, KAfInet, KSockStream, KProtocolInetTcp)); // Get the IAP id of the underlying interface of this RConnection //TUint32 iapId = 0; //User::LeaveIfError(conn.GetIntSetting(_L("IAP\\Id"), iapId)); // Get IP information from the socket TSoInetInterfaceInfo ifInfo; TPckg<TSoInetInterfaceInfo> ifInfoPkg(ifInfo); TSoInetIfQuery ifQuery; TPckg<TSoInetIfQuery> ifQueryPkg(ifQuery); // To find out which interfaces are using our current IAP, we must // enumerate and go through all of them and make a query by name for each. User::LeaveIfError(sock.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl)); while(sock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifInfoPkg) == KErrNone) { ifQuery.iName = ifInfo.iName; TInt err = sock.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifQueryPkg); if( err == KErrNone && ifQuery.iZone[1] == g_iapId) { // IAP ID is index 1 of iZone // We have found an interface using the IAP we are interested in. //if( ifinfo.iAddress.Address() >0 ) if (!ifInfo.iAddress.IsUnspecified() && !ifInfo.iAddress.IsLoopback() && !ifInfo.iAddress.IsLinkLocal()) { // found a IPv4 address aAddr = ifInfo.iAddress; aAddr.ConvertToV4(); aAddr.Output(aIP); aIP8.Copy(aIP); strncpy(out,(char*)aIP8.Ptr(),aIP8.Length()); sock.Close(); return err; // stop & return KErrNone } } else if( err !=KErrNone ) { sock.Close(); return err; // return with error } } // while sock.Close(); return KErrNotFound; // return with KErrNotFound }
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Socket Connection over 3G | primal | Symbian Networking & Messaging | 2 | 2008-03-26 09:36 |
| Local IP address (emulator/mobile phone) | machiel | Wired and Wireless interfaces | 1 | 2008-05-26 18:57 |
| 求助:S60 3rd版本上获取的IPV6的地址,比如::1,如果将其转转化为IPV4的地址呢? | sslaoyao | Symbian | 3 | 2007-04-26 03:46 |
