Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a getter method for the destination IP address. #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dIoTte
Copy link

@dIoTte dIoTte commented Mar 2, 2017

This is useful when the beginPacket method is called with the hostname parameter.

The method should also be added to Arduino/hardware/arduino/avr/cores/arduino/Udp.h and to Arduino/libraries/WiFi/src/WiFiUdp.h.

This is useful when the beginPacket method is called with the hostname
parameter.
@sandeepmistry
Copy link
Contributor

Hey @dIoTte,

Thanks for submitting this PR!

Would you mind sharing an example sketch of how you are using this new capability?

Since the UDP base class of WiFiUDP already has a remoteIP() method, I'm wondering if it's better to make that smarter and return the _sndIP after beginPacket is called. What do you think?

@sandeepmistry sandeepmistry added the status: waiting for information More information must be provided before work can proceed label Mar 2, 2017
@dIoTte
Copy link
Author

dIoTte commented Mar 3, 2017

Hello @sandeepmistry , I've created https://github.com/dIoTte/ArduinoNTPClient containing an example. Please have a look at the methods NetworkTimeProtocolClient::getCurrentNTPTime() and NetworkTimeProtocolClient::readResponseNTPPacket(IPAddress& destinationIP) that illustrate what I'm explaining below.

The new destinationIP() method would allow to check if a UDP request and response match in the case that several UDP requests are made to different servers in a short period of time. Currently, the only way to achieve this verification is to call the method WiFi.hostByName(const char* aHostname, IPAddress& aResult) to obtain the Destination IP before calling the method beginPacket(IPAddress ip, uint16_t port). The problem is that WiFi101.h and WiFi.h don't have a common class hierarchy and makes it impossible to have polymorphic code. However, Udp.h in the Arduino core is virtual and makes it the perfect place to implement the new capability. Regardless of which Udp.h implementation that would be used, it would work.

To answer your question, could solely relaying on _sndIP would introduce a race condition in certain cases?

Thanks for taking the time to look at this. It is very appreciated.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


sebas seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for information More information must be provided before work can proceed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants