File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 30
30
#include " socket.h"
31
31
#include " Ethernet.h"
32
32
#include " Udp.h"
33
+ #include " Dns.h"
33
34
34
35
/* Constructor */
35
36
UDP::UDP () : _sock(MAX_SOCK_NUM) {}
@@ -74,6 +75,22 @@ void UDP::stop()
74
75
_sock = MAX_SOCK_NUM;
75
76
}
76
77
78
+ int UDP::beginPacket (const char *host, uint16_t port)
79
+ {
80
+ // Look up the host first
81
+ int ret = 0 ;
82
+ DNSClient dns;
83
+ IPAddress remote_addr;
84
+
85
+ dns.begin (Ethernet.dnsServerIP ());
86
+ ret = dns.getHostByName (host, remote_addr);
87
+ if (ret == 1 ) {
88
+ return beginPacket (remote_addr, port);
89
+ } else {
90
+ return ret;
91
+ }
92
+ }
93
+
77
94
int UDP::beginPacket (IPAddress ip, uint16_t port)
78
95
{
79
96
_offset = 0 ;
Original file line number Diff line number Diff line change @@ -60,6 +60,9 @@ class UDP : public Stream {
60
60
// Start building up a packet to send to the remote host specific in ip and port
61
61
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
62
62
int beginPacket (IPAddress ip, uint16_t port);
63
+ // Start building up a packet to send to the remote host specific in host and port
64
+ // Returns 1 if successful, 0 if there was a problem resolving the hostname or port
65
+ int beginPacket (const char *host, uint16_t port);
63
66
// Finish off this packet and send it
64
67
// Returns 1 if the packet was sent successfully, 0 if there was an error
65
68
int endPacket ();
You can’t perform that action at this time.
0 commit comments