find host IP address

This is a discussion on find host IP address within the Symbian forums in Other Technologies category; Hi [~mach], The reason why it may not work on the emulator (I'mpretty sure its THE reas= on) is the emulator isn't using the whole of Symbian OS networking stack fo= r connectivity (what it basically does it uses the host OS networking stack= , in this case Winsock). The upside, getting emulator connectivity is prett= y easy. The downside as you've already come across, not all Symbian OS spec= ific networking stack support is present! As for getting locally administered address (169...) I'mnot sure if that's = happening becasue you are querying the interface even before its actually b= ...

Go Back   Application Development Forum > Other Technologies > Symbian

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 05-26-2008, 11:54 AM
maxpayne
Guest
 
Default Re: find host IP address

Hi [~mach],

The reason why it may not work on the emulator (I'mpretty sure its THE reas=
on) is the emulator isn't using the whole of Symbian OS networking stack fo=
r connectivity (what it basically does it uses the host OS networking stack=
, in this case Winsock). The upside, getting emulator connectivity is prett=
y easy. The downside as you've already come across, not all Symbian OS spec=
ific networking stack support is present!

As for getting locally administered address (169...) I'mnot sure if that's =
happening becasue you are querying the interface even before its actually b=
een assigned a 'proper' IP address by DHCP! I'll have to take a look at thi=
s later when I come back from vacation :-)

Hope that helps.
Reply With Quote
  #2  
Old 05-26-2008, 12:24 PM
mach
Guest
 
Default find host IP address

I have an application for a socket server. I use the following to find
out what the local IP adddress is (to later make a call to bind to this
same address).=20

=20

bq. =09RSocket sock; \\=09 sock.Open(iSocketServ, KAfInet, KSockStream, KPr=
otocolInetTcp); \\=09 iConnection.Open(iSocketServ)); \\=09 iConnection.Get=
IntSetting(_L("IAP\\=09Id"), iapId)); \\=09 TSoInetInterfaceInfo ifinfo; \\=
=09 TPckg<TSoInetInterfaceInfo> ifinfopkg(ifinfo); \\=09 TSoInetIfQue=
ry ifquery; \\=09 TPckg<TSoInetIfQuery> ifquerypkg(ifquery); \\=09 so=
ck.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
bq. while(sock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) =3D=
=3D KErrNone)bq. =09=09 ifquery.iName =3D ifinfo.iName; \\
bq. =09=09 sock.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg); =
\\
bq. if(ifquery.iZone[1] =3D=3D iapId)bq. if(ifinfo.iAddress.Address() > =
0)bq. =09=09=09=09aAddr =3D ifinfo.iAddress; \\


bq. bq. bq. =09=09=09=09 sock.Close(); \\


bq. bq. bq. return KErrNone;



bq. bq. bq. }


bq. bq. }

bq. }
bq. sock.Close();


On an emulator (S60_3rd_FP1_3), the above does not work. It goes twice
through the loop, but the IAP-IDs and addresses it finds are always
equal to 0. Why is this?
On the mobile phone it returns an IP address of the form 169.x.x.x,
which normally means that the adddress is non-valid (however, from
another phone or the emulator I can actually connect to the socket
using this IP address).=20

On the other hand, the following code *does* find the local IP address on t=
he emulator:=20



bq. =09// Get info about local IP address \\=09 RHostResolver hostResolver;=
\\=09 hostResolver.Open(iSocketServ, KAfInet, KProtocolInetTcp, iConnectio=
n); \\=09 TBuf<255> hostName; \\=09 hostResolver.GetHostName(hostName=
); \\=09 TNameEntry nameEntry; \\=09 hostResolver.GetByName(hostName, nameE=
ntry); \\=09 TNameRecord nameRec =3D nameEntry(); \\=09 TSockAddr sockAddr =
=3D nameRec.iAddr;
bq. GetInetAddressL(sockAddr, aInetAddr);
Now, both on the emulator as on the mobile phone, I get an IP address of th=
e form 192.x.x.x=20

I would like to know why one code works and the other doesn´t, since =
I
have found both types of code on the internet presented as valid
solutions.

Edited by: mach on 26-May-2008 17:23
Reply With Quote
  #3  
Old 05-26-2008, 12:42 PM
mach
Guest
 
Default Re: find host IP address

Thanks for your reply. It at least explains the behaviour of the emulator.=
=20

About the second half of your reply, I am not sure I understand what you me=
an with "querying the interface even before its actually been assigned a 'p=
roper' IP address by DHCP". I make the query after opening and starting the=
iConnection.=20
(In my previous mail I didn´t do the copy and paste correctly. The iC=
onnection.Start was missing).=20
I am relatively new with sockets. What do you mean with locally administere=
d address (169...)?

By the way, I do apologize for the format of my mails (especially the code =
part). Somehow I don´t manage to get the code nicely outlined into th=
e posts.=20



bq. User::LeaveIfError(iConnection.Open(iSocketServ)); \\ User::LeaveIfErro=
r(iConnection.Start(prefs)); \\ GetLocalIPAddressL(inetAddr); \\ User::Leav=
eIfError(sock.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp)); \=
\ User::LeaveIfError(iConnection.GetIntSetting(_L("I AP\\Id"), iapId)); \\ c=
onsole->Printf(_L("iConnection, IAP ID =3D %d \n"), iapId); \\ TSoInetIn=
terfaceInfo ifinfo; \\ TPckg<TSoInetInterfaceInfo> ifinfopkg(ifinfo);=
\\ TSoInetIfQuery ifquery; \\ TPckg<TSoInetIfQuery> ifquerypkg(ifque=
ry); \\ User::LeaveIfError(sock.SetOpt(KSoInetEnumInterfac es, KSolInetIfCtr=
l)); \\ while(sock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) =
=3D=3D KErrNone) \\ ..
Reply With Quote
  #4  
Old 05-29-2008, 09:12 AM
maxpayne
Guest
 
Default Re: find host IP address

Hi [~mach],

Are you using WLAN by any chance? Because it seems that its a specific prob=
lem with the Nokia WLAN interface. For some weired reason, the same WLAN in=
terface is present with a link local address and the actual DHCP assigned a=
ddress. So what happens is when you run the code you posted, you'd actually=
hit ifquery.iZone[1] =3D=3D iapId twice, instead of once, if you don't ter=
minate the loop.


Reply With Quote
  #5  
Old 05-29-2008, 12:30 PM
mach
Guest
 
Default Re: find host IP address

You´re right! That´s what happens. It´s even worse though=
, because the first address is the 169 address, only the second time it&acu=
te;s the DHCP address. Anyway, mystery solved. Thank you very much.
Is there a place where one can report this sort of "bugs"?
Reply With Quote
  #6  
Old 05-29-2008, 12:59 PM
maxpayne
Guest
 
Default Re: find host IP address

Hi [~mach],
> Is there a place where one can report this sort of "bugs"?

http://www.forum.nokia.com/main/feedback/index.html

Hope that helps.








Reply With Quote
  #7  
Old 05-30-2008, 03:18 AM
Markku Savela
Guest
 
Default Re: find host IP address

mach wrote:
> You´re right! That´s what happens. It´s even worse though,because the first
> address is the 169 address, only the second time it´s the DHCP address. Anyway,
> mystery solved. Thank you very much. Is there a place where one can report this
> sort of "bugs"?


What bug? Interfaces can have multiple addresses. Assigned addresses can
come and go, some addresses are available sooner than others.

Normally, you don't need to care what the local address is. Just listen
to a port without specifying local address (SetLocalPort).

If you need to communicate an address to an outside entity, *then* you
need to know about different types of addresses (link local, private or
global). Depending on your application an needs, some of those address
classes may not be suitable.
Reply With Quote
  #8  
Old 05-30-2008, 06:20 AM
maxpayne
Guest
 
Default Re: find host IP address

Hi [Markku,|https://mail.google.com/mail?view=3D...D1&to=3DMarkk=
u.Savela@vtt.fi]

Using SetLocalPort was exactly what I recommended anyway elsewhere. It woul=
d be interesting to see what LocalName would return for the socket in quest=
ion.

Cheers.
Reply With Quote
  #9  
Old 05-30-2008, 06:32 AM
Markku Savela
Guest
 
Default Re: find host IP address

maxpayne wrote:
> Hi
> [Markku,|https://mail.google.com/mail?view=cm...Savela@vtt.fi]
> Using SetLocalPort was exactly what I recommended anyway elsewhere. It would be
> interesting to see what LocalName would return for the socket in question.. Cheers.


*After* the socket is connected (or first packet has been sent via UDP),
the LocalName() returns address that is appropriate for the connection
depending on the address of the other end. The stack selects appropriate
source address automaticly.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:11 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.