The NetBurner UDP protocol Socket API. More...
Functions | |
UDPPacket::UDPPacket (OS_FIFO *pFifo, uint32_t timeout) | |
Constructor to create a UDP Packet object from a UDP FIFO entry. More... | |
UDPPacket::UDPPacket (int sock) | |
Constructor to create a UDP Packet object from an open UDP socket. More... | |
UDPPacket::UDPPacket (PoolPtr p) | |
Constructor to create a UDP packet from a system pool buffer. More... | |
UDPPacket::UDPPacket (UDPPacket &pkt) | |
Constructor to create a new UDP packet from an existing UDP packet. More... | |
UDPPacket::~UDPPacket () | |
UDP packet object destructor. Frees any associated memory. More... | |
void | UDPPacket::SetSourcePort (uint16_t port) |
Set the source port number of a UDP Packet object. More... | |
uint16_t | UDPPacket::GetSourcePort (void) const |
Get the source port number of a UDP Packet object. More... | |
IPADDR4 | UDPPacket::GetSourceAddress4 (void) |
Get the source IPv4 address a UDP Packet object. More... | |
IPADDR4 | UDPPacket::GetDestinationAddress4 () |
Get the destination IPv4 address a UDP Packet object. More... | |
MACADR | UDPPacket::GetMacSource () |
Get the source MAC address a UDP Packet object. More... | |
IPADDR6 | UDPPacket::GetSourceAddress6 (void) |
Get the source IPv6 address a UDP Packet object. More... | |
IPADDR6 | UDPPacket::GetDestinationAddress6 () |
Get the destination IPv6 address a UDP Packet object. More... | |
void | UDPPacket::SetDestinationPort (uint16_t) |
Set the destination port number of a UDP Packet object. More... | |
uint16_t | UDPPacket::GetDestinationPort (void) const |
Get the destination port number of a UDP Packet object. More... | |
puint8_t | UDPPacket::GetDataBuffer (bool bReAllocateIfNeeded=false) |
Get a pointer to the UDP Packet object's data buffer. More... | |
void | UDPPacket::SetDataSize (uint16_t numBytes) |
Set the UDP Packet data size. More... | |
uint16_t | UDPPacket::GetDataSize (void) const |
Get the UDP Packet object data size. More... | |
void | UDPPacket::AddData (puint8_t pData, uint16_t len) |
Add data to a UDP Packet object. More... | |
void | UDPPacket::AddData (PCSTR pData) |
Add data to a UDP Packet object as a NULL terminated ASCII string. More... | |
void | UDPPacket::AddDataWord (uint16_t w) |
Add a 16-bit unsigned integer to a UDP Packet object. More... | |
void | UDPPacket::AddDataByte (uint8_t b) |
Add an 8-bit unsigned integer to a UDP Packet object. More... | |
BOOL | UDPPacket::Validate (void) |
Verify a received UDP packet. More... | |
void | UDPPacket::ResetData (void) |
Set the data size of a UDP Packet object to 0. | |
void | UDPPacket::SendAndKeep4 (IPADDR4 destIP, uint8_t ttl=0) |
Make a copy of a UDP Packet and send it. The original packet will remain intact. More... | |
void | UDPPacket::Send4 (IPADDR4 destIP, uint8_t ttl=0) |
Send the UDP Packet and free the pool buffer. More... | |
void | UDPPacket::SendViaInterfaceNum4 (IPADDR4 destIP, int interface, uint8_t ttl=0) |
Send the UDP Packet using the specified interface, and free the pool buffer. More... | |
void | UDPPacket::SendAndKeep6 (const IPADDR6 &to, uint8_t ttl=0) |
Make a copy of a UDP Packet and send it. The original packet will remain intact. More... | |
void | UDPPacket::Send6 (const IPADDR6 &to, uint8_t ttl=0) |
Send the UDP Packet and free the pool buffer. More... | |
void | UDPPacket::SendViaInterfaceNum6 (const IPADDR6 &to, int interface, uint8_t ttl=0) |
Send the UDP Packet using the specified interface, and free the pool buffer. More... | |
int | CreateRxUdpSocket (uint16_t listening_port) |
Open a UDP socket for receiving incoming UDP packets. More... | |
int | CreateTxUdpSocket4 (IPADDR4 send_to_addr, uint16_t remote_port, uint16_t local_port) |
Open a UDP socket for transmitting UDP packets. More... | |
int | CreateRxTxUdpSocket4 (IPADDR4 send_to_addr, uint16_t send_to_remote_port, uint16_t local_port) |
Open a UDP socket that can transmit and receive UDP packets. More... | |
int | CreateTxUdpSocket6 (const IPADDR6 &send_to_addr, uint16_t remote_port, uint16_t local_port) |
Open a UDP socket for transmitting UDP packets. More... | |
int | CreateTxUdpSocket (const IPADDR6 &send_to_addr, uint16_t remote_port, uint16_t local_port) |
Open a UDP socket for transmitting UDP packets. More... | |
int | CreateRxTxUdpSocket6 (const IPADDR6 &send_to_addr, uint16_t send_to_remote_port, uint16_t local_port) |
Open a UDP socket that can transmit and receive UDP packets. More... | |
int | sendto4 (int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port) |
Send a UDP packet. More... | |
int | sendto6 (int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port) |
Send a UDP packet. More... | |
int | sendto (int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port) |
Send a UDP packet. More... | |
int | sendtovia4 (int sock, puint8_t what_to_send, int len_to_send, IPADDR4 to_addr, uint16_t remote_port, int intfnum) |
Send a UDP packet on the specified interface. More... | |
int | sendtovia6 (int sock, puint8_t what_to_send, int len_to_send, const IPADDR6 &to_addr, uint16_t remote_port, int intfnum) |
Send a UDP packet on the specified interface. More... | |
int | recvfrom4 (int sock, puint8_t buffer, int len, IPADDR4 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port) |
Receive a UDP packet. More... | |
int | recvfrom6 (int sock, puint8_t buffer, int len, IPADDR6 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port) |
Receive a UDP packet. More... | |
int | recvfrom (int sock, puint8_t buffer, int len, IPADDR6 *pAddr, uint16_t *pLocal_port, uint16_t *pRemote_port) |
Receive a UDP packet. More... | |
The NetBurner UDP protocol Socket API.
The NetBurner UDP protocol API is implemented in two ways:
1. As a C++ class, which makes memory management easier. 2. Wrapper functions that implement a UDP sockets interface.
void UDPPacket::AddData | ( | puint8_t | pData, |
uint16_t | len | ||
) |
Add data to a UDP Packet object.
pData | Pointer to the data to add |
len | Number of bytes |
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::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 |
int CreateRxTxUdpSocket4 | ( | IPADDR4 | send_to_addr, |
uint16_t | send_to_remote_port, | ||
uint16_t | local_port | ||
) |
Open a UDP socket that can transmit and receive UDP packets.
Calling CreateRxTxUdpSocket() in dual stack mode will automatically select the correct IPv4/IPv6 function.
send_to_addr | Destination IP address |
send_to_remote_port | Destination port number |
local_port | Local port number. A value of 0 will select a random port number (recommended) |
int CreateRxTxUdpSocket6 | ( | const IPADDR6 & | send_to_addr, |
uint16_t | send_to_remote_port, | ||
uint16_t | local_port | ||
) |
Open a UDP socket that can transmit and receive UDP packets.
Calling CreateRxTxUdpSocket() in dual stack mode will automatically select the correct IPv4/IPv6 function.
send_to_addr | Destination IP address |
send_to_remote_port | Destination port number |
local_port | Local port number. A value of 0 will select a random port number (recommended) |
int CreateRxUdpSocket | ( | uint16_t | listening_port | ) |
Open a UDP socket for receiving incoming UDP packets.
Returns a file descriptor that can be used by read functions such as: read() and select() to process multiple file descriptors at one time.
listening_port | Port to listen on for incoming packets |
|
inline |
Open a UDP socket for transmitting UDP packets.
Calling CreateTxUdpSocket() in dual stack mode will automatically select the correct IPv4/IPv6 function.
Returns a file descriptor that can be used by transmit functions such as sendto().
send_to_addr | Destination IP address |
remote_port | Destination port number |
local_port | Local port number. A value of 0 will select a random port number (recommended) |
int CreateTxUdpSocket4 | ( | IPADDR4 | send_to_addr, |
uint16_t | remote_port, | ||
uint16_t | local_port | ||
) |
Open a UDP socket for transmitting UDP packets.
Calling CreateTxUdpSocket() in dual stack mode will automatically select the correct IPv4/IPv6 function.
Returns a file descriptor that can be used by transmit functions such as write().
send_to_addr | Destination IP address |
remote_port | Destination port number |
local_port | Local port number. A value of 0 will select a random port number (recommended) |
int CreateTxUdpSocket6 | ( | const IPADDR6 & | send_to_addr, |
uint16_t | remote_port, | ||
uint16_t | local_port | ||
) |
Open a UDP socket for transmitting UDP packets.
Calling CreateTxUdpSocket() in dual stack mode will automatically select the correct IPv4/IPv6 function.
Returns a file descriptor that can be used by transmit functions such as sendto().
send_to_addr | Destination IP address |
remote_port | Destination port number |
local_port | Local port number. A value of 0 will select a random port number (recommended) |
puint8_t UDPPacket::GetDataBuffer | ( | bool | bReAllocateIfNeeded = false | ) |
Get a pointer to the UDP Packet object's data buffer.
uint16_t UDPPacket::GetDataSize | ( | void | ) | const |
IPADDR4 UDPPacket::GetDestinationAddress4 | ( | void | ) |
Get the destination IPv4 address a UDP Packet object.
Calling GetDestinationAddress() in dual stack mode will automatically select the correct IPv4/IPv6 function.
IPADDR6 UDPPacket::GetDestinationAddress6 | ( | ) |
Get the destination IPv6 address a UDP Packet object.
Calling GetDestinationAddress() in dual stack mode will automatically select the correct IPv4/IPv6 function.
uint16_t UDPPacket::GetDestinationPort | ( | void | ) | const |
Get the destination port number of a UDP Packet object.
MACADR UDPPacket::GetMacSource | ( | ) |
Get the source MAC address a UDP Packet object.
IPADDR4 UDPPacket::GetSourceAddress4 | ( | void | ) |
Get the source IPv4 address a UDP Packet object.
Calling GetSourceAddress() in dual stack mode will automatically select the correct IPv4/IPv6 function.
IPADDR6 UDPPacket::GetSourceAddress6 | ( | void | ) |
Get the source IPv6 address a UDP Packet object.
Calling GetSourceAddress() in dual stack mode will automatically select the correct IPv4/IPv6 function.
uint16_t UDPPacket::GetSourcePort | ( | void | ) | const |
Get the source port number of a UDP Packet object.
|
inline |
Receive a UDP packet.
Calling recvfrom() in dual stack mode will automatically select the correct IPv4/IPv6 function.
sock | File descriptor from a previous call to CreateRxUdpSocket() or CreateRxTxSocket() |
buffer | Pointer to BYTE array buffer to store received UDP packet data |
len | Maximum number of bytes to receive |
pAddr | Pointer to an IPADDR variable to store the sender’s IP address of the packet |
pLocal_port | Pointer to WORD variable to store the local port number of the packet |
pRemote_port | Pointer to WORD variable to store the sender’s port number of the packet |
int recvfrom4 | ( | int | sock, |
puint8_t | buffer, | ||
int | len, | ||
IPADDR4 * | pAddr, | ||
uint16_t * | pLocal_port, | ||
uint16_t * | pRemote_port | ||
) |
Receive a UDP packet.
Calling recvfrom() in dual stack mode will automatically select the correct IPv4/IPv6 function.
sock | File descriptor from a previous call to CreateRxUdpSocket() or CreateRxTxSocket() |
buffer | Pointer to BYTE array buffer to store received UDP packet data |
len | Maximum number of bytes to receive |
pAddr | Pointer to an IPADDR variable to store the sender’s IP address of the packet |
pLocal_port | Pointer to WORD variable to store the local port number of the packet |
pRemote_port | Pointer to WORD variable to store the sender’s port number of the packet |
int recvfrom6 | ( | int | sock, |
puint8_t | buffer, | ||
int | len, | ||
IPADDR6 * | pAddr, | ||
uint16_t * | pLocal_port, | ||
uint16_t * | pRemote_port | ||
) |
Receive a UDP packet.
Calling recvfrom() in dual stack mode will automatically select the correct IPv4/IPv6 function.
sock | File descriptor from a previous call to CreateRxUdpSocket() or CreateRxTxSocket() |
buffer | Pointer to BYTE array buffer to store received UDP packet data |
len | Maximum number of bytes to receive |
pAddr | Pointer to an IPADDR variable to store the sender’s IP address of the packet |
pLocal_port | Pointer to WORD variable to store the local port number of the packet |
pRemote_port | Pointer to WORD variable to store the sender’s port number of the packet |
void UDPPacket::Send4 | ( | IPADDR4 | destIP, |
uint8_t | ttl = 0 |
||
) |
Send the UDP Packet and free the pool buffer.
Calling Send() in dual stack mode will automatically select the correct IPv4/IPv6 function.
destIP | Destination IP address |
ttl | Optional. If not specified the system default will be used |
void UDPPacket::Send6 | ( | const IPADDR6 & | to, |
uint8_t | ttl = 0 |
||
) |
Send the UDP Packet and free the pool buffer.
Calling Send() in dual stack mode will automatically select the correct IPv4/IPv6 function.
destIP | Destination IP address |
ttl | Optional. If not specified the system default will be used |
void UDPPacket::SendAndKeep4 | ( | IPADDR4 | destIP, |
uint8_t | ttl = 0 |
||
) |
Make a copy of a UDP Packet and send it. The original packet will remain intact.
Calling SendAndKeep() in dual stack mode will automatically select the correct IPv4/IPv6 function.
destIP | Destination IP address |
ttl | Optional. If not specified the system default will be used |
void UDPPacket::SendAndKeep6 | ( | const IPADDR6 & | to, |
uint8_t | ttl = 0 |
||
) |
Make a copy of a UDP Packet and send it. The original packet will remain intact.
Calling SendAndKeep() in dual stack mode will automatically select the correct IPv4/IPv6 function.
destIP | Destination IP address |
ttl | Optional. If not specified the system default will be used |
|
inline |
Send a UDP packet.
Calling sendto() in dual stack mode will automatically select the correct IPv4/IPv6 function.
sock | Socket to send packet to |
what_to_send | Pointer to data to be sent |
len_to_send | Number of data bytes to send |
to_addr | Destination IP address |
remote_port | Destination port number |
int sendto4 | ( | int | sock, |
puint8_t | what_to_send, | ||
int | len_to_send, | ||
IPADDR4 | to_addr, | ||
uint16_t | remote_port | ||
) |
Send a UDP packet.
Calling sendto() in dual stack mode will automatically select the correct IPv4/IPv6 function.
sock | Socket to send packet to |
what_to_send | Pointer to data to be sent |
len_to_send | Number of data bytes to send |
to_addr | Destination IP address |
remote_port | Destination port number |
int sendto6 | ( | int | sock, |
puint8_t | what_to_send, | ||
int | len_to_send, | ||
const IPADDR6 & | to_addr, | ||
uint16_t | remote_port | ||
) |
Send a UDP packet.
Calling sendto() in dual stack mode will automatically select the correct IPv4/IPv6 function.
sock | Socket to send packet to |
what_to_send | Pointer to data to be sent |
len_to_send | Number of data bytes to send |
to_addr | Destination IP address |
remote_port | Destination port number |
int sendtovia4 | ( | int | sock, |
puint8_t | what_to_send, | ||
int | len_to_send, | ||
IPADDR4 | to_addr, | ||
uint16_t | remote_port, | ||
int | intfnum | ||
) |
Send a UDP packet on the specified interface.
Calling sendtovia() in dual stack mode will automatically select the correct IPv4/IPv6 function.
sock | Socket to send packet to |
what_to_send | Pointer to data to be sent |
len_to_send | Number of data bytes to send |
to_addr | Destination IP address |
remote_port | Destination port number |
intfnum | Interface number |
int sendtovia6 | ( | int | sock, |
puint8_t | what_to_send, | ||
int | len_to_send, | ||
const IPADDR6 & | to_addr, | ||
uint16_t | remote_port, | ||
int | intfnum | ||
) |
Send a UDP packet on the specified interface.
Calling sendtovia() in dual stack mode will automatically select the correct IPv4/IPv6 function.
sock | Socket to send packet to |
what_to_send | Pointer to data to be sent |
len_to_send | Number of data bytes to send |
to_addr | Destination IP address |
remote_port | Destination port number |
intfnum | Interface number |
void UDPPacket::SendViaInterfaceNum4 | ( | IPADDR4 | destIP, |
int | interface, | ||
uint8_t | ttl = 0 |
||
) |
Send the UDP Packet using the specified interface, and free the pool buffer.
Calling SendViaInterfaceNum() in dual stack mode will automatically select the correct IPv4/IPv6 function.
destIP | Destination IP address |
interface | Interface number |
ttl | Optional. If not specified the system default will be used |
void UDPPacket::SendViaInterfaceNum6 | ( | const IPADDR6 & | to, |
int | interface, | ||
uint8_t | ttl = 0 |
||
) |
Send the UDP Packet using the specified interface, and free the pool buffer.
Calling SendViaInterfaceNum() in dual stack mode will automatically select the correct IPv4/IPv6 function.
destIP | 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 | nv | ) |
Set the destination port number of a UDP Packet object.
port | Destination port number |
void UDPPacket::SetSourcePort | ( | uint16_t | port | ) |
Set the source port number of a UDP Packet object.
port | Source port number |
UDPPacket::UDPPacket | ( | OS_FIFO * | pFifo, |
uint32_t | 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 |
BOOL UDPPacket::Validate | ( | void | ) |
Verify a received UDP packet.
Verifies a received UDP packet has data and validates the checksum. This function should be called when receiving a UDP packet.