Hi guys i want to determine IP address of handset so please tell me
how to get that information in s60 2nd FP3![]()
Hi guys i want to determine IP address of handset so please tell me
how to get that information in s60 2nd FP3![]()
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
Regards,
Pramod Murthy
"Nobody will believe in you unless you believe in yourself."
Whats wrong with this code?Code:// Get the IAP id of the underlying interface of this RConnection TUint32 iapId = 0; iAppUi->ShowNoteL(_L("Inside GetIPAddress")); User::LeaveIfError(iConnection.GetIntSetting(_L("IAP\\Id"), iapId)); // 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. iAppUi->ShowNoteL(_L("Setting SetOpt")); User::LeaveIfError(iSocket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl)); while(iSocket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) == KErrNone) { iAppUi->ShowNoteL(_L("Inside While")); ifquery.iName = ifinfo.iName; TBuf<20> ErrDesc; ErrDesc.Copy(_L("Err : ")); TInt err = iSocket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg); ErrDesc.AppendNum(err); iAppUi->ShowNoteL(ErrDesc); //if(err == KErrNone && ifquery.iZone[1] == iapId) // IAP ID is index 1 of iZone if(err == KErrNone && ifquery.iZone[1] == 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) { // found a IPv4 address aAddr = ifinfo.iAddress; iAppUi->ShowNoteL(_L("Found IP")); //iSocket.Close(); return err; // stop & return KErrNone } } else if(err != KErrNone) { //iSocket.Close(); return err; // return with error } } // while
I am calling this after establishing connection.
it shows Inside GetIPAddress
after that no message displayed
Last edited by ltomuta; 2008-06-17 at 20:38. Reason: Use the [CODE] tags, they're free ;)