NetBurner 3.5.6
PDF Version |
UDP Packet Class. More...
#include <udp.h>
Public Member Functions | |
UDPPacket (OS_FIFO *pFifo, TickTimeout timeout) | |
Constructor to create a UDP Packet object from a UDP FIFO entry. | |
UDPPacket (int sock) | |
Constructor to create a UDP Packet object from an open UDP socket. | |
UDPPacket (PoolPtr p) | |
Constructor to create a UDP packet from a system pool buffer. | |
UDPPacket (UDPPacket &pkt) | |
Constructor to create a new UDP packet from an existing UDP packet. | |
~UDPPacket () | |
UDP packet object destructor. Frees any associated memory. | |
void | SetSourcePort (uint16_t port) |
Set the source port number of a UDP Packet object. | |
uint16_t | GetSourcePort (void) const |
Get the source port number of a UDP Packet object. | |
MACADR | GetMacSource () |
Get the source MAC address a UDP Packet object. | |
IPADDR | GetSourceAddress (void) |
Get the source IP address a UDP Packet object. | |
IPADDR | GetDestinationAddress (void) |
Get the destination IP address a UDP Packet object. | |
bool | bIsIPV6 () const |
Check if the IPADDR holds an IPv6 IP address. | |
void | SetDestinationPort (uint16_t port) |
Set the destination port number of a UDP Packet object. | |
uint16_t | GetDestinationPort (void) const |
Get the destination port number of a UDP Packet object. | |
uint16_t | GetPacketId (void) |
Get UDP packet ID. | |
void | SetDSCP (uint8_t dscp) |
Set the Differentiated Services Code Point (DSCP) value for the packet. | |
uint8_t | GetDSCP (void) const |
Get the Differentiated Services Code Point (DSCP) value from the packet. | |
puint8_t | GetDataBuffer (bool bReAllocateIfNeeded=false) |
Get a pointer to the UDP Packet object's data buffer. | |
void | SetDataSize (uint16_t numBytes) |
Set the UDP Packet data size. | |
uint16_t | GetDataSize (void) const |
Get the UDP Packet object data size. | |
void | AddData (puint8_t pData, uint16_t len) |
Add a number of data bytes to a UDP Packet object. | |
void | AddData (PCSTR pData) |
Add data to a UDP Packet object as a NULL terminated ASCII string. | |
void | AddDataWord (uint16_t w) |
Add a 16-bit unsigned integer to a UDP Packet object. | |
void | AddDataByte (uint8_t b) |
Add an 8-bit unsigned integer to a UDP Packet object. | |
BOOL | Validate (void) |
Verify a received UDP packet is valid. | |
void | ResetData (void) |
Set the data size of a UDP Packet object to 0. | |
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. | |
void | Send (const IPADDR &to, uint8_t ttl=0) |
Send the UDP Packet and free the pool buffer. | |
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 will remain intact. | |
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. | |
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 address parameter. If more than one interface has the same IP address, the lower interface number will be used. The original packet will remain intact. | |
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. If more than one interface has the same IP address, the lower interface number will be used. The UDP pool buffer will be freed. | |
UDP Packet Class.
This class holds PoolBuffers and treats them as UDP Packets. The process for sending a UDP packet is as follows:
Data can be put in the packet two ways:
When the UDP packet has been configured it can be sent two ways:
SendAndKeep(IPADDR destinationIP);
. You must free the buffer manually.Send(IPADDR4 destinationIP);
There are many UDP examples, and we recommend reviewing them to determine the best method to use for your application.
UDPPacket::UDPPacket | ( | OS_FIFO * | pFifo, |
TickTimeout | timeout ) |
Constructor to create a UDP Packet object from a UDP FIFO entry.
UDP packets are received in a OS_FIFO. This constructor create a UDP packet from the next entry in the FIFO, which also removes the entry from the FIFO. If there is not a packet in the FIFO, this constructor will block until one is available, or the specified timeout occurs. If a timeout occurs, an invalid UDP packet will be created. The UDP Validate() function must always be called after this constructor to verify a valid UDP packet has been created.
pFifo | Pointer to an OS_FIFO object |
timeout | Timeout in system Time Ticks |
UDPPacket::UDPPacket | ( | int | sock | ) |
Constructor to create a UDP Packet object from an open UDP socket.
This constructor will block until a UDP packet is received. It is useful for situations such as a select() call that will block on a UDP file descriptor until a packet is received. After the select() returns, this constructor can be used to create the packet.
sock | Open UDP socket |
UDPPacket::UDPPacket | ( | PoolPtr | p | ) |
Constructor to create a UDP packet from a system pool buffer.
This constructor can be used in unique situations in which an application is operating directly on the system pool buffers. This is a rare situation.
p | Pointer to a pool buffer |
UDPPacket::UDPPacket | ( | UDPPacket & | pkt | ) |
Constructor to create a new UDP packet from an existing UDP packet.
The UDP packet passed in the argument will be destroyed.
pkt | UDP packet object |
UDPPacket::~UDPPacket | ( | ) |
UDP packet object destructor. Frees any associated memory.
void UDPPacket::AddData | ( | PCSTR | pData | ) |
Add data to a UDP Packet object as a NULL terminated ASCII string.
pData | Pointer to the null terminated string |
void UDPPacket::AddData | ( | puint8_t | pData, |
uint16_t | len ) |
Add a number of data bytes to a UDP Packet object.
pData | Pointer to the data to add |
len | Number of bytes |
void UDPPacket::AddDataByte | ( | uint8_t | b | ) |
Add an 8-bit unsigned integer to a UDP Packet object.
b | 8-bit unsigned integer |
void UDPPacket::AddDataWord | ( | uint16_t | w | ) |
Add a 16-bit unsigned integer to a UDP Packet object.
w | 16 bit unsigned integer |
|
inline |
Check if the IPADDR holds an IPv6 IP address.
puint8_t UDPPacket::GetDataBuffer | ( | bool | bReAllocateIfNeeded = false | ) |
Get a pointer to the UDP Packet object's data buffer.
uint16_t UDPPacket::GetDataSize | ( | void | ) | const |
|
inline |
Get the destination IP address a UDP Packet object.
uint16_t UDPPacket::GetDestinationPort | ( | void | ) | const |
Get the destination port number of a UDP Packet object.
uint8_t UDPPacket::GetDSCP | ( | void | ) | const |
Get the Differentiated Services Code Point (DSCP) value from the packet.
Retrieves the DSCP value from the IP header. This method works transparently for both IPv4 and IPv6 packets. For received packets, this returns the DSCP value set by the sender.
MACADR UDPPacket::GetMacSource | ( | ) |
Get the source MAC address a UDP Packet object.
uint16_t UDPPacket::GetPacketId | ( | void | ) |
Get UDP packet ID.
|
inline |
Get the source IP address a UDP Packet object.
uint16_t UDPPacket::GetSourcePort | ( | void | ) | const |
Get the source port number of a UDP Packet object.
|
inline |
Send the UDP Packet and free the pool buffer.
to | Destination IP address |
ttl | Optional. If not specified the system default will be used |
|
inline |
Make a copy of a UDP Packet and send it. The original packet will remain intact.
to | Destination IP address |
ttl | Optional. If not specified the system default will be used |
|
inline |
Make a copy of a UDP Packet and send it through the network interface specified by the from_ip IP address parameter. If more than one interface has the same IP address, the lower interface number will be used. The original packet will remain intact.
to | Destination IP address |
from_ip | IP address to identify the local network interface as the source |
ttl | Optional. If not specified the system default will be used |
|
inline |
Make a copy of a UDP Packet and send it using the specified network interface. The original packet will remain intact.
to | Destination IP address |
interface | Interface number |
ttl | Optional. If not specified the system default will be used |
Send a UDP packet through the network interface specified by the from_ip IP address parameter. If more than one interface has the same IP address, the lower interface number will be used. The UDP pool buffer will be freed.
to | Destination IP address |
from_ip | IP address to identify the local network interface as the source |
ttl | Optional. If not specified the system default will be used |
|
inline |
Send the UDP Packet using the specified network interface and free the pool buffer.
to | Destination IP address |
interface | Interface number |
ttl | Optional. If not specified the system default will be used |
void UDPPacket::SetDataSize | ( | uint16_t | numBytes | ) |
void UDPPacket::SetDestinationPort | ( | uint16_t | port | ) |
Set the destination port number of a UDP Packet object.
port | Destination port number |
void UDPPacket::SetDSCP | ( | uint8_t | dscp | ) |
Set the Differentiated Services Code Point (DSCP) value for the packet.
DSCP provides Quality of Service (QoS) marking for IP packets. The DSCP value is a 6-bit field that can range from 0 to 63. This method works transparently for both IPv4 and IPv6 packets.
dscp | The DSCP value (0-63). Values greater than 63 will be masked to 6 bits. |
void UDPPacket::SetSourcePort | ( | uint16_t | port | ) |
Set the source port number of a UDP Packet object.
port | Source port number |
BOOL UDPPacket::Validate | ( | void | ) |
Verify a received UDP packet is valid.
Verifies a received UDP packet has data and validates the checksum. This function should be called anytime a UDP packet is received.