NetBurner 3.5.6
PDF Version
udp.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
21#ifndef _NB_UDP_H_
22#define _NB_UDP_H_
23#include <predef.h>
24#include <ip.h>
25
26#ifdef IPV6
27struct IPv6FrameProcessingStruct; // Forward
28#endif
29
30#ifdef IPV6
31struct IP6FRAME;
32#endif
33
34struct UdpSocketDataSet
35{
36 OS_FIFO the_fifo;
37 int fd = 0;
38 IPADDR address;
39 int ifn;
40 uint16_t rxport = 0;
41 uint16_t lport = 0;
42 uint16_t rport = 0;
43 uint16_t io_counter=0;
44};
45
81{
82 protected:
83 PoolPtr m_p;
84 PUDPPKT m_pPkt;
85
86#ifdef IPV6
87 IP6FRAME *m_pIP6f;
88#endif
89
90#ifdef UDP_FRAGMENTS
91 BOOL m_bIsFragBuffer;
92#endif
93
94 PIPPKT GetIpPacket();
95 int BuildHeaders4(IPADDR4 destIP, IPADDR4 *srcIP, uint8_t ttl);
96 friend PoolPtr CreateDnsResponse4(IPADDR4 serverIp, IPADDR4 clientIp, uint16_t serverPort, uint16_t clientPort, const char *name, IPADDR hostIp, uint32_t ttl);
97
98 UDPPacket(UDPPacket *pkt,bool clone);
99
100
101 public:
118 UDPPacket(OS_FIFO *pFifo, TickTimeout timeout);
119
120 UDPPacket(OS_FIFO *pFifo, uint32_t timeout);
121
135 UDPPacket(int sock);
136
137#ifdef IPV6
139 void Fix_6_Sb_4();
140#endif
141
153
164
165#ifdef IPV6
166 UDPPacket(bool bIsIpv6 = false);
167#else
168 UDPPacket();
169#endif
170
177
178 // Returns true if it was able to receive another packet into this UDP object.
179 inline bool Receive(OS_FIFO *pFifo, uint32_t wait_ticks)
180 {
181 if (m_p != 0)
182 {
183#ifdef UDP_FRAGMENTS
184 FragFreeBuffer(m_p);
185#else
186 FreeBuffer(m_p);
187#endif
188
189 m_p = NULL;
190 }
191
192 m_p = OSPoolFifoPend(pFifo, wait_ticks);
193
194 if (m_p)
195 {
196#ifdef UDP_FRAGMENTS // Do a fragment test
197 puint8_t pb = (puint8_t)m_p;
198
199 if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
200 {
201 m_bIsFragBuffer = TRUE;
202 m_pPkt = (PUDPPKT)(((PIPPKT)(pb + 4))->DATA);
203 }
204 else
205 {
206 m_bIsFragBuffer = FALSE;
207 m_pPkt = GetUdpPkt(m_p);
208 if (m_p)
209 {
210#ifdef UDP_FRAGMENTS // Do a fragment test
211 puint8_t pb = (puint8_t)m_p;
212
213 if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
214 {
215 m_bIsFragBuffer = TRUE;
216 m_pPkt = (PUDPPKT)(((PIPPKT)(pb + 4))->DATA);
217 }
218 else
219 {
220 m_bIsFragBuffer = FALSE;
221 m_pPkt = GetUdpPkt(m_p);
222 }
223#else
224 SetUpUdpPkt(m_p);
225#endif
226 }
227 else
228 {
229 m_pPkt = NULL;
230 }
231 }
232#else
233 SetUpUdpPkt(m_p);
234#endif
235 }
236 else
237 {
238 m_pPkt = NULL;
239 }
240
241 if (m_p == NULL) return false;
242 return true;
243 };
244
252 void SetSourcePort(uint16_t port);
253
261 uint16_t GetSourcePort(void) const;
262
263 IPADDR4 GetSourceAddress4(void);
264 IPADDR4 GetDestinationAddress4();
265
272
273#ifdef IPV6
274 IPADDR GetSourceAddress6(void);
275 IPADDR GetDestinationAddress6();
276
277 void SetUpUdpPkt(PoolPtr pp);
278 PUDPPKT InitUdpPkt(bool IpV6 = false);
279
285 inline IPADDR GetSourceAddress(void) { return GetSourceAddress6(); };
286
292 inline IPADDR GetDestinationAddress(void) { return GetDestinationAddress6(); }
293
299 inline bool bIsIPV6() const { return (m_pIP6f != NULL); };
300#else
301 inline IPADDR4 GetSourceAddress(void) { return GetSourceAddress4(); };
302 inline IPADDR4 GetDestinationAddress() { return GetDestinationAddress4(); }
303
304 /* Get UDP Packet pointer from network buffer pool buffer */
305 inline PUDPPKT GetUdpPkt(PoolPtr p) { return ::GetUdpPkt(GetIpPkt(p)); };
306
307 inline void SetUpUdpPkt(PoolPtr pp) { m_pPkt = GetUdpPkt(pp); };
308
309 inline PUDPPKT GetInitUdpPkt(PIPPKT pIp)
310 {
311 pIp->bVerHdrLen = 0x45;
312 return (PUDPPKT)pIp->DATA;
313 }
314
315 inline PUDPPKT GetInitUdpPkt(PoolPtr p) { return GetInitUdpPkt(GetIpPkt(p)); };
316#endif
317
325 void SetDestinationPort(uint16_t port);
326
334 uint16_t GetDestinationPort(void) const;
335
341 uint16_t GetPacketId(void);
342
354 void SetDSCP(uint8_t dscp);
355
367 uint8_t GetDSCP(void) const;
368
374 puint8_t GetDataBuffer(bool bReAllocateIfNeeded = false);
375
383 void SetDataSize(uint16_t numBytes);
384
392 uint16_t GetDataSize(void) const;
393
402 void AddData(puint8_t pData, uint16_t len);
403
411 void AddData(PCSTR pData);
412
420 void AddDataWord(uint16_t w);
421
429 void AddDataByte(uint8_t b);
430
439 BOOL Validate(void); // Check the Checksum
440
445 void ResetData(void); // Zero the data buffer and return.
446
447 void SendAndKeep4(IPADDR4 destIP, uint8_t ttl = 0);
448 void Send4(IPADDR4 destIP, uint8_t ttl = 0);
449 void SendAndKeepViaInterfaceNum4(IPADDR4 to, int interface, uint8_t ttl = 0);
450 void SendViaInterfaceNum4(IPADDR4 destIP, int interface, uint8_t ttl = 0);
451
452#ifdef IPV6
453 void SendAndKeep6(const IPADDR &to, uint8_t ttl = 0);
454 void Send6(const IPADDR &to, uint8_t ttl = 0);
455 void SendAndKeepViaInterfaceNum6(const IPADDR &to, int interface, uint8_t ttl = 0);
456 void SendViaInterfaceNum6(const IPADDR &to, int interface, uint8_t ttl = 0);
457
466 inline void SendAndKeep(const IPADDR &to, uint8_t ttl = 0) { SendAndKeep6(to, ttl); };
467
477 inline void Send(const IPADDR &to, uint8_t ttl = 0) { Send6(to, ttl); };
478
489 inline void SendAndKeepViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl = 0)
490 {
491 SendAndKeepViaInterfaceNum6(to, interface, ttl);
492 }
493
503 inline void SendViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl = 0) { SendViaInterfaceNum6(to, interface, ttl); };
504
505#else
506 inline void SendAndKeep(IPADDR4 to, uint8_t ttl = 0) { SendAndKeep4(to, ttl); };
507 inline void Send(IPADDR4 to, uint8_t ttl = 0) { Send4(to, ttl); };
508 inline void SendAndKeepViaInterfaceNum(IPADDR4 to, int interface, uint8_t ttl = 0) { SendAndKeepViaInterfaceNum4(to, interface, ttl); };
509 inline void SendViaInterfaceNum(IPADDR4 to, int interface, uint8_t ttl = 0) { SendViaInterfaceNum4(to, interface, ttl); };
510#endif
511
512#ifdef UDP_FRAGMENTS
513 void FragFreeBuffer(PoolPtr mp);
514 void ReleaseBuffer(void);
515 PoolPtr GetPoolPtr(void);
516 void FixTransmitBuffers();
517#else
518 void ReleaseBuffer(void)
519 {
520 m_p = NULL;
521 m_pPkt = NULL;
522
523#ifdef IPV6
524 m_pIP6f = NULL;
525#endif
526 };
527
528 PoolPtr GetPoolPtr(void) { return m_p; };
529#endif
530
531#if defined MULTIHOME || defined AUTOIP
532 void SendViaIfAddr4(IPADDR4 to, IPADDR4 *from_ip, uint8_t ttl = 0);
533 void SendViaIfAddrAndNum4(IPADDR4 to, IPADDR4 *from_ip, int interface, uint8_t ttl = 0);
534 void SendAndKeepViaIfAddr4(IPADDR4 to, IPADDR4 *from_ip, uint8_t ttl = 0);
535
536#ifdef IPV6
537 void SendAndKeepViaIfAddr6(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0);
538
550 inline void SendAndKeepViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0) { SendAndKeepViaIfAddr6(to, from_ip, ttl); }
551 // Send destroys the data in the packet.
552 void SendViaIfAddr6(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0);
553
565 inline void SendViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0) { SendViaIfAddr(to, from_ip, ttl); };
566#else
567 // Send and keep makes a copy of this UDP packet and sends it.
568 inline void SendAndKeepViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendAndKeepViaIfAddr4(to, &from_ip, ttl); }
569 // Send destroys the data in the packet.
570 inline void SendViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendViaIfAddr4(to, &from_ip, ttl); };
571#endif //
572#endif // Multi home
573
574 bool process_all_udp();
575
576 // Uncomment when C++11 is enabled.
577 // UDPPacket & operator = (const UDPPacket & pf) =delete;
578
579 // Destructive Copy constructor destroys other UdpPacket
580 inline void CopyFrom(UDPPacket cpyfrm)
581 {
582 if (m_p != 0)
583 {
584#ifdef UDP_FRAGMENTS
585 FragFreeBuffer(m_p);
586#else
587 FreeBuffer(m_p);
588#endif
589
590 m_p = NULL;
591 }
592 m_p = cpyfrm.m_p;
593 m_pPkt = cpyfrm.m_pPkt;
594 cpyfrm.m_p = NULL;
595 cpyfrm.m_pPkt = NULL;
596
597#ifdef IPV6
598 m_pIP6f = cpyfrm.m_pIP6f;
599 cpyfrm.m_pIP6f = NULL;
600#endif
601
602#ifdef UDP_FRAGMENTS
603 m_bIsFragBuffer = cpyFrm.m_bIsFragBuffer;
604#endif
605 };
606
607 void Swap(UDPPacket &rhs);
608
609}; // end of UDPPacket Class
610
611#ifdef UDP_FRAGMENTS
612extern uint8_t pFragmentBuffers[UDP_FRAGMENTS * (65536 + 4)];
613extern puint8_t pMaxFragmentBuffer;
614#endif
615
616typedef void(udp_data_notify)(OS_FIFO *pfifo, uint16_t port);
617
631bool RegisterUDPFifo(uint16_t listenPort, OS_FIFO *pFifo);
632
647bool RegisterUDPFifoVia(uint16_t listenPort, OS_FIFO *pFifo, int interface);
648
664uint16_t RegisterEphemeralFifo(OS_FIFO *pfifo, int ifn = -1);
665
682bool RegisterUDPFifoWithNotify(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction);
683
702bool RegisterUDPFifoWithNotifyVia(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction, int interface);
703
712void UnregisterUDPFifo(uint16_t listenPort, bool drain = false);
713
714// INTERNAL FUNCTIONS. Used by the ip.cpp process packet functions
715
716void process_udp4(PoolPtr pp, PIPPKT pIP, uint16_t csum);
717
718#ifdef IPV6
719struct IPv6FrameProcessingStruct; // Forward
720bool process_udp6(IPv6FrameProcessingStruct &p6proc);
721#endif
722
727#define UDP_ERR_NOSUCH_SOCKET (-1)
728#define UDP_ERR_NOTOPEN_TO_WRITE (-2)
729#define UDP_ERR_NOTOPEN_TO_READ (-3)
732 // end of groupUDP
733
734//----- Wrappers to create a UDP socket interface -----
735
758int CreateRxUdpSocket(uint16_t listening_port);
759
760int CreateTxUdpSocket4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port);
761int CreateRxTxUdpSocket4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
762
763#ifdef IPV6
764
765int CreateTxUdpSocket6(const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port);
766
780inline int CreateTxUdpSocket(const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port)
781{
782 return CreateTxUdpSocket6(send_to_addr, remote_port, local_port);
783};
784#else
785inline int CreateTxUdpSocket(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port)
786{
787 return CreateTxUdpSocket4(send_to_addr, remote_port, local_port);
788};
789#endif
790
791#ifdef IPV6
792
793int CreateRxTxUdpSocket6(const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
794
806inline int CreateRxTxUdpSocket(const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
807{
808 return CreateRxTxUdpSocket6(send_to_addr, send_to_remote_port, local_port);
809};
810#else
811inline int CreateRxTxUdpSocket(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
812{
813 return CreateRxTxUdpSocket4(send_to_addr, send_to_remote_port, local_port);
814};
815#endif
816
817int sendto4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port);
818
819#ifdef IPV6
820
821int sendto6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port);
822
836inline int sendto(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port)
837{
838 return sendto6(sock, what_to_send, len_to_send, to_addr, remote_port);
839};
840#else
841inline int sendto(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port)
842{
843 return sendto4(sock, what_to_send, len_to_send, to_addr, remote_port);
844};
845#endif
846
847#if defined MULTIHOME || defined AUTOIP
848
849int sendtovia4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum);
850
851#ifdef IPV6
852int sendtovia6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum);
853[[deprecated]] inline int sendto6via(int sock,
854 puint8_t what_to_send,
855 int len_to_send,
856 const IPADDR &to_addr,
857 uint16_t remote_port,
858 int intfnum)
859{
860 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
861}
862
877inline int sendtovia(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum)
878{
879 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
880};
881#else
882inline int sendtovia(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum)
883{
884 return sendtovia4(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
885};
886#endif
887#endif
888
889int recvfrom4(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
890
891#ifdef IPV6
892
893int recvfrom6(int sock, puint8_t buffer, int len, IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
894
895// If address is IPV4 you get a IPV4 encoded in IPV6 ie ::FFFF.x.x.x.x
910inline int recvfrom(int sock, puint8_t buffer, int len, IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
911{
912 return recvfrom6(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
913};
914#else
915inline int recvfrom(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
916{
917 return recvfrom4(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
918};
919#endif
920
921/* Send a large fragmented UDP packet to is the destination address source_port is the source port dest_port
922 * is the destination port data is the data to send length is the length to send.
923 *
924 * returns 0 on failure, length on success
925 */
926int SendFragmentedUdpPacket4(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length);
927
928#ifdef IPV6
929int SendFragmentedUdpPacket6(const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length);
930
943inline int SendFragmentedUdpPacket(const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
944{
945 return SendFragmentedUdpPacket6(to, source_port, dest_port, data, length);
946};
947#else
948inline int SendFragmentedUdpPacket(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
949{
950 return SendFragmentedUdpPacket4(to, source_port, dest_port, data, length);
951};
952#endif
953
954#ifndef IPV6
955#ifndef IPV4ONLY
956#error Must select an IP version in udp.h
957#endif
958#endif
959
960#ifdef IPV6
961#ifdef IPV4ONLY
962#error Must select IPV4ONLY or IPV6 but not both
963#endif
964#endif
965
966
967
980int CreateRxUdpSocketVia(uint16_t listening_port, int interfacenum);
981
996int CreateRxUdpSocketVia(uint16_t listening_port, const IPADDR interfaceIp);
997
998int CreateTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum);
999int CreateTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, const IPADDR4 interfaceIp);
1000int CreateRxTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum);
1001int CreateRxTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, const IPADDR4 interfaceIp);
1002
1003[[deprecated]] inline int CreateTxUdpSocket4Via(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
1004{
1005 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
1006}
1007[[deprecated]] inline int CreateTxUdpSocket4Via(const IPADDR4 send_to_addr,
1008 uint16_t remote_port,
1009 uint16_t local_port,
1010 const IPADDR4 interfaceIp)
1011{
1012 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
1013}
1014[[deprecated]] inline int CreateRxTxUdpSocket4Via(const IPADDR4 send_to_addr,
1015 uint16_t send_to_remote_port,
1016 uint16_t local_port,
1017 int interfacenum)
1018{
1019 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
1020}
1021[[deprecated]] inline int CreateRxTxUdpSocket4Via(const IPADDR4 send_to_addr,
1022 uint16_t send_to_remote_port,
1023 uint16_t local_port,
1024 const IPADDR4 interfaceIp)
1025{
1026 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1027}
1028
1029#ifdef IPV6
1030int CreateRxTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum);
1031int CreateRxTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, const IPADDR interfaceIp);
1032int CreateTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum);
1033int CreateTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, const IPADDR interfaceIp);
1034
1035[[deprecated]] inline int CreateRxTxUdpSocket6Via(const IPADDR send_to_addr,
1036 uint16_t send_to_remote_port,
1037 uint16_t local_port,
1038 int interfacenum)
1039{
1040 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
1041}
1042[[deprecated]] inline int CreateRxTxUdpSocket6Via(const IPADDR send_to_addr,
1043 uint16_t send_to_remote_port,
1044 uint16_t local_port,
1045 const IPADDR interfaceIp)
1046{
1047 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1048}
1049[[deprecated]] inline int CreateTxUdpSocket6Via(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
1050{
1051 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
1052}
1053[[deprecated]] inline int CreateTxUdpSocket6Via(const IPADDR send_to_addr,
1054 uint16_t remote_port,
1055 uint16_t local_port,
1056 const IPADDR interfaceIp)
1057{
1058 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
1059}
1060
1074inline int CreateRxTxUdpSocketVia(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
1075{
1076 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
1077}
1078
1091inline int CreateRxTxUdpSocketVia(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, IPADDR interfaceIp)
1092{
1093 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1094}
1095
1110inline int CreateTxUdpSocketVia(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
1111{
1112 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
1113}
1114
1130inline int CreateTxUdpSocketVia(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, IPADDR interfaceIp)
1131{
1132 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
1133}
1134#else
1135inline int CreateRxTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
1136{
1137 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
1138}
1139
1140inline int CreateRxTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, IPADDR4 interfaceIp)
1141{
1142 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1143}
1144
1145inline int CreateTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
1146{
1147 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
1148}
1149
1150inline int CreateTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, IPADDR4 interfaceIp)
1151{
1152 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
1153}
1154
1155#endif
1156
1157#endif /* #ifndef _NB_UDP_H_ */
1158
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:168
UDP Packet Class.
Definition udp.h:81
void SendViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl=0)
Send a UDP packet through the network interface specified by the from_ip IP address parameter....
Definition udp.h:565
~UDPPacket()
UDP packet object destructor. Frees any associated memory.
void SendAndKeep(const IPADDR &to, uint8_t ttl=0)
Make a copy of a UDP Packet and send it. The original packet will remain intact.
Definition udp.h:466
IPADDR GetSourceAddress(void)
Get the source IP address a UDP Packet object.
Definition udp.h:285
void Send(const IPADDR &to, uint8_t ttl=0)
Send the UDP Packet and free the pool buffer.
Definition udp.h:477
void SendViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl=0)
Send the UDP Packet using the specified network interface and free the pool buffer.
Definition udp.h:503
void ResetData(void)
Set the data size of a UDP Packet object to 0.
void SetDestinationPort(uint16_t port)
Set the destination port number of a UDP Packet object.
UDPPacket(int sock)
Constructor to create a UDP Packet object from an open UDP socket.
void SetDSCP(uint8_t dscp)
Set the Differentiated Services Code Point (DSCP) value for the packet.
uint16_t GetPacketId(void)
Get UDP packet ID.
void SetSourcePort(uint16_t port)
Set the source port number of a UDP Packet object.
BOOL Validate(void)
Verify a received UDP packet is valid.
void AddData(PCSTR pData)
Add data to a UDP Packet object as a NULL terminated ASCII string.
IPADDR GetDestinationAddress(void)
Get the destination IP address a UDP Packet object.
Definition udp.h:292
MACADR GetMacSource()
Get the source MAC address a UDP Packet object.
UDPPacket(OS_FIFO *pFifo, TickTimeout timeout)
Constructor to create a UDP Packet object from a UDP FIFO entry.
uint16_t GetDataSize(void) const
Get the UDP Packet object data size.
bool bIsIPV6() const
Check if the IPADDR holds an IPv6 IP address.
Definition udp.h:299
uint16_t GetDestinationPort(void) const
Get the destination port number of a UDP Packet object.
uint8_t GetDSCP(void) const
Get the Differentiated Services Code Point (DSCP) value from the packet.
void AddData(puint8_t pData, uint16_t len)
Add a number of data bytes to a UDP Packet object.
void SetDataSize(uint16_t numBytes)
Set the UDP Packet data size.
puint8_t GetDataBuffer(bool bReAllocateIfNeeded=false)
Get a pointer to the UDP Packet object's data buffer.
uint16_t GetSourcePort(void) const
Get the source port number of a UDP Packet object.
void SendAndKeepViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl=0)
Make a copy of a UDP Packet and send it using the specified network interface. The original packet wi...
Definition udp.h:489
UDPPacket(UDPPacket &pkt)
Constructor to create a new UDP packet from an existing UDP packet.
void AddDataWord(uint16_t w)
Add a 16-bit unsigned integer to a UDP Packet object.
void SendAndKeepViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl=0)
Make a copy of a UDP Packet and send it through the network interface specified by the from_ip IP add...
Definition udp.h:550
void AddDataByte(uint8_t b)
Add an 8-bit unsigned integer to a UDP Packet object.
UDPPacket(PoolPtr p)
Constructor to create a UDP packet from a system pool buffer.
void FreeBuffer(PoolPtr nbuf)
Free a buffer and return it to the unused pool.
PIPPKT GetIpPkt(PoolPtr p)
Get IP Packet pointer from network buffer pool buffer.
Definition ip.h:518
PUDPPKT GetUdpPkt(PIPPKT pIp)
Get UPD packet pointer from IP packet pointer.
Definition ip.h:536
uint16_t RegisterEphemeralFifo(OS_FIFO *pfifo, int ifn=-1)
Register a UDP FIFO with a random port number to receive incoming UDP packets.
void UnregisterUDPFifo(uint16_t listenPort, bool drain=false)
Unregister a UDP FIFO.
bool RegisterUDPFifoVia(uint16_t listenPort, OS_FIFO *pFifo, int interface)
Register a FIFO to receive incoming UDP packets on the specified network interface.
bool 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...
bool RegisterUDPFifo(uint16_t listenPort, OS_FIFO *pFifo)
Register a FIFO to receive incoming UDP packets.
bool RegisterUDPFifoWithNotifyVia(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction, int interface)
Register a FIFO to receive incoming UDP packets and a callback function to receive a notification whe...
int recvfrom(int sock, puint8_t buffer, int len, IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
Receive a UDP packet.
Definition udp.h:910
int sendtovia(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum)
Send a UDP packet on the specified interface.
Definition udp.h:877
int sendto(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port)
Send a UDP packet.
Definition udp.h:836
int CreateTxUdpSocket(const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port)
Open a UDP socket for transmitting UDP packets.
Definition udp.h:780
int CreateRxUdpSocketVia(uint16_t listening_port, int interfacenum)
Open a UDP socket for receiving incoming UDP packets on the specified network interface,...
int CreateRxUdpSocket(uint16_t listening_port)
Open a UDP socket for receiving incoming UDP packets.
int CreateRxTxUdpSocket(const IPADDR &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 udp.h:806
int CreateRxTxUdpSocketVia(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
Open a UDP socket that can transmit and receive UDP packets on the local network interface specified ...
Definition udp.h:1074
int SendFragmentedUdpPacket(const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
Send a large fragmented UDP packet.
Definition udp.h:943
int CreateTxUdpSocketVia(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
Open a UDP socket for transmitting UDP packets on the local network interface specified by the interf...
Definition udp.h:1110
NetBurner IP Definitions.
Internal IPv4 Header.
Definition ip.h:120
uint8_t bVerHdrLen
Definition ip.h:121
IPv6 frame processing structure for packet analysis and header walking.
Definition ipv6_interface.h:69
Definition nbrtos.h:932
Internal UDP Header.
Definition ip.h:141
Main buffer structure for network and serial communication.
Definition buffers.h:90