NetBurner 3.5.6
PDF Version
udp.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
53// end of udp.h file tag
54
55
56#ifndef _NB_UDP_H_
57#define _NB_UDP_H_
58
59#include <predef.h>
60#include <ip.h>
61
62
471// Start of groupNBAPI-UDP
472
473
474#ifdef IPV6
475struct IPv6FrameProcessingStruct; // Forward declaration
476#endif
477
478#ifdef IPV6
479struct IP6FRAME;
480#endif
481
482/*
483 * brief Internal UDP socket data structure
484 *
485 * Maintains UDP socket state including receive queue, port bindings, and interface association.
486 * This structure encapsulates all the state information needed to manage a UDP socket in the
487 * NetBurner system, including both BSD socket compatibility (fd) and RTOS-native features (FIFO).
488 *
489 * @warning This is an internal structure - use public API functions instead of direct access
490 * @warning Direct manipulation of these fields may cause socket corruption or memory leaks
491 * @warning Always use CreateRxUdpSocket(), CreateRxTxUdpSocket(), and related functions
492 *
493 * @note This structure bridges BSD sockets and NetBurner's RTOS architecture
494 * @note Each UDP socket maintains its own FIFO for packet queuing
495 * @note The structure supports both connected and unconnected UDP sockets
496 * @note Interface binding allows multi-homed device support
497 *
498 * @par Internal Architecture:
499 * The structure combines several addressing and queuing mechanisms:
500 * - **FIFO Queue**: OS_FIFO for asynchronous packet reception
501 * - **BSD Socket**: File descriptor for select()/poll() compatibility
502 * - **Address Binding**: Local IP address for multi-interface systems
503 * - **Port Management**: Separate receive, local, and remote ports
504 * - **Interface Control**: Specific network interface binding
505 * - **I/O Tracking**: Counter for monitoring socket activity
506 *
507 * @par Port Field Meanings:
508 * | Field | Purpose | Typical Value |
509 * |-------|---------|---------------|
510 * | rxport | Port where packets are received | 1024-65535 or 0 for any |
511 * | lport | Local port for socket operations | Same as rxport typically |
512 * | rport | Remote port (connected sockets only) | 0 for unconnected sockets |
513 *
514 * @par Socket States:
515 * The structure represents different socket states through its fields:
516 * - **Uninitialized**: fd = 0, rxport = 0
517 * - **Bound**: rxport set, address may be bound
518 * - **Connected**: rport set (connected UDP socket)
519 * - **Interface-specific**: ifn != -1
520 *
521 * @par Multi-Interface Support:
522 * The `ifn` field enables binding to specific network interfaces:
523 * - **-1**: Listen on all interfaces (default)
524 * - **0, 1, 2...**: Specific interface number
525 * - Useful for dual Ethernet, WiFi + Ethernet, etc.
526 *
527 * @par Thread Safety:
528 * - The OS_FIFO is thread-safe for packet queuing
529 * - Other fields should not be modified from multiple threads
530 * - Socket operations are internally synchronized by the stack
531 *
532 * @see CreateRxUdpSocket(), CreateRxTxUdpSocket(), RegisterUDPFifo()
533 */
534struct UdpSocketDataSet
535{
536 OS_FIFO the_fifo;
537 int fd = 0;
538 IPADDR address;
539 int ifn;
540 uint16_t rxport = 0;
541 uint16_t lport = 0;
542 uint16_t rport = 0;
543 uint16_t io_counter=0;
544};
545
602{
603 protected:
604 PoolPtr m_p;
605 PUDPPKT m_pPkt;
606
607#ifdef IPV6
608 IP6FRAME *m_pIP6f;
609#endif
610
611#ifdef UDP_FRAGMENTS
612 BOOL m_bIsFragBuffer;
613#endif
614
615 PIPPKT GetIpPacket();
616 int BuildHeaders4(IPADDR4 destIP, IPADDR4 *srcIP, uint8_t ttl);
617 friend PoolPtr CreateDnsResponse4(IPADDR4 serverIp, IPADDR4 clientIp, uint16_t serverPort, uint16_t clientPort, const char *name, IPADDR hostIp, uint32_t ttl);
618 UDPPacket(UDPPacket *pkt,bool clone);
619
620 public:
784 UDPPacket(OS_FIFO *pFifo, TickTimeout timeout);
785 UDPPacket(OS_FIFO *pFifo, uint32_t timeout);
786
1003 UDPPacket(int sock);
1004
1005#ifdef IPV6
1007 void Fix_6_Sb_4();
1008#endif
1009
1164
1338
1339#ifdef IPV6
1498 UDPPacket(bool bIsIpv6 = false);
1499#else
1682 UDPPacket();
1683#endif
1684
1877
2049 inline bool Receive(OS_FIFO *pFifo, uint32_t wait_ticks)
2050 {
2051 if (m_p != 0)
2052 {
2053#ifdef UDP_FRAGMENTS
2054 FragFreeBuffer(m_p);
2055#else
2056 FreeBuffer(m_p);
2057#endif
2058 m_p = NULL;
2059 }
2060
2061 m_p = OSPoolFifoPend(pFifo, wait_ticks);
2062
2063 if (m_p)
2064 {
2065#ifdef UDP_FRAGMENTS
2066 puint8_t pb = (puint8_t)m_p;
2067 if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
2068 {
2069 m_bIsFragBuffer = TRUE;
2070 m_pPkt = (PUDPPKT)(((PIPPKT)(pb + 4))->DATA);
2071 }
2072 else
2073 {
2074 m_bIsFragBuffer = FALSE;
2075 m_pPkt = GetUdpPkt(m_p);
2076 if (m_p)
2077 {
2078#ifdef UDP_FRAGMENTS
2079 puint8_t pb = (puint8_t)m_p;
2080 if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
2081 {
2082 m_bIsFragBuffer = TRUE;
2083 m_pPkt = (PUDPPKT)(((PIPPKT)(pb + 4))->DATA);
2084 }
2085 else
2086 {
2087 m_bIsFragBuffer = FALSE;
2088 m_pPkt = GetUdpPkt(m_p);
2089 }
2090#else
2091 SetUpUdpPkt(m_p);
2092#endif
2093 }
2094 else
2095 {
2096 m_pPkt = NULL;
2097 }
2098 }
2099#else
2100 SetUpUdpPkt(m_p);
2101#endif
2102 }
2103 else
2104 {
2105 m_pPkt = NULL;
2106 }
2107
2108 if (m_p == NULL) return false;
2109 return true;
2110 };
2111
2212 void SetSourcePort(uint16_t port);
2213
2336 uint16_t GetSourcePort(void) const;
2337
2338 IPADDR4 GetSourceAddress4(void);
2339 IPADDR4 GetDestinationAddress4();
2340
2448
2449#ifdef IPV6
2450 IPADDR GetSourceAddress6(void);
2451 IPADDR GetDestinationAddress6();
2452 void SetUpUdpPkt(PoolPtr pp);
2453 PUDPPKT InitUdpPkt(bool IpV6 = false);
2454
2496 inline IPADDR GetSourceAddress(void) { return GetSourceAddress6(); }
2497
2543 inline IPADDR GetDestinationAddress(void) { return GetDestinationAddress6(); }
2544
2599 inline bool bIsIPV6() const { return (m_pIP6f != NULL); }
2600#else
2601 inline IPADDR4 GetSourceAddress(void) { return GetSourceAddress4(); };
2602 inline IPADDR4 GetDestinationAddress() { return GetDestinationAddress4(); }
2603 inline PUDPPKT GetUdpPkt(PoolPtr p) { return ::GetUdpPkt(GetIpPkt(p)); };
2604 inline void SetUpUdpPkt(PoolPtr pp) { m_pPkt = GetUdpPkt(pp); };
2605 inline PUDPPKT GetInitUdpPkt(PIPPKT pIp)
2606 {
2607 pIp->bVerHdrLen = 0x45;
2608 return (PUDPPKT)pIp->DATA;
2609 }
2610 inline PUDPPKT GetInitUdpPkt(PoolPtr p) { return GetInitUdpPkt(GetIpPkt(p)); };
2611#endif
2612
2652 void SetDestinationPort(uint16_t port);
2653
2695 uint16_t GetDestinationPort(void) const;
2696
2741 uint16_t GetPacketId(void);
2742
2759 void SetDSCP(uint8_t dscp);
2760
2801 uint8_t GetDSCP(void) const;
2802
2819 puint8_t GetDataBuffer(bool bReAllocateIfNeeded = false);
2820
2837 void SetDataSize(uint16_t numBytes);
2838
2859 uint16_t GetDataSize(void) const;
2860
2895 void AddData(puint8_t pData, uint16_t len);
2896
2923 void AddData(PCSTR pData);
2924
2946 void AddDataWord(uint16_t w);
2947
2969 void AddDataByte(uint8_t b);
2970
2971
3001 BOOL Validate(void);
3002
3003
3037 void ResetData(void);
3038
3039 void SendAndKeep4(IPADDR4 destIP, uint8_t ttl = 0);
3040 void Send4(IPADDR4 destIP, uint8_t ttl = 0);
3041 void SendAndKeepViaInterfaceNum4(IPADDR4 to, int interface, uint8_t ttl = 0);
3042 void SendViaInterfaceNum4(IPADDR4 destIP, int interface, uint8_t ttl = 0);
3043
3044#ifdef IPV6
3045 void SendAndKeep6(const IPADDR &to, uint8_t ttl = 0);
3046 void Send6(const IPADDR &to, uint8_t ttl = 0);
3047 void SendAndKeepViaInterfaceNum6(const IPADDR &to, int interface, uint8_t ttl = 0);
3048 void SendViaInterfaceNum6(const IPADDR &to, int interface, uint8_t ttl = 0);
3049
3195inline void SendAndKeep(const IPADDR &to, uint8_t ttl = 0) { SendAndKeep6(to, ttl); }
3196
3391inline void Send(const IPADDR &to, uint8_t ttl = 0) { Send6(to, ttl); }
3392
3578inline void SendAndKeepViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl = 0)
3579{
3580 SendAndKeepViaInterfaceNum6(to, interface, ttl);
3581}
3582
3800inline void SendViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl = 0)
3801{
3802 SendViaInterfaceNum6(to, interface, ttl);
3803}
3804#else
3805 inline void SendAndKeep(IPADDR4 to, uint8_t ttl = 0) { SendAndKeep4(to, ttl); };
3806 inline void Send(IPADDR4 to, uint8_t ttl = 0) { Send4(to, ttl); };
3807 inline void SendAndKeepViaInterfaceNum(IPADDR4 to, int interface, uint8_t ttl = 0) { SendAndKeepViaInterfaceNum4(to, interface, ttl); };
3808 inline void SendViaInterfaceNum(IPADDR4 to, int interface, uint8_t ttl = 0) { SendViaInterfaceNum4(to, interface, ttl); };
3809#endif
3810
3811#ifdef UDP_FRAGMENTS
3812 void FragFreeBuffer(PoolPtr mp);
3813 void ReleaseBuffer(void);
3814 PoolPtr GetPoolPtr(void);
3815 void FixTransmitBuffers();
3816#else
3817 void ReleaseBuffer(void)
3818 {
3819 m_p = NULL;
3820 m_pPkt = NULL;
3821#ifdef IPV6
3822 m_pIP6f = NULL;
3823#endif
3824 };
3825 PoolPtr GetPoolPtr(void) { return m_p; };
3826#endif
3827
3828#if defined MULTIHOME || defined AUTOIP
3829 void SendViaIfAddr4(IPADDR4 to, IPADDR4 *from_ip, uint8_t ttl = 0);
3830 void SendViaIfAddrAndNum4(IPADDR4 to, IPADDR4 *from_ip, int interface, uint8_t ttl = 0);
3831 void SendAndKeepViaIfAddr4(IPADDR4 to, IPADDR4 *from_ip, uint8_t ttl = 0);
3832
3833#ifdef IPV6
3834 void SendAndKeepViaIfAddr6(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0);
3835
3852 inline void SendAndKeepViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0) { SendAndKeepViaIfAddr6(to, from_ip, ttl); }
3853
3854 void SendViaIfAddr6(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0);
3855
3872 inline void SendViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl = 0) { SendViaIfAddr(to, from_ip, ttl); };
3873#else
3874 inline void SendAndKeepViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendAndKeepViaIfAddr4(to, &from_ip, ttl); }
3875 inline void SendViaIfAddr(IPADDR4 to, IPADDR4 from_ip, uint8_t ttl = 0) { SendViaIfAddr4(to, &from_ip, ttl); };
3876#endif
3877#endif
3878
3879 bool process_all_udp();
3880
3881 // Destructive copy - transfers ownership
3882 inline void CopyFrom(UDPPacket cpyfrm)
3883 {
3884 if (m_p != 0)
3885 {
3886#ifdef UDP_FRAGMENTS
3887 FragFreeBuffer(m_p);
3888#else
3889 FreeBuffer(m_p);
3890#endif
3891 m_p = NULL;
3892 }
3893 m_p = cpyfrm.m_p;
3894 m_pPkt = cpyfrm.m_pPkt;
3895 cpyfrm.m_p = NULL;
3896 cpyfrm.m_pPkt = NULL;
3897#ifdef IPV6
3898 m_pIP6f = cpyfrm.m_pIP6f;
3899 cpyfrm.m_pIP6f = NULL;
3900#endif
3901#ifdef UDP_FRAGMENTS
3902 m_bIsFragBuffer = cpyFrm.m_bIsFragBuffer;
3903#endif
3904 };
3905
3906 void Swap(UDPPacket &rhs);
3907};
3908
3909#ifdef UDP_FRAGMENTS
3910extern uint8_t pFragmentBuffers[UDP_FRAGMENTS * (65536 + 4)];
3911extern puint8_t pMaxFragmentBuffer;
3912#endif
3913
4002typedef void(udp_data_notify)(OS_FIFO *pfifo, uint16_t port);
4003
4143bool RegisterUDPFifo(uint16_t listenPort, OS_FIFO *pFifo);
4144
4315bool RegisterUDPFifoVia(uint16_t listenPort, OS_FIFO *pFifo, int interface);
4316
4317
4416uint16_t RegisterEphemeralFifo(OS_FIFO *pfifo, int ifn = -1);
4417
4529bool RegisterUDPFifoWithNotify(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction);
4530
4663bool RegisterUDPFifoWithNotifyVia(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction, int interface);
4664
4736void UnregisterUDPFifo(uint16_t listenPort, bool drain = false);
4737
4738void process_udp4(PoolPtr pp, PIPPKT pIP, uint16_t csum);
4739
4740#ifdef IPV6
4742bool process_udp6(IPv6FrameProcessingStruct &p6proc);
4743#endif
4744
4745
4746
4747//========================================================================================================================
4748//========================================================================================================================
4749//========================================================================================================================
4750
4762#define UDP_ERR_NOSUCH_SOCKET (-1)
4763#define UDP_ERR_NOTOPEN_TO_WRITE (-2)
4764#define UDP_ERR_NOTOPEN_TO_READ (-3)
5261// start of groupUDPSocket
5262
5263
5402int CreateRxUdpSocket(uint16_t listening_port);
5403
5404int CreateTxUdpSocket4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port);
5405int CreateRxTxUdpSocket4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
5406
5407#ifdef IPV6
5408int CreateTxUdpSocket6(const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port);
5409
5563inline int CreateTxUdpSocket(const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port)
5564{
5565 return CreateTxUdpSocket6(send_to_addr, remote_port, local_port);
5566};
5567#else
5568inline int CreateTxUdpSocket(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port)
5569{
5570 return CreateTxUdpSocket4(send_to_addr, remote_port, local_port);
5571};
5572#endif
5573
5574#ifdef IPV6
5575int CreateRxTxUdpSocket6(const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
5576
5748inline int CreateRxTxUdpSocket(const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
5749{
5750 return CreateRxTxUdpSocket6(send_to_addr, send_to_remote_port, local_port);
5751};
5752#else
5753inline int CreateRxTxUdpSocket(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
5754{
5755 return CreateRxTxUdpSocket4(send_to_addr, send_to_remote_port, local_port);
5756};
5757#endif
5758
5759int sendto4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port);
5760
5761#ifdef IPV6
5762int sendto6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port);
5763
5876inline int sendto(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port)
5877{
5878 return sendto6(sock, what_to_send, len_to_send, to_addr, remote_port);
5879};
5880#else
5881inline int sendto(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port)
5882{
5883 return sendto4(sock, what_to_send, len_to_send, to_addr, remote_port);
5884};
5885#endif
5886
5887#if defined MULTIHOME || defined AUTOIP
5888int sendtovia4(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum);
5889#ifdef IPV6
5890int sendtovia6(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum);
5891[[deprecated]] inline int sendto6via(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum)
5892{
5893 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
5894}
5895
5899inline int sendtovia(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum)
5900{
5901 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
5902};
5903#else
5904inline int sendtovia(int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum)
5905{
5906 return sendtovia4(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
5907};
5908#endif
5909#endif
5910
5911int recvfrom4(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
5912
5913#ifdef IPV6
5914int recvfrom6(int sock, puint8_t buffer, int len, IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
5915
5960inline int recvfrom(int sock, puint8_t buffer, int len, IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
5961{
5962 return recvfrom6(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
5963};
5964#else
5965inline int recvfrom(int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
5966{
5967 return recvfrom4(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
5968};
5969#endif
5970
5971int SendFragmentedUdpPacket4(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length);
5972
5973#ifdef IPV6
5974int SendFragmentedUdpPacket6(const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length);
5975
6018inline int SendFragmentedUdpPacket(const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
6019{
6020 return SendFragmentedUdpPacket6(to, source_port, dest_port, data, length);
6021}
6022#else
6023inline int SendFragmentedUdpPacket(IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
6024{
6025 return SendFragmentedUdpPacket4(to, source_port, dest_port, data, length);
6026};
6027#endif
6028
6029#ifndef IPV6
6030#ifndef IPV4ONLY
6031#error Must select an IP version in udp.h
6032#endif
6033#endif
6034
6035#ifdef IPV6
6036#ifdef IPV4ONLY
6037#error Must select IPV4ONLY or IPV6 but not both
6038#endif
6039#endif
6040
6041int CreateRxUdpSocketVia(uint16_t listening_port, int interfacenum);
6042int CreateRxUdpSocketVia(uint16_t listening_port, const IPADDR interfaceIp);
6043
6044int CreateTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum);
6045int CreateTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, const IPADDR4 interfaceIp);
6046int CreateRxTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum);
6047int CreateRxTxUdpSocketVia4(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, const IPADDR4 interfaceIp);
6048
6049[[deprecated]] inline int CreateTxUdpSocket4Via(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
6050{
6051 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
6052}
6053[[deprecated]] inline int CreateTxUdpSocket4Via(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, const IPADDR4 interfaceIp)
6054{
6055 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
6056}
6057[[deprecated]] inline int CreateRxTxUdpSocket4Via(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
6058{
6059 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
6060}
6061[[deprecated]] inline int CreateRxTxUdpSocket4Via(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, const IPADDR4 interfaceIp)
6062{
6063 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
6064}
6065
6066#ifdef IPV6
6067int CreateRxTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum);
6068int CreateRxTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, const IPADDR interfaceIp);
6069int CreateTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum);
6070int CreateTxUdpSocketVia6(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, const IPADDR interfaceIp);
6071
6072[[deprecated]] inline int CreateRxTxUdpSocket6Via(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
6073{
6074 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
6075}
6076[[deprecated]] inline int CreateRxTxUdpSocket6Via(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, const IPADDR interfaceIp)
6077{
6078 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
6079}
6080[[deprecated]] inline int CreateTxUdpSocket6Via(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
6081{
6082 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
6083}
6084[[deprecated]] inline int CreateTxUdpSocket6Via(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, const IPADDR interfaceIp)
6085{
6086 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
6087}
6088
6089inline int CreateRxTxUdpSocketVia(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
6090{
6091 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
6092}
6093
6094inline int CreateRxTxUdpSocketVia(const IPADDR send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, IPADDR interfaceIp)
6095{
6096 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
6097}
6098
6099inline int CreateTxUdpSocketVia(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
6100{
6101 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
6102}
6103
6104inline int CreateTxUdpSocketVia(const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port, IPADDR interfaceIp)
6105{
6106 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
6107}
6108#else
6109inline int CreateRxTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, int interfacenum)
6110{
6111 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
6112}
6113
6114inline int CreateRxTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port, IPADDR4 interfaceIp)
6115{
6116 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
6117}
6118
6119inline int CreateTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, int interfacenum)
6120{
6121 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
6122}
6123
6124inline int CreateTxUdpSocketVia(const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port, IPADDR4 interfaceIp)
6125{
6126 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
6127}
6128
6129#endif /* IPV6 */
6130
6131 // groupUdpSocket
6132
6133 // groupNBAPI-UDP
6134
6135#endif /* #ifndef _NB_UDP_H_ */
6136
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
UDP Packet Class - Complete UDP packet management.
Definition udp.h:602
void SendViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl=0)
Send a packet via a specific interface address.
Definition udp.h:3872
~UDPPacket()
Destructor - automatically frees pool buffer.
UDPPacket(bool bIsIpv6=false)
Construct a new UDP packet object.
void SendAndKeep(const IPADDR &to, uint8_t ttl=0)
Send copy, keep original (for sending to multiple destinations)
Definition udp.h:3195
IPADDR GetSourceAddress(void)
Get source IP address of the packet.
Definition udp.h:2496
void Send(const IPADDR &to, uint8_t ttl=0)
Send and free buffer (recommended - most efficient)
Definition udp.h:3391
void SendViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl=0)
Send via specific interface and free buffer.
Definition udp.h:3800
void ResetData(void)
Reset data size to 0 (clears packet)
void SetDestinationPort(uint16_t port)
Set destination port (standard services: 53=DNS, 80=HTTP, 123=NTP, 161=SNMP)
UDPPacket(int sock)
Create UDP packet from socket (blocks until data available)
void SetDSCP(uint8_t dscp)
Set DSCP for QoS (0=best effort, 46=VoIP/EF, 34=video/AF41, 8=bulk/CS1)
uint16_t GetPacketId(void)
Get IP packet ID (used for fragment reassembly and packet tracking)
void SetSourcePort(uint16_t port)
Set source port (0=auto-assign ephemeral port, 1024-65535=specific port)
BOOL Validate(void)
Validate received packet (checks checksum and data presence)
void AddData(PCSTR pData)
Add null-terminated string (includes NULL in packet)
IPADDR GetDestinationAddress(void)
Get destination IP address of the packet.
Definition udp.h:2543
MACADR GetMacSource()
Get sender's MAC address (link-layer identification)
UDPPacket(OS_FIFO *pFifo, TickTimeout timeout)
Create UDP packet from FIFO with timeout.
bool Receive(OS_FIFO *pFifo, uint32_t wait_ticks)
Reuse packet object for multiple receives (efficiency optimization)
Definition udp.h:2049
uint16_t GetDataSize(void) const
Get current data size in bytes.
bool bIsIPV6() const
Check if packet uses IPv6 addressing.
Definition udp.h:2599
uint16_t GetDestinationPort(void) const
Get destination port (for received packets: local port that received it)
uint8_t GetDSCP(void) const
Get DSCP value (0-63)
void AddData(puint8_t pData, uint16_t len)
Add binary data (auto-updates size - no SetDataSize() needed)
void SetDataSize(uint16_t numBytes)
Set data size (REQUIRED after GetDataBuffer() writes)
puint8_t GetDataBuffer(bool bReAllocateIfNeeded=false)
Get data buffer pointer for reading or writing.
uint16_t GetSourcePort(void) const
Get source port from received packet or previously set value.
void SendAndKeepViaInterfaceNum(const IPADDR &to, int interface, uint8_t ttl=0)
Send copy via specific interface, keep original.
Definition udp.h:3578
UDPPacket(UDPPacket &pkt)
Move constructor - transfers ownership.
void AddDataWord(uint16_t w)
Add 16-bit value.
void SendAndKeepViaIfAddr(const IPADDR &to, const IPADDR &from_ip, uint8_t ttl=0)
Send a packet and retain a copy via a specific interface address.
Definition udp.h:3852
void AddDataByte(uint8_t b)
Add 8-bit value.
UDPPacket(PoolPtr p)
Create from raw pool buffer (ADVANCED - rarely needed)
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:632
PUDPPKT GetUdpPkt(PIPPKT pIp)
Get UDP packet pointer from IP packet pointer.
Definition ip.h:676
uint16_t RegisterEphemeralFifo(OS_FIFO *pfifo, int ifn=-1)
Register UDP FIFO on a random unused ephemeral port.
void UnregisterUDPFifo(uint16_t listenPort, bool drain=false)
Unregister UDP FIFO and stop receiving packets on specified port.
bool RegisterUDPFifoVia(uint16_t listenPort, OS_FIFO *pFifo, int interface)
Register FIFO to receive UDP packets on specified port via specific network interface.
bool RegisterUDPFifoWithNotify(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction)
Register UDP FIFO with callback notification on packet arrival.
bool RegisterUDPFifo(uint16_t listenPort, OS_FIFO *pFifo)
Register FIFO to receive UDP packets on specified port.
bool RegisterUDPFifoWithNotifyVia(uint16_t listenPort, OS_FIFO *pFifo, udp_data_notify *pNotifyFunction, int interface)
Register UDP FIFO with callback notification on specific network interface.
void udp_data_notify(OS_FIFO *pfifo, uint16_t port)
UDP packet arrival notification callback function type.
Definition udp.h:4002
int recvfrom(int sock, puint8_t buffer, int len, IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
Receive UDP packet from socket with sender information.
Definition udp.h:5960
int sendtovia(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port, int intfnum)
Send via specific interface.
Definition udp.h:5899
int sendto(int sock, puint8_t what_to_send, int len_to_send, const IPADDR &to_addr, uint16_t remote_port)
Send UDP packet through socket to specified destination.
Definition udp.h:5876
int CreateTxUdpSocket(const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port)
Create transmit-only UDP socket for sending to specified destination.
Definition udp.h:5563
int CreateRxUdpSocket(uint16_t listening_port)
Create receive-only UDP socket bound to specified port.
int CreateRxTxUdpSocket(const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port)
Create bidirectional UDP socket for both sending and receiving.
Definition udp.h:5748
int SendFragmentedUdpPacket(const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data, int length)
Send large UDP packet (>MTU) with IP fragmentation.
Definition udp.h:6018
Internal IPv4 Header Representation.
Definition ip.h:169
uint8_t DATA[]
Flexible array member - payload data follows header (actual length varies by packet)
Definition ip.h:183
uint8_t bVerHdrLen
Version and header length (same as versionNLength in IpHeaderIPv4)
Definition ip.h:170
IPv6 frame processing structure for packet analysis and header walking.
Definition ipv6_interface.h:69
Internal UDP Packet Header Structure.
Definition ip.h:201
Main buffer structure for network and serial communication.
Definition buffers.h:90