Determine Local IP of UDP client data packet

Roger Alcindor
Roger Alcindor used Ask the Experts™
on
I am using an Indy 10 UDP client component with Embarcadero C++ builder EX 10.1 Berlin

I need to determine the IP address of the local PC that received the broadcast packet (not the peer IP). there are two network cards.
The UDP client is bound to 0.0.0.0 port 13580

How do I determine the IP address of the Ethernet port that generated the event ?

void __fastcall TForm1::IdSystatUDPServer1UDPRead(TIdUDPListenerThread *AThread, const TIdBytes AData,
          TIdSocketHandle *ABinding)
{
	UnicodeString u;


	u = ABinding->IP; // this is the binding which is 0.0.0.0
 	u = AThread->Binding->IP; // I was expecting this to give what I want but it returns .0.0.0.0

	if(u == u"10.41.0.20")  // only use specified local ethernet port
{
.....
}
else
{ // handle differently if another network adapter received the data

}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Geert GOracle dba
Top Expert 2009

Commented:
we fill a database table with the ip adress, port and exe name at startup
and gets reset every x hours

an automated job, deletes entries older then x+1 hours

here is a link on how to get the local ip with several methods
http://delphiprogrammingdiary.blogspot.com/2018/06/how-to-get-local-ip-address-in-delphi.html

some require admin rights

Author

Commented:
Thanks for your comment, interesting and informative though it is, it doesn't answer my question. I already know the IP addresses of the local machine.
What I need to know is which one received the UDP packet that triggered the Indy IdSystatUDPServer1UDPRead event handler as shown in my code sample.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial