34struct UdpSocketDataSet
43 uint16_t io_counter=0;
96 friend PoolPtr CreateDnsResponse4(
IPADDR4 serverIp,
IPADDR4 clientIp, uint16_t serverPort, uint16_t clientPort,
const char *name,
IPADDR hostIp, uint32_t ttl);
179 inline bool Receive(
OS_FIFO *pFifo, uint32_t wait_ticks)
192 m_p = OSPoolFifoPend(pFifo, wait_ticks);
197 puint8_t pb = (puint8_t)m_p;
199 if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
201 m_bIsFragBuffer = TRUE;
206 m_bIsFragBuffer = FALSE;
211 puint8_t pb = (puint8_t)m_p;
213 if ((((puint8_t)m_p) >= pFragmentBuffers) && (((puint8_t)m_p) < pMaxFragmentBuffer))
215 m_bIsFragBuffer = TRUE;
220 m_bIsFragBuffer = FALSE;
241 if (m_p == NULL)
return false;
263 IPADDR4 GetSourceAddress4(
void);
264 IPADDR4 GetDestinationAddress4();
274 IPADDR GetSourceAddress6(
void);
275 IPADDR GetDestinationAddress6();
278 PUDPPKT InitUdpPkt(
bool IpV6 =
false);
299 inline bool bIsIPV6()
const {
return (m_pIP6f != NULL); };
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);
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);
477 inline void Send(
const IPADDR &to, uint8_t ttl = 0) { Send6(to, ttl); };
491 SendAndKeepViaInterfaceNum6(to, interface, ttl);
507 inline void Send(
IPADDR4 to, uint8_t ttl = 0) { Send4(to, ttl); };
513 void FragFreeBuffer(
PoolPtr mp);
514 void ReleaseBuffer(
void);
516 void FixTransmitBuffers();
518 void ReleaseBuffer(
void)
528 PoolPtr GetPoolPtr(
void) {
return m_p; };
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);
537 void SendAndKeepViaIfAddr6(
const IPADDR &to,
const IPADDR &from_ip, uint8_t ttl = 0);
552 void SendViaIfAddr6(
const IPADDR &to,
const IPADDR &from_ip, uint8_t ttl = 0);
574 bool process_all_udp();
593 m_pPkt = cpyfrm.m_pPkt;
595 cpyfrm.m_pPkt = NULL;
598 m_pIP6f = cpyfrm.m_pIP6f;
599 cpyfrm.m_pIP6f = NULL;
603 m_bIsFragBuffer = cpyFrm.m_bIsFragBuffer;
612extern uint8_t pFragmentBuffers[UDP_FRAGMENTS * (65536 + 4)];
613extern puint8_t pMaxFragmentBuffer;
616typedef void(udp_data_notify)(
OS_FIFO *pfifo, uint16_t port);
727#define UDP_ERR_NOSUCH_SOCKET (-1)
728#define UDP_ERR_NOTOPEN_TO_WRITE (-2)
729#define UDP_ERR_NOTOPEN_TO_READ (-3)
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);
765int CreateTxUdpSocket6(
const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port);
782 return CreateTxUdpSocket6(send_to_addr, remote_port, local_port);
787 return CreateTxUdpSocket4(send_to_addr, remote_port, local_port);
793int CreateRxTxUdpSocket6(
const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
808 return CreateRxTxUdpSocket6(send_to_addr, send_to_remote_port, local_port);
813 return CreateRxTxUdpSocket4(send_to_addr, send_to_remote_port, local_port);
817int sendto4(
int sock, puint8_t what_to_send,
int len_to_send,
IPADDR4 to_addr, uint16_t remote_port);
821int sendto6(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR &to_addr, uint16_t remote_port);
836inline int sendto(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR &to_addr, uint16_t remote_port)
838 return sendto6(sock, what_to_send, len_to_send, to_addr, remote_port);
841inline int sendto(
int sock, puint8_t what_to_send,
int len_to_send,
IPADDR4 to_addr, uint16_t remote_port)
843 return sendto4(sock, what_to_send, len_to_send, to_addr, remote_port);
847#if defined MULTIHOME || defined AUTOIP
849int sendtovia4(
int sock, puint8_t what_to_send,
int len_to_send,
IPADDR4 to_addr, uint16_t remote_port,
int intfnum);
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,
857 uint16_t remote_port,
860 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
877inline int sendtovia(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR &to_addr, uint16_t remote_port,
int intfnum)
879 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
882inline int sendtovia(
int sock, puint8_t what_to_send,
int len_to_send,
IPADDR4 to_addr, uint16_t remote_port,
int intfnum)
884 return sendtovia4(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
889int recvfrom4(
int sock, puint8_t buffer,
int len,
IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
893int recvfrom6(
int sock, puint8_t buffer,
int len,
IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
910inline int recvfrom(
int sock, puint8_t buffer,
int len,
IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
912 return recvfrom6(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
915inline int recvfrom(
int sock, puint8_t buffer,
int len,
IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
917 return recvfrom4(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
926int SendFragmentedUdpPacket4(
IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data,
int length);
929int SendFragmentedUdpPacket6(
const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data,
int length);
945 return SendFragmentedUdpPacket6(to, source_port, dest_port, data, length);
950 return SendFragmentedUdpPacket4(to, source_port, dest_port, data, length);
956#error Must select an IP version in udp.h
962#error Must select IPV4ONLY or IPV6 but not both
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);
1003[[deprecated]]
inline int CreateTxUdpSocket4Via(
const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port,
int interfacenum)
1005 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
1007[[deprecated]]
inline int CreateTxUdpSocket4Via(
const IPADDR4 send_to_addr,
1008 uint16_t remote_port,
1009 uint16_t local_port,
1012 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
1014[[deprecated]]
inline int CreateRxTxUdpSocket4Via(
const IPADDR4 send_to_addr,
1015 uint16_t send_to_remote_port,
1016 uint16_t local_port,
1019 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
1021[[deprecated]]
inline int CreateRxTxUdpSocket4Via(
const IPADDR4 send_to_addr,
1022 uint16_t send_to_remote_port,
1023 uint16_t local_port,
1026 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
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);
1035[[deprecated]]
inline int CreateRxTxUdpSocket6Via(
const IPADDR send_to_addr,
1036 uint16_t send_to_remote_port,
1037 uint16_t local_port,
1040 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
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)
1047 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1049[[deprecated]]
inline int CreateTxUdpSocket6Via(
const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port,
int interfacenum)
1051 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
1053[[deprecated]]
inline int CreateTxUdpSocket6Via(
const IPADDR send_to_addr,
1054 uint16_t remote_port,
1055 uint16_t local_port,
1056 const IPADDR interfaceIp)
1058 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
1076 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
1093 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1112 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
1132 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
1137 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
1142 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1147 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
1152 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
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
Internal UDP Header.
Definition ip.h:141
Main buffer structure for network and serial communication.
Definition buffers.h:90