mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Added new method to UDP to take a hostname rather than an IP address. Part of issue 243
This commit is contained in:
parent
abfe299bfd
commit
a9c2ebf455
@ -30,6 +30,7 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "Ethernet.h"
|
#include "Ethernet.h"
|
||||||
#include "Udp.h"
|
#include "Udp.h"
|
||||||
|
#include "Dns.h"
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
UDP::UDP() : _sock(MAX_SOCK_NUM) {}
|
UDP::UDP() : _sock(MAX_SOCK_NUM) {}
|
||||||
@ -74,6 +75,22 @@ void UDP::stop()
|
|||||||
_sock = MAX_SOCK_NUM;
|
_sock = MAX_SOCK_NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int UDP::beginPacket(const char *host, uint16_t port)
|
||||||
|
{
|
||||||
|
// Look up the host first
|
||||||
|
int ret = 0;
|
||||||
|
DNSClient dns;
|
||||||
|
IPAddress remote_addr;
|
||||||
|
|
||||||
|
dns.begin(Ethernet.dnsServerIP());
|
||||||
|
ret = dns.getHostByName(host, remote_addr);
|
||||||
|
if (ret == 1) {
|
||||||
|
return beginPacket(remote_addr, port);
|
||||||
|
} else {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int UDP::beginPacket(IPAddress ip, uint16_t port)
|
int UDP::beginPacket(IPAddress ip, uint16_t port)
|
||||||
{
|
{
|
||||||
_offset = 0;
|
_offset = 0;
|
||||||
|
@ -60,6 +60,9 @@ public:
|
|||||||
// Start building up a packet to send to the remote host specific in ip and port
|
// Start building up a packet to send to the remote host specific in ip and port
|
||||||
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||||
int beginPacket(IPAddress ip, uint16_t port);
|
int beginPacket(IPAddress ip, uint16_t port);
|
||||||
|
// Start building up a packet to send to the remote host specific in host and port
|
||||||
|
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||||
|
int beginPacket(const char *host, uint16_t port);
|
||||||
// Finish off this packet and send it
|
// Finish off this packet and send it
|
||||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||||
int endPacket();
|
int endPacket();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user