javacommons/gcfprotocols/socket/socket/src.s60/socketlocalhostinfo.cpp
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
    20 #include <in_sock.h>
    20 #include <in_sock.h>
    21 #include "socketlocalhostinfo.h"
    21 #include "socketlocalhostinfo.h"
    22 #include "logger.h"
    22 #include "logger.h"
    23 #include "connectionmanager.h"
    23 #include "connectionmanager.h"
    24 
    24 
    25 #define localhost_len   20
       
    26 int GetlocalIPAdressL(char *localaddr, int aMidletIapId, int aApType);
    25 int GetlocalIPAdressL(char *localaddr, int aMidletIapId, int aApType);
    27 char* GetlocalHostNameL();
       
    28 
       
    29 char* SocketLocalHostInfo::getLocalHostName()
       
    30 {
       
    31     char* localhostname =NULL;
       
    32     TRAPD(err,localhostname = GetlocalHostNameL());
       
    33     ILOG1(ESOCKET, "err %d ", err);
       
    34     if (err != KErrNone)
       
    35     {
       
    36         localhostname = new char[localhost_len];
       
    37         strcpy(localhostname,"localhost");
       
    38         return localhostname;
       
    39     }
       
    40     else
       
    41         return localhostname;
       
    42 }
       
    43 
    26 
    44 OS_EXPORT int SocketLocalHostInfo::getLocalAddress(int /* aSd */, char *aLocalAddr,
    27 OS_EXPORT int SocketLocalHostInfo::getLocalAddress(int /* aSd */, char *aLocalAddr,
    45         int aMidletIapId, int aApType)
    28         int aMidletIapId, int aApType)
    46 {
    29 {
    47     TRAPD(err,GetlocalIPAdressL(aLocalAddr,aMidletIapId, aApType););
    30     TRAPD(err,GetlocalIPAdressL(aLocalAddr,aMidletIapId, aApType););
   205 
   188 
   206     return err; // return with KErrNotFound
   189     return err; // return with KErrNotFound
   207 
   190 
   208 
   191 
   209 }
   192 }
   210 
       
   211 char* GetlocalHostNameL()
       
   212 {
       
   213     TUint32 activeIapId = 0;
       
   214 
       
   215     TConnectionInfoBuf connectionInfo;
       
   216     TUint count = 0;
       
   217     RSocketServ socketServ;
       
   218     RSocket sock;
       
   219     RConnection conn;
       
   220 
       
   221     User::LeaveIfError(socketServ.Connect());
       
   222     User::LeaveIfError(sock.Open(socketServ, KAfInet, KSockStream,
       
   223                                  KProtocolInetTcp));
       
   224     User::LeaveIfError(conn.Open(socketServ));
       
   225     User::LeaveIfError(conn.EnumerateConnections(count));
       
   226 
       
   227     char* localhost = new char[localhost_len];
       
   228 
       
   229     if (count <= 0)
       
   230     {
       
   231         strcpy(localhost,"localhost");
       
   232     }
       
   233     else
       
   234     {
       
   235 
       
   236         User::LeaveIfError(conn.GetConnectionInfo(1, connectionInfo));
       
   237         activeIapId = connectionInfo().iIapId;
       
   238         getIPAddressL(activeIapId,localhost);
       
   239     }
       
   240 
       
   241     conn.Close();
       
   242     sock.Close();
       
   243     socketServ.Close();
       
   244 
       
   245     return localhost;
       
   246 }
       
   247