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 |
25 int GetlocalIPAdressL(char *localaddr, int aMidletIapId, int aApType); |
26 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 } |
26 |
43 |
27 OS_EXPORT int SocketLocalHostInfo::getLocalAddress(int /* aSd */, char *aLocalAddr, |
44 OS_EXPORT int SocketLocalHostInfo::getLocalAddress(int /* aSd */, char *aLocalAddr, |
28 int aMidletIapId, int aApType) |
45 int aMidletIapId, int aApType) |
29 { |
46 { |
30 TRAPD(err,GetlocalIPAdressL(aLocalAddr,aMidletIapId, aApType);); |
47 TRAPD(err,GetlocalIPAdressL(aLocalAddr,aMidletIapId, aApType);); |
188 |
205 |
189 return err; // return with KErrNotFound |
206 return err; // return with KErrNotFound |
190 |
207 |
191 |
208 |
192 } |
209 } |
|
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 |