27struct IPv6FrameProcessingStruct;
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);
138 UDPPacket(IPv6FrameProcessingStruct &p6);
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();
277 void SetUpUdpPkt(PoolPtr pp);
278 PUDPPKT InitUdpPkt(
bool IpV6 =
false);
299 inline bool bIsIPV6() {
return (m_pIP6f != NULL); };
307 inline void SetUpUdpPkt(PoolPtr pp) { m_pPkt =
GetUdpPkt(pp); };
315 inline PUDPPKT GetInitUdpPkt(PoolPtr p) {
return GetInitUdpPkt(
GetIpPkt(p)); };
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);
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);
451 inline void Send(
const IPADDR &to, uint8_t ttl = 0) { Send6(to, ttl); };
465 SendAndKeepViaInterfaceNum6(to, interface, ttl);
481 inline void Send(
IPADDR4 to, uint8_t ttl = 0) { Send4(to, ttl); };
487 void FragFreeBuffer(PoolPtr mp);
488 void ReleaseBuffer(
void);
489 PoolPtr GetPoolPtr(
void);
490 void FixTransmitBuffers();
492 void ReleaseBuffer(
void)
502 PoolPtr GetPoolPtr(
void) {
return m_p; };
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);
511 void SendAndKeepViaIfAddr6(
const IPADDR &to,
const IPADDR &from_ip, uint8_t ttl = 0);
526 void SendViaIfAddr6(
const IPADDR &to,
const IPADDR &from_ip, uint8_t ttl = 0);
548 bool process_all_udp();
567 m_pPkt = cpyfrm.m_pPkt;
569 cpyfrm.m_pPkt = NULL;
572 m_pIP6f = cpyfrm.m_pIP6f;
573 cpyfrm.m_pIP6f = NULL;
577 m_bIsFragBuffer = cpyFrm.m_bIsFragBuffer;
586extern uint8_t pFragmentBuffers[UDP_FRAGMENTS * (65536 + 4)];
587extern puint8_t pMaxFragmentBuffer;
590typedef void(udp_data_notify)(
OS_FIFO *pfifo, uint16_t port);
690void process_udp4(PoolPtr pp,
PIPPKT pIP, uint16_t csum);
693struct IPv6FrameProcessingStruct;
694bool process_udp6(IPv6FrameProcessingStruct &p6proc);
701#define UDP_ERR_NOSUCH_SOCKET (-1)
702#define UDP_ERR_NOTOPEN_TO_WRITE (-2)
703#define UDP_ERR_NOTOPEN_TO_READ (-3)
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);
739int CreateTxUdpSocket6(
const IPADDR &send_to_addr, uint16_t remote_port, uint16_t local_port);
756 return CreateTxUdpSocket6(send_to_addr, remote_port, local_port);
761 return CreateTxUdpSocket4(send_to_addr, remote_port, local_port);
767int CreateRxTxUdpSocket6(
const IPADDR &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port);
782 return CreateRxTxUdpSocket6(send_to_addr, send_to_remote_port, local_port);
787 return CreateRxTxUdpSocket4(send_to_addr, send_to_remote_port, local_port);
791int sendto4(
int sock, puint8_t what_to_send,
int len_to_send,
IPADDR4 to_addr, uint16_t remote_port);
795int sendto6(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR &to_addr, uint16_t remote_port);
810inline int sendto(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR &to_addr, uint16_t remote_port)
812 return sendto6(sock, what_to_send, len_to_send, to_addr, remote_port);
815inline int sendto(
int sock, puint8_t what_to_send,
int len_to_send,
IPADDR4 to_addr, uint16_t remote_port)
817 return sendto4(sock, what_to_send, len_to_send, to_addr, remote_port);
821#if defined MULTIHOME || defined AUTOIP
823int sendtovia4(
int sock, puint8_t what_to_send,
int len_to_send,
IPADDR4 to_addr, uint16_t remote_port,
int intfnum);
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,
831 uint16_t remote_port,
834 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
851inline int sendtovia(
int sock, puint8_t what_to_send,
int len_to_send,
const IPADDR &to_addr, uint16_t remote_port,
int intfnum)
853 return sendtovia6(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
856inline int sendtovia(
int sock, puint8_t what_to_send,
int len_to_send,
IPADDR4 to_addr, uint16_t remote_port,
int intfnum)
858 return sendtovia4(sock, what_to_send, len_to_send, to_addr, remote_port, intfnum);
863int recvfrom4(
int sock, puint8_t buffer,
int len,
IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
867int recvfrom6(
int sock, puint8_t buffer,
int len,
IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port);
884inline int recvfrom(
int sock, puint8_t buffer,
int len,
IPADDR *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
886 return recvfrom6(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
889inline int recvfrom(
int sock, puint8_t buffer,
int len,
IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port)
891 return recvfrom4(sock, buffer, len, pAddr, pLocal_port, pRemote_port);
900int SendFragmentedUdpPacket4(
IPADDR4 to, uint16_t source_port, uint16_t dest_port, puint8_t data,
int length);
903int SendFragmentedUdpPacket6(
const IPADDR &to, uint16_t source_port, uint16_t dest_port, puint8_t data,
int length);
919 return SendFragmentedUdpPacket6(to, source_port, dest_port, data, length);
924 return SendFragmentedUdpPacket4(to, source_port, dest_port, data, length);
930#error Must select an IP version in udp.h
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);
969[[deprecated]]
inline int CreateTxUdpSocket4Via(
const IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port,
int interfacenum)
971 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
973[[deprecated]]
inline int CreateTxUdpSocket4Via(
const IPADDR4 send_to_addr,
974 uint16_t remote_port,
978 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
980[[deprecated]]
inline int CreateRxTxUdpSocket4Via(
const IPADDR4 send_to_addr,
981 uint16_t send_to_remote_port,
985 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
987[[deprecated]]
inline int CreateRxTxUdpSocket4Via(
const IPADDR4 send_to_addr,
988 uint16_t send_to_remote_port,
992 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
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);
1001[[deprecated]]
inline int CreateRxTxUdpSocket6Via(
const IPADDR send_to_addr,
1002 uint16_t send_to_remote_port,
1003 uint16_t local_port,
1006 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
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)
1013 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1015[[deprecated]]
inline int CreateTxUdpSocket6Via(
const IPADDR send_to_addr, uint16_t remote_port, uint16_t local_port,
int interfacenum)
1017 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
1019[[deprecated]]
inline int CreateTxUdpSocket6Via(
const IPADDR send_to_addr,
1020 uint16_t remote_port,
1021 uint16_t local_port,
1022 const IPADDR interfaceIp)
1024 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
1042 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfacenum);
1059 return CreateRxTxUdpSocketVia6(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1078 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfacenum);
1098 return CreateTxUdpSocketVia6(send_to_addr, remote_port, local_port, interfaceIp);
1103 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfacenum);
1108 return CreateRxTxUdpSocketVia4(send_to_addr, send_to_remote_port, local_port, interfaceIp);
1113 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfacenum);
1118 return CreateTxUdpSocketVia4(send_to_addr, remote_port, local_port, interfaceIp);
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
Internal UDP Header.
Definition ip.h:141