NetBurner 3.5.0
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
138 UDPPacket(IPv6FrameProcessingStruct &p6);
139 void Fix_6_Sb_4();
140#endif
141
152 UDPPacket(PoolPtr p);
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() { 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
348 puint8_t GetDataBuffer(bool bReAllocateIfNeeded = false);
349
357 void SetDataSize(uint16_t numBytes);
358
366 uint16_t GetDataSize(void) const;
367
376 void AddData(puint8_t pData, uint16_t len);
377
385 void AddData(PCSTR pData);
386
394 void AddDataWord(uint16_t w);
395
403 void AddDataByte(uint8_t b);
404
413 BOOL Validate(void); // Check the Checksum
414
419 void ResetData(void); // Zero the data buffer and return.
420
421 void SendAndKeep4(IPADDR4 destIP, uint8_t ttl = 0);
422 void Send4(IPADDR4 destIP, uint8_t ttl = 0);
423 void SendAndKeepViaInterfaceNum4(IPADDR4 to, int interface, uint8_t ttl = 0);
424 void SendViaInterfaceNum4(IPADDR4 destIP, int interface, uint8_t ttl = 0);
425
426#ifdef IPV6
427 void SendAndKeep6(const IPADDR &to, uint8_t ttl = 0);
428 void Send6(const IPADDR &to, uint8_t ttl = 0);
429 void SendAndKeepViaInterfaceNum6(const IPADDR &to, int interface, uint8_t ttl = 0);
430 void SendViaInterfaceNum6(const IPADDR &to, int interface, uint8_t ttl = 0);
431
440 inline void SendAndKeep(const IPADDR &to, uint8_t ttl = 0) { SendAndKeep6(to, ttl); };
441
451 inline void Send(const IPADDR &to, uint8_t ttl = 0) { Send6(to, ttl); };
452
463 inline void SendAndKeepViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl = 0)
464 {
465 SendAndKeepViaInterfaceNum6(to, interface, ttl);
466 }
467
477 inline void SendViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl = 0) { SendViaInterfaceNum6(to, interface, ttl); };
478
479#else
480 inline void SendAndKeep(IPADDR4 to, uint8_t ttl = 0) { SendAndKeep4(to, ttl); };
481 inline void Send(IPADDR4 to, uint8_t ttl = 0) { Send4(to, ttl); };
482 inline void SendAndKeepViaInterfaceNum(IPADDR4 to, int interface, uint8_t ttl = 0) { SendAndKeepViaInterfaceNum4(to, interface, ttl); };
483 inline void SendViaInterfaceNum(IPADDR4 to, int interface, uint8_t ttl = 0) { SendViaInterfaceNum4(to, interface, ttl); };
484#endif
485
486#ifdef UDP_FRAGMENTS
487 void FragFreeBuffer(PoolPtr mp);
488 void ReleaseBuffer(void);
489 PoolPtr GetPoolPtr(void);
490 void FixTransmitBuffers();
491#else
492 void ReleaseBuffer(void)
493 {
494 m_p = NULL;
495 m_pPkt = NULL;
496
497#ifdef IPV6
498 m_pIP6f = NULL;
499#endif
500 };
501
502 PoolPtr GetPoolPtr(void) { return m_p; };
503#endif
504
505#if defined MULTIHOME || defined AUTOIP
506 void SendViaIfAddr4(IPADDR4 to, IPADDR4 *from_ip, uint8_t ttl = 0);
507 void SendViaIfAddrAndNum4(IPADDR4 to, IPADDR4 *from_ip, int interface, uint8_t ttl = 0);
508 void SendAndKeepViaIfAddr4(IPADDR4 to, IPADDR4 *from_ip, uint8_t ttl = 0);
509
510#ifdef IPV6
511 void SendAndKeepViaIfAddr6(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0);
512
524 inline void SendAndKeepViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0) { SendAndKeepViaIfAddr6(to, from_ip, ttl); }
525 // Send destroys the data in the packet.
526 void SendViaIfAddr6(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0);
527
539 inline void SendViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0) { SendViaIfAddr(to, from_ip, ttl); };
540#else
541 // Send and keep makes a copy of this UDP packet and sends it.
542 inline void SendAndKeepViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendAndKeepViaIfAddr4(to, &from_ip, ttl); }
543 // Send destroys the data in the packet.
544 inline void SendViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendViaIfAddr4(to, &from_ip, ttl); };
545#endif //
546#endif // Multi home
547
548 bool process_all_udp();
549
550 // Uncomment when C++11 is enabled.
551 // UDPPacket & operator = (const UDPPacket & pf) =delete;
552
553 // Destructive Copy constructor destroys other UdpPacket
554 inline void CopyFrom(UDPPacket cpyfrm)
555 {
556 if (m_p != 0)
557 {
558#ifdef UDP_FRAGMENTS
559 FragFreeBuffer(m_p);
560#else
561 FreeBuffer(m_p);
562#endif
563
564 m_p = NULL;
565 }
566 m_p = cpyfrm.m_p;
567 m_pPkt = cpyfrm.m_pPkt;
568 cpyfrm.m_p = NULL;
569 cpyfrm.m_pPkt = NULL;
570
571#ifdef IPV6
572 m_pIP6f = cpyfrm.m_pIP6f;
573 cpyfrm.m_pIP6f = NULL;
574#endif
575
576#ifdef UDP_FRAGMENTS
577 m_bIsFragBuffer = cpyFrm.m_bIsFragBuffer;
578#endif
579 };
580
581 void Swap(UDPPacket &rhs);
582
583}; // end of UDPPacket Class
584
585#ifdef UDP_FRAGMENTS
586extern uint8_t pFragmentBuffers[UDP_FRAGMENTS * (65536 + 4)];
587extern puint8_t pMaxFragmentBuffer;
588#endif
589
590typedef void(udp_data_notify)(OS_FIFO *pfifo, uint16_t port);
591
605bool RegisterUDPFifo(uint16_t listenPort, OS_FIFO *pFifo);
606
621bool RegisterUDPFifoVia(uint16_t listenPort, OS_FIFO *pFifo, int interface);
622
638uint16_t RegisterEphemeralFifo(OS_FIFO *pfifo, int ifn = -1);
639
656bool RegisterUDPFifoWithNotify(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction);
657
676bool RegisterUDPFifoWithNotifyVia(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction, int interface);
677
686void UnregisterUDPFifo(uint16_t listenPort, bool drain = false);
687
688// INTERNAL FUNCTIONS. Used by the ip.cpp process packet functions
689
690void process_udp4(PoolPtr pp, PIPPKT pIP, uint16_t csum);
691
692#ifdef IPV6
693struct IPv6FrameProcessingStruct; // Forward
694bool process_udp6(IPv6FrameProcessingStruct &p6proc);
695#endif
696
701#define UDP_ERR_NOSUCH_SOCKET (-1)
702#define UDP_ERR_NOTOPEN_TO_WRITE (-2)
703#define UDP_ERR_NOTOPEN_TO_READ (-3)
706 // end of groupUDP
707
708//----- Wrappers to create a UDP socket interface -----
709
732int CreateRxUdpSocket(uint16_t listening_port);
733
734int CreateTxUdpSocket4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port);
735int CreateRxTxUdpSocket4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
736
737#ifdef IPV6
738
739int CreateTxUdpSocket6(const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port);
740
754inline int CreateTxUdpSocket(const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port)
755{
756 return CreateTxUdpSocket6(send_to_addr, remote_port, local_port);
757};
758#else
759inline int CreateTxUdpSocket(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port)
760{
761 return CreateTxUdpSocket4(send_to_addr, remote_port, local_port);
762};
763#endif
764
765#ifdef IPV6
766
767int CreateRxTxUdpSocket6(const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
768
780inline int CreateRxTxUdpSocket(const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
781{
782 return CreateRxTxUdpSocket6(send_to_addr, send_to_remote_port, local_port);
783};
784#else
785inline int CreateRxTxUdpSocket(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
786{
787 return CreateRxTxUdpSocket4(send_to_addr, send_to_remote_port, local_port);
788};
789#endif
790
791int sendto4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port);
792
793#ifdef IPV6
794
795int sendto6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port);
796
810inline int sendto(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port)
811{
812 return sendto6(sock, what_to_send, len_to_send, to_addr, remote_port);
813};
814#else
815inline int sendto(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port)
816{
817 return sendto4(sock, what_to_send, len_to_send, to_addr, remote_port);
818};
819#endif
820
821#if defined MULTIHOME || defined AUTOIP
822
823int sendtovia4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum);
824
825#ifdef IPV6
826int sendtovia6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum);
827[[deprecated]] inline int sendto6via(int sock,
828 puint8_t what_to_send,
829 int len_to_send,
830 const IPADDR &to_addr,
831 uint16_t remote_port,
832 int intfnum)
833{
834 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
835}
836
851inline int sendtovia(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum)
852{
853 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
854};
855#else
856inline int sendtovia(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum)
857{
858 return sendtovia4(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
859};
860#endif
861#endif
862
863int recvfrom4(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
864
865#ifdef IPV6
866
867int recvfrom6(int sock, puint8_t buffer, int len, IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
868
869// If address is IPV4 you get a IPV4 encoded in IPV6 ie ::FFFF.x.x.x.x
884inline int recvfrom(int sock, puint8_t buffer, int len, IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
885{
886 return recvfrom6(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
887};
888#else
889inline int recvfrom(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
890{
891 return recvfrom4(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
892};
893#endif
894
895/* Send a large fragmented UDP packet to is the destination address source_port is the source port dest_port
896 * is the destination port data is the data to send length is the length to send.
897 *
898 * returns 0 on failure, length on success
899 */
900int SendFragmentedUdpPacket4(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length);
901
902#ifdef IPV6
903int SendFragmentedUdpPacket6(const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length);
904
917inline int SendFragmentedUdpPacket(const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
918{
919 return SendFragmentedUdpPacket6(to, source_port, dest_port, data, length);
920};
921#else
922inline int SendFragmentedUdpPacket(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
923{
924 return SendFragmentedUdpPacket4(to, source_port, dest_port, data, length);
925};
926#endif
927
928#ifndef IPV6
929#ifndef IPV4ONLY
930#error Must select an IP version in udp.h
931#endif
932#endif
933
946int CreateRxUdpSocketVia(uint16_t listening_port, int interfacenum);
947
962int CreateRxUdpSocketVia(uint16_t listening_port, const IPADDR interfaceIp);
963
964int CreateTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum);
965int CreateTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, const IPADDR4 interfaceIp);
966int CreateRxTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum);
967int CreateRxTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, const IPADDR4 interfaceIp);
968
969[[deprecated]] inline int CreateTxUdpSocket4Via(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
970{
971 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
972}
973[[deprecated]] inline int CreateTxUdpSocket4Via(const IPADDR4 send_to_addr,
974 uint16_t remote_port,
975 uint16_t local_port,
976 const IPADDR4 interfaceIp)
977{
978 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
979}
980[[deprecated]] inline int CreateRxTxUdpSocket4Via(const IPADDR4 send_to_addr,
981 uint16_t send_to_remote_port,
982 uint16_t local_port,
983 int interfacenum)
984{
985 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
986}
987[[deprecated]] inline int CreateRxTxUdpSocket4Via(const IPADDR4 send_to_addr,
988 uint16_t send_to_remote_port,
989 uint16_t local_port,
990 const IPADDR4 interfaceIp)
991{
992 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
993}
994
995#ifdef IPV6
996int CreateRxTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum);
997int CreateRxTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, const IPADDR interfaceIp);
998int CreateTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum);
999int CreateTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, const IPADDR interfaceIp);
1000
1001[[deprecated]] inline int CreateRxTxUdpSocket6Via(const IPADDR send_to_addr,
1002 uint16_t send_to_remote_port,
1003 uint16_t local_port,
1004 int interfacenum)
1005{
1006 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
1007}
1008[[deprecated]] inline int CreateRxTxUdpSocket6Via(const IPADDR send_to_addr,
1009 uint16_t send_to_remote_port,
1010 uint16_t local_port,
1011 const IPADDR interfaceIp)
1012{
1013 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1014}
1015[[deprecated]] inline int CreateTxUdpSocket6Via(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
1016{
1017 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
1018}
1019[[deprecated]] inline int CreateTxUdpSocket6Via(const IPADDR send_to_addr,
1020 uint16_t remote_port,
1021 uint16_t local_port,
1022 const IPADDR interfaceIp)
1023{
1024 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
1025}
1026
1040inline int CreateRxTxUdpSocketVia(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
1041{
1042 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
1043}
1044
1057inline int CreateRxTxUdpSocketVia(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, IPADDR interfaceIp)
1058{
1059 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1060}
1061
1076inline int CreateTxUdpSocketVia(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
1077{
1078 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
1079}
1080
1096inline int CreateTxUdpSocketVia(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, IPADDR interfaceIp)
1097{
1098 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
1099}
1100#else
1101inline int CreateRxTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
1102{
1103 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
1104}
1105
1106inline int CreateRxTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, IPADDR4 interfaceIp)
1107{
1108 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1109}
1110
1111inline int CreateTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
1112{
1113 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
1114}
1115
1116inline int CreateTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, IPADDR4 interfaceIp)
1117{
1118 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
1119}
1120
1121#endif
1122
1123#endif /* #ifndef _NB_UDP_H_ */
1124
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:208
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:157
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:539
bool bIsIPV6()
Check if the IPADDR holds an IPv6 IP address.
Definition udp.h:299
~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:440
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:451
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:477
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.
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.
uint16_t GetDestinationPort(void) const
Get the destination port number of a UDP Packet object.
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:463
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:524
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.
PIPPKT GetIpPkt(PoolPtr p)
Get IP Packet pointer from network buffer pool buffer.
Definition ip.h:260
PUDPPKT GetUdpPkt(PIPPKT pIp)
Get UPD packet pointer from IP packet pointer.
Definition ip.h:278
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:884
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:851
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:810
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:754
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:780
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:1040
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:917
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:1076
NetBurner IP Definitions.
Internal IPv4 Header.
Definition ip.h:120
uint8_t bVerHdrLen
Definition ip.h:121
Definition nbrtos.h:907
Internal UDP Header.
Definition ip.h:141