diff --git a/src/EtherCard.h b/src/EtherCard.h index 703b599..d5ea452 100644 --- a/src/EtherCard.h +++ b/src/EtherCard.h @@ -89,6 +89,7 @@ /** This type definition defines the structure of a UDP server event handler callback function */ typedef void (*UdpServerCallback)( uint16_t dest_port, ///< Port the packet was sent to + const uint8_t *src_mac, uint8_t src_ip[IP_LEN], ///< IP address of the sender uint16_t src_port, ///< Port the packet was sent from const char *data, ///< UDP payload data @@ -263,7 +264,7 @@ class EtherCard : public Ethernet { * @param dip Pointer to 4 byte destination IP address * @param dport Destination port */ - static void udpPrepare (uint16_t sport, const uint8_t *dip, uint16_t dport); + static void udpPrepare (uint16_t sport, const uint8_t *dip, uint16_t dport, const uint8_t *dmac = nullptr); /** @brief Transmit UDP packet * @param len Size of payload @@ -278,7 +279,7 @@ class EtherCard : public Ethernet { * @param dport Destination port */ static void sendUdp (const char *data, uint8_t len, uint16_t sport, - const uint8_t *dip, uint16_t dport); + const uint8_t *dip, uint16_t dport, const uint8_t *dmac = nullptr); /** @brief Resister the function to handle ping events * @param cb Pointer to function diff --git a/src/tcpip.cpp b/src/tcpip.cpp index 9c2cf39..8738795 100644 --- a/src/tcpip.cpp +++ b/src/tcpip.cpp @@ -373,9 +373,13 @@ uint8_t EtherCard::ntpProcessAnswer (uint32_t *time,uint8_t dstport_l) { return 1; } -void EtherCard::udpPrepare (uint16_t sport, const uint8_t *dip, uint16_t dport) { +void EtherCard::udpPrepare (uint16_t sport, const uint8_t *dip, uint16_t dport, const uint8_t *dmac) { if(is_lan(myip, dip)) { // this works because both dns mac and destinations mac are stored in same variable - destmacaddr - setMACandIPs(destmacaddr, dip); // at different times. The program could have separate variable for dns mac, then here should be + if (dmac!=nullptr){ + setMACandIPs(/*destmacaddr*/dmac, dip); // at different times. The program could have separate variable for dns mac, then here should be + }else{ + setMACandIPs(destmacaddr, dip); + } } else { // checked if dip is dns ip and separately if dip is hisip and then use correct mac. setMACandIPs(gwmacaddr, dip); } @@ -408,8 +412,8 @@ void EtherCard::udpTransmit (uint16_t datalen) { } void EtherCard::sendUdp (const char *data, uint8_t datalen, uint16_t sport, - const uint8_t *dip, uint16_t dport) { - udpPrepare(sport, dip, dport); + const uint8_t *dip, uint16_t dport, const uint8_t *dmac) { + udpPrepare(sport, dip, dport, dmac); if (datalen>220) datalen = 220; memcpy(gPB + UDP_DATA_P, data, datalen); diff --git a/src/udpserver.cpp b/src/udpserver.cpp index aa3b74f..6358bbf 100644 --- a/src/udpserver.cpp +++ b/src/udpserver.cpp @@ -62,6 +62,7 @@ bool EtherCard::udpServerHasProcessedPacket(uint16_t plen) { uint16_t datalen = (uint16_t) (gPB[UDP_LEN_H_P] << 8) + gPB[UDP_LEN_L_P] - UDP_HEADER_LEN; listeners[i].callback( listeners[i].port, + (const uint8_t *) gPB + ETH_SRC_MAC, gPB + IP_SRC_P, (gPB[UDP_SRC_PORT_H_P] << 8) | gPB[UDP_SRC_PORT_L_P], (const char *) (gPB + UDP_DATA_P),