NetBurner 3.1
udp.h
Go to the documentation of this file.
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
19 #ifndef _NB_UDP_H_
20 #define _NB_UDP_H_
21 #include <ip.h>
22 
23 #ifdef IPV6
24 struct IPv6FrameProcessingStruct; // Forward
25 #endif
26 
27 /*-----------------------------------------------------------------------------------------------**
28  * This class holds PoolBuffers and treats them as UDP Packets. The process for sending a UDP
29  * packet is as follows:
30  * UDPPacket myUdpPacket; // declare the object
31  * myUdpPacket.SetSourcePort(123); // Set source port number
32  * myUdpPacket.SetDestinatioPort(456); // Set destination port number
33  *
34  * Data can be put in the packet two ways:
35  * 1. Get a pointer to the object's data buffer and copy the data in. Be certain to set the data length.
36  * uint16_t len = siprintf( myUdpPacket.GetDataBuffer(), "This is a printf to a packet at time = %ld", TickCount );
37  * myUdpPacket.SetDataSize(len);
38  *
39  * 2. Copy the data directly to the packet buffer:
40  * AddData("This is the data to add"); // Add a constant string
41  * AddData(pData, len); // Add with a pointer to the data and the data length
42  *
43  * When the UDP packet has been configured it can be sent two ways:
44  * 1. Send and keep the packet and keep the constructed pool buffer:
45  * SendAndKeep(IPADDR destinationIP);
46  *
47  * 2. Send and automatically free the pool buffer (more efficient):
48  * Send(IPADDR4 destinationIP);
49  *
50  *-----------------------------------------------------------------------------------------------*/
51 #ifdef IPV6
52 struct IP6FRAME;
53 #endif
54 
55 struct UdpSocketDataSet
56 {
57  OS_FIFO the_fifo;
58  int fd = 0;
59  IPADDR address;
60  uint16_t rxport = 0;
61  uint16_t lport = 0;
62  uint16_t rport = 0;
63 };
64 
70 class UDPPacket
71 {
72  protected:
73  PoolPtr m_p;
74  PUDPPKT m_pPkt;
75 
76 #ifdef IPV6
77  IP6FRAME *m_pIP6f;
78 #endif
79 
80 #ifdef UDP_FRAGMENTS
81  BOOL m_bIsFragBuffer;
82 #endif
83 
84  PIPPKT GetIpPacket();
85  void SendandKeepCopy(PoolPtr p);
86 
87  public:
104  UDPPacket(OS_FIFO *pFifo, uint32_t timeout);
105 
119  UDPPacket(int sock);
120 
121 #ifdef IPV6
122  UDPPacket(IPv6FrameProcessingStruct &p6);
123  void Fix_6_Sb_4();
124 #endif
125 
136  UDPPacket(PoolPtr p);
137 
147  UDPPacket(UDPPacket &pkt);
148 
149 #ifdef IPV6
150  UDPPacket(bool bIsIpv6 = false);
151 #else
152  UDPPacket();
153 #endif
154 
160  ~UDPPacket();
161 
162  // Returns true if it was able to receive another packet into this UDP object.
163  inline bool Receive(OS_FIFO *pFifo, uint32_t wait_ticks)
164  {
165  if (m_p != 0)
166  {
167 #ifdef UDP_FRAGMENTS
168  FragFreeBuffer(m_p);
169 #else
170  FreeBuffer(m_p);
171 #endif
172 
173  m_p = NULL;
174  }
175 
176  m_p = OSPoolFifoPend(pFifo, wait_ticks);
177 
178  if (m_p)
179  {
180 #ifdef UDP_FRAGMENTS // Do a fragment test
181  puint8_t pb = (puint8_t)m_p;
182 
183  if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
184  {
185  m_bIsFragBuffer = TRUE;
186  m_pPkt = (PUDPPKT)(((PIPPKT)(pb + 4))->DATA);
187  }
188  else
189  {
190  m_bIsFragBuffer = FALSE;
191  m_pPkt = GetUdpPkt(m_p);
192  if (m_p)
193  {
194 #ifdef UDP_FRAGMENTS // Do a fragment test
195  puint8_t pb = (puint8_t)m_p;
196 
197  if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
198  {
199  m_bIsFragBuffer = TRUE;
200  m_pPkt = (PUDPPKT)(((PIPPKT)(pb + 4))->DATA);
201  }
202  else
203  {
204  m_bIsFragBuffer = FALSE;
205  m_pPkt = GetUdpPkt(m_p);
206  }
207 #else
208  SetUpUdpPkt(m_p);
209 #endif
210  }
211  else
212  {
213  m_pPkt = NULL;
214  }
215  }
216 #else
217  SetUpUdpPkt(m_p);
218 #endif
219  }
220  else
221  {
222  m_pPkt = NULL;
223  }
224 
225  if (m_p == NULL) return false;
226  return true;
227  };
228 
236  void SetSourcePort(uint16_t port);
237 
245  uint16_t GetSourcePort(void) const;
246 
256  IPADDR4 GetSourceAddress4(void);
257 
267  IPADDR4 GetDestinationAddress4();
268 
275  MACADR GetMacSource();
276 
277 #ifdef IPV6
278 
288 
299 
300  void SetUpUdpPkt(PoolPtr pp);
301  PUDPPKT InitUdpPkt(bool IpV6 = false);
302 
303  inline IPADDR6 GetSourceAddress(void) { return GetSourceAddress6(); };
304  inline IPADDR6 GetDestinationAddress(void) { return GetDestinationAddress6(); }
305  inline bool bIsIPV6() { return (m_pIP6f != NULL); };
306 #else
307  inline IPADDR4 GetSourceAddress(void) { return GetSourceAddress4(); };
308  inline IPADDR4 GetDestinationAddress() { return GetDestinationAddress4(); }
309 
310  /* Get UDP Packet pointer from network buffer pool buffer */
311  inline PUDPPKT GetUdpPkt(PoolPtr p) { return ::GetUdpPkt(GetIpPkt(p)); };
312 
313  inline void SetUpUdpPkt(PoolPtr pp) { m_pPkt = GetUdpPkt(pp); };
314 
315  inline PUDPPKT GetInitUdpPkt(PIPPKT pIp)
316  {
317  pIp->bVerHdrLen = 0x45;
318  return (PUDPPKT)pIp->DATA;
319  }
320 
321  inline PUDPPKT GetInitUdpPkt(PoolPtr p) { return GetInitUdpPkt(GetIpPkt(p)); };
322 #endif
323 
331  void SetDestinationPort(uint16_t);
332 
340  uint16_t GetDestinationPort(void) const;
341 
342  uint16_t GetPacketId(void);
343 
349  puint8_t GetDataBuffer(bool bReAllocateIfNeeded = false);
350 
358  void SetDataSize(uint16_t numBytes);
359 
367  uint16_t GetDataSize(void) const;
368 
377  void AddData(puint8_t pData, uint16_t len);
378 
386  void AddData(PCSTR pData);
387 
395  void AddDataWord(uint16_t w);
396 
404  void AddDataByte(uint8_t b);
405 
415  BOOL Validate(void); // Check the Checksum
416 
421  void ResetData(void); // Zero the data buffer and return.
422 
434  void SendAndKeep4(IPADDR4 destIP, uint8_t ttl = 0);
435 
447  void Send4(IPADDR4 destIP, uint8_t ttl = 0);
448 
461  void SendViaInterfaceNum4(IPADDR4 destIP, int interface, uint8_t ttl = 0);
462 
463 #ifdef IPV6
464 
475  void SendAndKeep6(const IPADDR6 &to, uint8_t ttl = 0);
476 
488  void Send6(const IPADDR6 &to, uint8_t ttl = 0);
489 
502  void SendViaInterfaceNum6(const IPADDR6 &to, int interface, uint8_t ttl = 0);
503 
504  inline void SendAndKeep(const IPADDR6 &to, uint8_t ttl = 0) { SendAndKeep6(to, ttl); };
505 
506  // Send destroys the data in the packet.
507  inline void Send(const IPADDR6 &to, uint8_t ttl = 0) { Send6(to, ttl); };
508 
509  // Send destroys the data in the packet.
510  inline void SendViaInterfaceNum(const IPADDR6 &to, int interface, uint8_t ttl = 0) { SendViaInterfaceNum6(to, interface, ttl); };
511 
512 #else
513  inline void SendAndKeep(IPADDR4 to, uint8_t ttl = 0) { SendAndKeep4(to, ttl); };
514 
515  // Send destroys the data in the packet.
516  inline void Send(IPADDR4 to, uint8_t ttl = 0) { Send4(to, ttl); };
517 
518  // Send destroys the data in the packet.
519  inline void SendViaInterfaceNum(IPADDR4 to, int interface, uint8_t ttl = 0) { SendViaInterfaceNum4(to, interface, ttl); };
520 #endif
521 
522 #ifdef UDP_FRAGMENTS
523  void FragFreeBuffer(PoolPtr mp);
524  void ReleaseBuffer(void);
525  PoolPtr GetPoolPtr(void);
526  void FixTransmitBuffers();
527 #else
528  void ReleaseBuffer(void)
529  {
530  m_p = NULL;
531  m_pPkt = NULL;
532 
533 #ifdef IPV6
534  m_pIP6f = NULL;
535 #endif
536  };
537 
538  PoolPtr GetPoolPtr(void) { return m_p; };
539 #endif
540 
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);
544 
545 #ifdef IPV6
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)
548  {
549  SendAndKeepViaIfAddr6(to, from_ip, ttl);
550  }
551  // Send destroys the data in the packet.
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); };
554 #else
555  // Send and keep makes a copy of this UDP packet and sends it.
556  inline void SendAndKeepViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendAndKeepViaIfAddr4(to, from_ip, ttl); }
557  // Send destroys the data in the packet.
558  inline void SendViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendViaIfAddr4(to, from_ip, ttl); };
559 #endif //
560 #endif // Multi home
561 
562  bool process_all_udp();
563 
564  // Uncomment when C++11 is enabled.
565  // UDPPacket & operator = (const UDPPacket & pf) =delete;
566 
567  // Destructive Copy constructor destroys other UdpPacket
568  inline void CopyFrom(UDPPacket cpyfrm)
569  {
570  if (m_p != 0)
571  {
572 #ifdef UDP_FRAGMENTS
573  FragFreeBuffer(m_p);
574 #else
575  FreeBuffer(m_p);
576 #endif
577 
578  m_p = NULL;
579  }
580  m_p = cpyfrm.m_p;
581  m_pPkt = cpyfrm.m_pPkt;
582  cpyfrm.m_p = NULL;
583  cpyfrm.m_pPkt = NULL;
584 
585 #ifdef IPV6
586  m_pIP6f = cpyfrm.m_pIP6f;
587  cpyfrm.m_pIP6f = NULL;
588 #endif
589 
590 #ifdef UDP_FRAGMENTS
591  m_bIsFragBuffer = cpyFrm.m_bIsFragBuffer;
592 #endif
593  };
594 
595  void Swap(UDPPacket &rhs);
596 
597 }; // end of UDPPacket Class
598 
599 #ifdef UDP_FRAGMENTS
600 extern uint8_t pFragmentBuffers[UDP_FRAGMENTS * (65536 + 4)];
601 extern puint8_t pMaxFragmentBuffer;
602 #endif
603 
604 typedef void(udp_data_notify)(OS_FIFO *pfifo, uint16_t port);
605 
606 // Gets an unused ephemeral port registers the FIFO. Returns the Ephemeral value.
607 uint16_t RegisterEphemeralFifo(OS_FIFO *pfifo);
608 
621 void RegisterUDPFifo(uint16_t listenPort, OS_FIFO *pFifo);
622 
637 void RegisterUDPFifoWithNotify(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction);
638 
649 void UnregisterUDPFifo(uint16_t listenPort, bool drain = false);
650 
651 // INTERNAL FUNCTIONS. Used by the ip.cpp process packet functions
652 
653 void process_udp4(PoolPtr pp, PIPPKT pIP, uint16_t csum);
654 
655 #ifdef IPV6
656 struct IPv6FrameProcessingStruct; // Forward
657 bool process_udp6(IPv6FrameProcessingStruct &p6proc);
658 #endif
659 
663 #define UDP_ERR_NOSUCH_SOCKET (-1)
664 #define UDP_ERR_NOTOPEN_TO_WRITE (-2)
665 #define UDP_ERR_NOTOPEN_TO_READ (-3)
666  // end of groupUDP
669 
670 //----- Wrappers to create a UDP socket interface -----
671 
696 int CreateRxUdpSocket(uint16_t listening_port);
697 
714 int CreateTxUdpSocket4(IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port);
715 
730 int CreateRxTxUdpSocket4(IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
731 
732 #ifdef IPV6
733 
749 int CreateTxUdpSocket6(const IPADDR6 &send_to_addr, uint16_t remote_port, uint16_t local_port);
750 
767 inline int CreateTxUdpSocket(const IPADDR6 &send_to_addr, uint16_t remote_port, uint16_t local_port)
768 {
769  return CreateTxUdpSocket6(send_to_addr, remote_port, local_port);
770 };
771 #else
772 inline int CreateTxUdpSocket(IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port)
773 {
774  return CreateTxUdpSocket4(send_to_addr, remote_port, local_port);
775 };
776 #endif
777 
778 #ifdef IPV6
779 
793 int CreateRxTxUdpSocket6(const IPADDR6 &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
794 
795 inline int CreateRxTxUdpSocket(const IPADDR6 &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
796 {
797  return CreateRxTxUdpSocket6(send_to_addr, send_to_remote_port, local_port);
798 };
799 #else
800 inline int CreateRxTxUdpSocket(IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
801 {
802  return CreateRxTxUdpSocket4(send_to_addr, send_to_remote_port, local_port);
803 };
804 #endif
805 
822 int sendto4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port);
823 
824 #ifdef IPV6
825 
841 int sendto6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port);
842 
859 inline int sendto(int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port)
860 {
861  return sendto6(sock, what_to_send, len_to_send, to_addr, remote_port);
862 };
863 #else
864 inline int sendto(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port)
865 {
866  return sendto4(sock, what_to_send, len_to_send, to_addr, remote_port);
867 };
868 #endif
869 
870 #if defined MULTIHOME || defined AUTOIP
871 
888 int sendtovia4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum);
889 
890 #ifdef IPV6
891 
908 int sendtovia6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port, int intfnum);
909 
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)
911 {
912  return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
913 };
914 #else
915 inline int sendtovia(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum)
916 {
917  return sendtovia4(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
918 };
919 #endif
920 #endif
921 
922 /* Receive a UDP packet and pointer. The pointer can be NULL and will not be used in that case.
923  *
924  * Parameters:
925  *
926  * sock The UDP socket
927  * buffer The data to send
928  * len The length of the data to send
929  * pAddr A pointer to an IPADDR variable to hold the address of the device that sent the UDP packet
930  * pLocal_port A pointer to a uint16_t variable to hold the local port this was sent to
931  * pRemote_port A pointer to a uint16_t variable to hold the remote port this was sent from
932  *
933  * Returns the number of bytes read or UDP_ERR_NOSUCH_SOCKET (-1)
934  */
935 
953 int recvfrom4(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
954 
955 #ifdef IPV6
956 
973 int recvfrom6(int sock, puint8_t buffer, int len, IPADDR6 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
974 
975 // If address is IPV4 you get a IPV4 encoded in IPV6 ie ::FFFF.x.x.x.x
993 inline int recvfrom(int sock, puint8_t buffer, int len, IPADDR6 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
994 {
995  return recvfrom6(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
996 };
997 #else
998 inline int recvfrom(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
999 {
1000  return recvfrom4(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
1001 };
1002 #endif
1003 
1004 /* Send a large fragmented UDP packet to is the destination address source_port is the source port dest_port
1005  * is the destination port data is the data to send length is the length to send.
1006  *
1007  * returns 0 on failure, length on success
1008  */
1009 int SendFragmentedUdpPacket4(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length);
1010 
1011 #ifdef IPV6
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)
1014 {
1015  return SendFragmentedUdpPacket6(to, source_port, dest_port, data, length);
1016 };
1017 #else
1018 inline int SendFragmentedUdpPacket(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
1019 {
1020  return SendFragmentedUdpPacket4(to, source_port, dest_port, data, length);
1021 };
1022 #endif
1023 
1024 #ifndef IPV6
1025 #ifndef IPV4ONLY
1026 #error Got to pick an IP version
1027 #endif
1028 #endif
1029 
1030 #endif /* #ifndef _NB_UDP_H_ */
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&#39;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