24 struct IPv6FrameProcessingStruct;
55 struct UdpSocketDataSet
85 void SendandKeepCopy(PoolPtr p);
122 UDPPacket(IPv6FrameProcessingStruct &p6);
163 inline bool Receive(
OS_FIFO *pFifo, uint32_t wait_ticks)
176 m_p = OSPoolFifoPend(pFifo, wait_ticks);
180 #ifdef UDP_FRAGMENTS // Do a fragment test 181 puint8_t pb = (puint8_t)m_p;
183 if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
185 m_bIsFragBuffer = TRUE;
186 m_pPkt = (PUDPPKT)(((PIPPKT)(pb + 4))->DATA);
190 m_bIsFragBuffer = FALSE;
191 m_pPkt = GetUdpPkt(m_p);
194 #ifdef UDP_FRAGMENTS // Do a fragment test 195 puint8_t pb = (puint8_t)m_p;
197 if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
199 m_bIsFragBuffer = TRUE;
200 m_pPkt = (PUDPPKT)(((PIPPKT)(pb + 4))->DATA);
204 m_bIsFragBuffer = FALSE;
205 m_pPkt = GetUdpPkt(m_p);
225 if (m_p ==
NULL)
return false;
300 void SetUpUdpPkt(PoolPtr pp);
301 PUDPPKT InitUdpPkt(
bool IpV6 =
false);
305 inline bool bIsIPV6() {
return (m_pIP6f !=
NULL); };
311 inline PUDPPKT GetUdpPkt(PoolPtr p) { return ::GetUdpPkt(GetIpPkt(p)); };
313 inline void SetUpUdpPkt(PoolPtr pp) { m_pPkt = GetUdpPkt(pp); };
315 inline PUDPPKT GetInitUdpPkt(PIPPKT pIp)
317 pIp->bVerHdrLen = 0x45;
318 return (PUDPPKT)pIp->DATA;
321 inline PUDPPKT GetInitUdpPkt(PoolPtr p) {
return GetInitUdpPkt(GetIpPkt(p)); };
342 uint16_t GetPacketId(
void);
377 void AddData(puint8_t pData, uint16_t len);
447 void Send4(IPADDR4 destIP, uint8_t ttl = 0);
507 inline void Send(
const IPADDR6 &to, uint8_t ttl = 0) {
Send6(to, ttl); };
513 inline void SendAndKeep(IPADDR4 to, uint8_t ttl = 0) {
SendAndKeep4(to, ttl); };
516 inline void Send(IPADDR4 to, uint8_t ttl = 0) {
Send4(to, ttl); };
519 inline void SendViaInterfaceNum(IPADDR4 to,
int interface, uint8_t ttl = 0) {
SendViaInterfaceNum4(to, interface, ttl); };
523 void FragFreeBuffer(PoolPtr mp);
524 void ReleaseBuffer(
void);
525 PoolPtr GetPoolPtr(
void);
526 void FixTransmitBuffers();
528 void ReleaseBuffer(
void)
538 PoolPtr GetPoolPtr(
void) {
return m_p; };
541 #if defined MULTIHOME || defined AUTOIP 542 void SendViaIfAddr4(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0);
543 void SendAndKeepViaIfAddr4(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0);
546 void SendAndKeepViaIfAddr6(
const IPADDR6 &to,
const IPADDR6 &from_ip, uint8_t ttl = 0);
547 inline void SendAndKeepViaIfAddr(
const IPADDR6 &to,
const IPADDR6 &from_ip, uint8_t ttl = 0)
549 SendAndKeepViaIfAddr6(to, from_ip, ttl);
552 void SendViaIfAddr6(
const IPADDR6 &to,
const IPADDR6 &from_ip, uint8_t ttl = 0);
553 inline void SendViaIfAddr(
const IPADDR6 &to,
const IPADDR6 &from_ip, uint8_t ttl = 0) { SendViaIfAddr(to, from_ip, ttl); };
556 inline void SendAndKeepViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendAndKeepViaIfAddr4(to, from_ip, ttl); }
558 inline void SendViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendViaIfAddr4(to, from_ip, ttl); };
562 bool process_all_udp();
581 m_pPkt = cpyfrm.m_pPkt;
583 cpyfrm.m_pPkt =
NULL;
586 m_pIP6f = cpyfrm.m_pIP6f;
587 cpyfrm.m_pIP6f =
NULL;
591 m_bIsFragBuffer = cpyFrm.m_bIsFragBuffer;
600 extern uint8_t pFragmentBuffers[UDP_FRAGMENTS * (65536 + 4)];
601 extern puint8_t pMaxFragmentBuffer;
604 typedef void(udp_data_notify)(
OS_FIFO *pfifo, uint16_t port);
607 uint16_t RegisterEphemeralFifo(
OS_FIFO *pfifo);
653 void process_udp4(PoolPtr pp, PIPPKT pIP, uint16_t csum);
656 struct IPv6FrameProcessingStruct;
657 bool process_udp6(IPv6FrameProcessingStruct &p6proc);
663 #define UDP_ERR_NOSUCH_SOCKET (-1) 664 #define UDP_ERR_NOTOPEN_TO_WRITE (-2) 665 #define UDP_ERR_NOTOPEN_TO_READ (-3) 714 int CreateTxUdpSocket4(IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port);
730 int CreateRxTxUdpSocket4(IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
772 inline int CreateTxUdpSocket(IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port)
795 inline int CreateRxTxUdpSocket(
const IPADDR6 &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
800 inline int CreateRxTxUdpSocket(IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
822 int sendto4(
int sock, puint8_t what_to_send,
int len_to_send, IPADDR4 to_addr, uint16_t remote_port);
841 int sendto6(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR6 &to_addr, uint16_t remote_port);
859 inline int sendto(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR6 &to_addr, uint16_t remote_port)
861 return sendto6(sock, what_to_send, len_to_send, to_addr, remote_port);
864 inline int sendto(
int sock, puint8_t what_to_send,
int len_to_send, IPADDR4 to_addr, uint16_t remote_port)
866 return sendto4(sock, what_to_send, len_to_send, to_addr, remote_port);
870 #if defined MULTIHOME || defined AUTOIP 888 int sendtovia4(
int sock, puint8_t what_to_send,
int len_to_send, IPADDR4 to_addr, uint16_t remote_port,
int intfnum);
908 int sendtovia6(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR6 &to_addr, uint16_t remote_port,
int intfnum);
910 inline int sendtovia(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR6 &to_addr, uint16_t remote_port,
int intfnum)
912 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
915 inline int sendtovia(
int sock, puint8_t what_to_send,
int len_to_send, IPADDR4 to_addr, uint16_t remote_port,
int intfnum)
917 return sendtovia4(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
953 int recvfrom4(
int sock, puint8_t buffer,
int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
973 int recvfrom6(
int sock, puint8_t buffer,
int len,
IPADDR6 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
993 inline int recvfrom(
int sock, puint8_t buffer,
int len,
IPADDR6 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
995 return recvfrom6(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
998 inline int recvfrom(
int sock, puint8_t buffer,
int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
1000 return recvfrom4(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
1009 int SendFragmentedUdpPacket4(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data,
int length);
1012 int SendFragmentedUdpPacket6(
const IPADDR6 &to, uint16_t source_port, uint16_t dest_port, puint8_t data,
int length);
1013 inline int SendFragmentedUdpPacket(
const IPADDR6 &to, uint16_t source_port, uint16_t dest_port, puint8_t data,
int length)
1015 return SendFragmentedUdpPacket6(to, source_port, dest_port, data, length);
1018 inline int SendFragmentedUdpPacket(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data,
int length)
1020 return SendFragmentedUdpPacket4(to, source_port, dest_port, data, length);
1026 #error Got to pick an IP version A FIFO is used to pass structures from one task to another. Note: Structures to be passed must have a...
Definition: nbrtos.h:736
int CreateTxUdpSocket6(const IPADDR6 &send_to_addr, uint16_t remote_port, uint16_t local_port)
Open a UDP socket for transmitting UDP packets.
Definition: ipv6_udpsocket.cpp:37
void RegisterUDPFifo(uint16_t listenPort, OS_FIFO *pFifo)
Register a FIFO to receive incoming UDP packets.
Definition: udp.cpp:1047
UDPPacket(OS_FIFO *pFifo, uint32_t timeout)
Constructor to create a UDP Packet object from a UDP FIFO entry.
Definition: udp.cpp:628
void SendAndKeep6(const IPADDR6 &to, uint8_t ttl=0)
Make a copy of a UDP Packet and send it. The original packet will remain intact.
Definition: ipv6_udp.cpp:131
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition: ipv6_addr.h:28
int CreateRxUdpSocket(uint16_t listening_port)
Open a UDP socket for receiving incoming UDP packets.
Definition: udpsocket.cpp:90
int CreateTxUdpSocket(const IPADDR6 &send_to_addr, uint16_t remote_port, uint16_t local_port)
Open a UDP socket for transmitting UDP packets.
Definition: udp.h:767
void UnregisterUDPFifo(uint16_t listenPort, bool drain=false)
Unregister a UDP FIFO.
Definition: udp.cpp:1106
IPADDR4 GetDestinationAddress4()
Get the destination IPv4 address a UDP Packet object.
Definition: udp.cpp:735
void SetDataSize(uint16_t numBytes)
Set the UDP Packet data size.
Definition: udp.cpp:810
void SetSourcePort(uint16_t port)
Set the source port number of a UDP Packet object.
Definition: udp.cpp:712
void SetDestinationPort(uint16_t)
Set the destination port number of a UDP Packet object.
Definition: udp.cpp:753
uint16_t GetSourcePort(void) const
Get the source port number of a UDP Packet object.
Definition: udp.cpp:717
BOOL Validate(void)
Verify a received UDP packet.
Definition: udp.cpp:1007
~UDPPacket()
UDP packet object destructor. Frees any associated memory.
Definition: udp.cpp:695
uint16_t GetDataSize(void) const
Get the UDP Packet object data size.
Definition: udp.cpp:815
int recvfrom(int sock, puint8_t buffer, int len, IPADDR6 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
Receive a UDP packet.
Definition: udp.h:993
uint16_t GetDestinationPort(void) const
Get the destination port number of a UDP Packet object.
Definition: udp.cpp:758
MACADR GetMacSource()
Get the source MAC address a UDP Packet object.
Definition: udp.cpp:1033
UDP Packet Class.
Definition: udp.h:70
void AddDataByte(uint8_t b)
Add an 8-bit unsigned integer to a UDP Packet object.
Definition: udp.cpp:851
int sendto6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port)
Send a UDP packet.
Definition: ipv6_udpsocket.cpp:79
IPADDR6 GetSourceAddress6(void)
Get the source IPv6 address a UDP Packet object.
Definition: ipv6_udp.cpp:109
int recvfrom4(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
Receive a UDP packet.
Definition: udpsocket.cpp:197
int CreateRxTxUdpSocket6(const IPADDR6 &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
Open a UDP socket that can transmit and receive UDP packets.
Definition: ipv6_udpsocket.cpp:56
void SendViaInterfaceNum4(IPADDR4 destIP, int interface, uint8_t ttl=0)
Send the UDP Packet using the specified interface, and free the pool buffer.
Definition: udp.cpp:959
int sendtovia4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum)
Send a UDP packet on the specified interface.
Definition: udpsocket.cpp:171
void Send6(const IPADDR6 &to, uint8_t ttl=0)
Send the UDP Packet and free the pool buffer.
Definition: ipv6_udp.cpp:140
int sendtovia6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port, int intfnum)
Send a UDP packet on the specified interface.
Definition: ipv6_udpsocket.cpp:92
void RegisterUDPFifoWithNotify(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction)
Register a FIFO to receive incoming UDP packets and a callback function to receive a notification whe...
Definition: udp.cpp:1077
int CreateTxUdpSocket4(IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port)
Open a UDP socket for transmitting UDP packets.
Definition: udpsocket.cpp:113
puint8_t GetDataBuffer(bool bReAllocateIfNeeded=false)
Get a pointer to the UDP Packet object's data buffer.
Definition: udp.cpp:768
IPADDR6 GetDestinationAddress6()
Get the destination IPv6 address a UDP Packet object.
Definition: ipv6_udp.cpp:120
#define NULL
Definition: nm_bsp.h:76
int sendto4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port)
Send a UDP packet.
Definition: udpsocket.cpp:157
void Send4(IPADDR4 destIP, uint8_t ttl=0)
Send the UDP Packet and free the pool buffer.
Definition: udp.cpp:913
void SendViaInterfaceNum6(const IPADDR6 &to, int interface, uint8_t ttl=0)
Send the UDP Packet using the specified interface, and free the pool buffer.
Definition: ipv6_udp.cpp:213
void AddData(puint8_t pData, uint16_t len)
Add data to a UDP Packet object.
Definition: udp.cpp:821
int recvfrom6(int sock, puint8_t buffer, int len, IPADDR6 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
Receive a UDP packet.
Definition: ipv6_udpsocket.cpp:105
int CreateRxTxUdpSocket4(IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
Open a UDP socket that can transmit and receive UDP packets.
Definition: udpsocket.cpp:133
int sendto(int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port)
Send a UDP packet.
Definition: udp.h:859
void AddDataWord(uint16_t w)
Add a 16-bit unsigned integer to a UDP Packet object.
Definition: udp.cpp:845
IPADDR4 GetSourceAddress4(void)
Get the source IPv4 address a UDP Packet object.
Definition: udp.cpp:726
void ResetData(void)
Set the data size of a UDP Packet object to 0.
Definition: udp.cpp:856
void SendAndKeep4(IPADDR4 destIP, uint8_t ttl=0)
Make a copy of a UDP Packet and send it. The original packet will remain intact.
Definition: udp.cpp:894