Get the IP of the sample sender

4 posts / 0 new
Last post
fps
fps's picture
Offline
Last seen: 2 years 5 months ago
Joined: 01/17/2013
Posts: 16
Get the IP of the sample sender

Hi,

When a sample is received, is it possible to work out the IP or hostname of the sender?

Thanks,
Fidel

Gerardo Pardo's picture
Offline
Last seen: 1 month 1 week ago
Joined: 06/02/2010
Posts: 591

Yes, this is possible.  But it requires a few steps which I describe below.

The IP address, in fact all the addresses that can be used to reach a DDS DomainParticipant are propagated by the DomainParticipant itself via discovery and available in in the ParticipantBuiltinTopicData which can be accessed reading the "DCPSParticipants" builtin Topic as described in the HOWTO tiltled "Detect the presence of DomainParticipants, DataWriters and DataReaders in the DDS Domain".

Each discovered participant is uniquely identified via a GUID which is available in the field ParticipantBuiltinTopicData.key. The IP address(es) of the DomainParticipant can be found in ParticipantBuiltinTopicData.metatraffic_unicast_locators.

Now when a sample is received, the SampleInfo_t contains a referece to the DataWriter that sent the sample. This reference is encoded in the SampleInfo_t.publication_handle.  With the publication_handle  you can get the information on the DataWriter that wrote the data by calling the operation get_matched_publication_data on the DataReader which accepts the SampleInfo_t.ublication_handle and fills a PublicationBuiltinTopicData with that informaton. There you can fiend the GUID of the participant that wrote the sample in the field PublicationBuiltinTopicData.participant_key.

Therefore one possible approch is to save the information on the locators of the discovered participants associating the information with the Participant GUID. Then when a sample is received you use the InstanceHandle_t to get to the GUID as shown in the Java pseudo-code below:

dataReader.take_next_sample(data, info); 
System.out.println("Receive data from DataWriter...");
dataReader.get_matched_publication_data(publicationData, info.publication_handle);
                           
// publicationData.participant_key contains GUID of the Participant that wrote the sample
// Locate the Participant using publicationData.participant_key and access its locators  

I uploaded to the File Exchange an example of how to do this in Java. It is the file  MonitorInformationOnSampleWriter.java.

Gerardo

 

fps
fps's picture
Offline
Last seen: 2 years 5 months ago
Joined: 01/17/2013
Posts: 16

Thank you once again Gerado for a very detailed answer!

Offline
Last seen: 3 months 3 weeks ago
Joined: 03/12/2020
Posts: 3

can you provide code snippet for the same in rti6 in c++