View Issue Details

IDProjectCategoryView StatusLast Update
0014661Lazarus CCR-public2009-09-23 23:19
ReporterBartOAssigned ToAles Katona 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
Summary0014661: Machine IP Address not the loop back address.
DescriptionI am using Lazarus 0.9.26.2. I need to be able to display the machine IP address or local IP Address. I looked around in the internet for solution and there seem to be none.

Here is the code I have tried using tools from INet Paelete- TLTCPComponent.

Following code gets me the local Loop Back or LocalHost IP address, but not the machine IP address.

FNetServer.Connect;
FNetServer.IterReset;
IPLabel.Caption:=FNetServer.Iterator.localaddress;
FNetServer.Disconnect;

What am I doing wrong or am I missing anything?

Any help will be appreciated. Thanks,
TagsNo tags attached.
WidgetsetGTK, GTK 2, Win32/Win64
Attached Files

Activities

Ales Katona

2009-09-23 21:06

developer   ~0030943

What are you connecting to? You can't expect to get the public interface IP address by connecting to localhost. If you connect to an external server (no matter the high level protocol) you can use TCP.Iterator.LocalAddress to get your external interface IP.

NOTE: the iterator must be valid, don't try this unconnected (iterator = nil then).

Ales Katona

2009-09-23 21:07

developer   ~0030944

If you connect to an external server (no matter the high level protocol) you can use TCP.Iterator.LocalAddress to get your external interface IP.

NOTE: the iterator must be valid, don't try this unconnected (iterator = nil then).

BartO

2009-09-23 22:12

reporter   ~0030946

Well, I do connect but it is not connected to anything as for as the external machines go. I need to be able to retrieve local TCP/IP address not the loop back.

Ales Katona

2009-09-23 22:47

developer   ~0030948

This isn't possible without connecting via an interface. The sockets API is interface-less (e.g: if you connect outside, the program doesn't care if it's via eth0 or some wireless interface) and as such can't provide such functionality. It's probably possible to figure out IPs for specific interfaces via concrete system calls.

BartO

2009-09-23 22:58

reporter   ~0030949

So, you actually have to connect a remote pc to retrieve your local TCP/IP address. That doesn't make sense. On Windows, you call gethostname and gethostbyname to retrieve TCP/IP address.

Yes, you are right about API calls. But what API calls? I am somewhat new to Lazarus. I even tried the sample C programs on the internet - compiled them and ran it on the terminal. It only returns the loop back IP address (127.0.0.1), but it was supposed to return machine TCP/IP address.

Could you give me some hints or the API calls?

Ales Katona

2009-09-23 23:19

developer   ~0030950

Not sure. There should be a way to get a list of available network interfaces (ala ifconfig) from the OS and then get specific info on each one. I never needed this tho, so I don't know.

Issue History

Date Modified Username Field Change
2009-09-23 20:25 BartO New Issue
2009-09-23 20:25 BartO Widgetset => GTK, GTK 2, Win32/Win64
2009-09-23 20:46 Vincent Snijders Project Lazarus => Lazarus CCR
2009-09-23 20:47 Vincent Snijders Assigned To => Ales Katona
2009-09-23 20:47 Vincent Snijders Status new => assigned
2009-09-23 20:47 Vincent Snijders Category LCL => -
2009-09-23 21:06 Ales Katona Note Added: 0030943
2009-09-23 21:07 Ales Katona Status assigned => resolved
2009-09-23 21:07 Ales Katona Resolution open => no change required
2009-09-23 21:07 Ales Katona Note Added: 0030944
2009-09-23 22:12 BartO Status resolved => feedback
2009-09-23 22:12 BartO Resolution no change required => reopened
2009-09-23 22:12 BartO Note Added: 0030946
2009-09-23 22:47 Ales Katona Status feedback => resolved
2009-09-23 22:47 Ales Katona Resolution reopened => no change required
2009-09-23 22:47 Ales Katona Note Added: 0030948
2009-09-23 22:58 BartO Status resolved => feedback
2009-09-23 22:58 BartO Resolution no change required => reopened
2009-09-23 22:58 BartO Note Added: 0030949
2009-09-23 23:19 Ales Katona Status feedback => resolved
2009-09-23 23:19 Ales Katona Resolution reopened => no change required
2009-09-23 23:19 Ales Katona Note Added: 0030950