diff -r e5618cc85d74 -r 6c158198356e javacommons/gcfprotocols/socket/socket/src.s60/socketlocalhostinfo.cpp --- a/javacommons/gcfprotocols/socket/socket/src.s60/socketlocalhostinfo.cpp Thu Jul 15 18:31:06 2010 +0300 +++ b/javacommons/gcfprotocols/socket/socket/src.s60/socketlocalhostinfo.cpp Thu Aug 19 09:48:13 2010 +0300 @@ -22,7 +22,24 @@ #include "logger.h" #include "connectionmanager.h" +#define localhost_len 20 int GetlocalIPAdressL(char *localaddr, int aMidletIapId, int aApType); +char* GetlocalHostNameL(); + +char* SocketLocalHostInfo::getLocalHostName() +{ + char* localhostname =NULL; + TRAPD(err,localhostname = GetlocalHostNameL()); + ILOG1(ESOCKET, "err %d ", err); + if (err != KErrNone) + { + localhostname = new char[localhost_len]; + strcpy(localhostname,"localhost"); + return localhostname; + } + else + return localhostname; +} OS_EXPORT int SocketLocalHostInfo::getLocalAddress(int /* aSd */, char *aLocalAddr, int aMidletIapId, int aApType) @@ -190,3 +207,41 @@ } + +char* GetlocalHostNameL() +{ + TUint32 activeIapId = 0; + + TConnectionInfoBuf connectionInfo; + TUint count = 0; + RSocketServ socketServ; + RSocket sock; + RConnection conn; + + User::LeaveIfError(socketServ.Connect()); + User::LeaveIfError(sock.Open(socketServ, KAfInet, KSockStream, + KProtocolInetTcp)); + User::LeaveIfError(conn.Open(socketServ)); + User::LeaveIfError(conn.EnumerateConnections(count)); + + char* localhost = new char[localhost_len]; + + if (count <= 0) + { + strcpy(localhost,"localhost"); + } + else + { + + User::LeaveIfError(conn.GetConnectionInfo(1, connectionInfo)); + activeIapId = connectionInfo().iIapId; + getIPAddressL(activeIapId,localhost); + } + + conn.Close(); + sock.Close(); + socketServ.Close(); + + return localhost; +} +