javacommons/gcfprotocols/socket/socket/src.s60/socketlocalhostinfo.cpp
changeset 56 abc41079b313
parent 49 35baca0e7a2e
child 83 26b2b12093af
--- a/javacommons/gcfprotocols/socket/socket/src.s60/socketlocalhostinfo.cpp	Fri Jul 09 16:35:45 2010 +0300
+++ b/javacommons/gcfprotocols/socket/socket/src.s60/socketlocalhostinfo.cpp	Fri Jul 23 12:27:20 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;
+}
+