Skip to content

Commit ca94b4a

Browse files
committed
EthernetUdp - prevent filtering of received messages by IP and port of
sent message
1 parent f1b97b8 commit ca94b4a

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/Ethernet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ UIPEthernetClass::tick()
262262
// uip_len is set to a value > 0. */
263263
if (uip_len > 0)
264264
{
265-
EthernetUDP::_send((uip_udp_userdata_t *)(uip_udp_conns[i].appstate));
265+
EthernetUDP::_send(&uip_udp_conns[i]);
266266
}
267267
}
268268
#endif /* UIP_UDP */

src/EthernetUdp.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ UIPUDP::beginPacket(IPAddress ip, uint16_t port)
9090
#endif
9191
if (_uip_udp_conn)
9292
{
93+
// [J.A]: for UDP server, setting ripaddr and rport causes in uIP filtering
94+
// of incoming messages. it would be better to store the IP and port in fields
95+
// and set them only in endPacket().
9396
_uip_udp_conn->rport = htons(port);
9497
uip_ipaddr_copy(_uip_udp_conn->ripaddr, &ripaddr);
9598
}
@@ -170,7 +173,7 @@ UIPUDP::endPacket()
170173
uip_udp_periodic_conn(_uip_udp_conn);
171174
if (uip_len > 0)
172175
{
173-
_send(&appdata);
176+
_send(_uip_udp_conn);
174177
return 1;
175178
}
176179
}
@@ -359,7 +362,8 @@ uipudp_appcall(void) {
359362
}
360363

361364
void
362-
UIPUDP::_send(uip_udp_userdata_t *data) {
365+
UIPUDP::_send(struct uip_udp_conn *uip_udp_conn) {
366+
363367
uip_arp_out(); //add arp
364368
if (uip_len == UIP_ARPHDRSIZE)
365369
{
@@ -373,9 +377,17 @@ UIPUDP::_send(uip_udp_userdata_t *data) {
373377
else
374378
//arp found ethaddr for ip (otherwise packet is replaced by arp-request)
375379
{
380+
uip_udp_userdata_t* data = (uip_udp_userdata_t *)(uip_udp_conn->appstate);
376381
UIPEthernetClass::network_send();
377382
data->send = false;
378383
data->packet_out = NOBLOCK;
384+
385+
// [J.A] a listening UDP port in uIP filters received messages
386+
// if rport and ripaddr are set. so we better clear them
387+
uip_udp_conn->rport = 0;
388+
uip_udp_conn->ripaddr[0] = 0;
389+
uip_udp_conn->ripaddr[1] = 0;
390+
379391
#ifdef UIPETHERNET_DEBUG_UDP
380392
Serial.print(F("udp, uip_packet to send: "));
381393
Serial.println(UIPEthernetClass::uip_packet);

src/EthernetUdp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class EthernetUDP : public UDP
129129
friend void uipudp_appcall(void);
130130

131131
friend class UIPEthernetClass;
132-
static void _send(uip_udp_userdata_t *data);
132+
static void _send(struct uip_udp_conn *uip_udp_conn);
133133

134134
static uint8_t _newBlock(uip_udp_msg_rec_t* blocks);
135135
static void _moveBlocks(uip_udp_msg_rec_t* blocks);

0 commit comments

Comments
 (0)