#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>
Go to the source code of this file.
◆ free_buffer()
void free_buffer |
( |
uint8_t * |
buffer, |
|
|
uintptr_t |
len |
|
) |
| |
Properly frees a buffer that was allocated by receive_c
Parameters
buffer
- Pointer to the buffer to free
len
- Length of the buffer in bytes
Safety
- If the buffer pointer was not created by receive_c, or has already been freed, undefined behavior will occur
- After this call, the buffer pointer must not be used again
◆ free_receiver()
void free_receiver |
( |
UdpReceiver * |
ptr | ) |
|
Properly frees a UdpReceiver that was created with new_unicast_receiver_c or new_multicast_receiver_c
Parameters
ptr
- Pointer to a UdpReceiver to free
Safety
- If the pointer was not created by new_unicast_receiver_c or new_multicast_receiver_c, or has already been freed, undefined behavior will occur
- After this call, the pointer must not be used again
◆ free_sender()
Properly frees a UdpSenderC that was created with new_unicast_sender_c or new_multicast_sender_c
Parameters
Safety
- If the sender was not created by new_unicast_sender_c or new_multicast_sender_c, or has already been freed, undefined behavior will occur
- After this call, the sender must not be used again
◆ new_multicast_receiver_c()
UdpReceiver * new_multicast_receiver_c |
( |
const char * |
bind_addr, |
|
|
const char * |
group_addr, |
|
|
const char * |
interface_addr |
|
) |
| |
Creates a new UDP multicast receiver that joins the specified multicast group
Parameters
bind_addr
- C string containing the address to bind to (e.g., "0.0.0.0:4444")
group_addr
- C string containing the multicast group to join (e.g., "224.0.0.1:4444")
interface_addr
- C string containing the local interface IP to use (e.g., "192.168.20.100") Use "0.0.0.0" to use the default interface
Returns
- Pointer to a heap-allocated UdpReceiver on success
- NULL pointer on failure (invalid parameters or socket creation failure)
Memory Management
- The returned pointer must be freed using free_receiver()
- Ownership of the UdpReceiver is transferred to the caller
◆ new_multicast_sender_c()
UdpSenderC new_multicast_sender_c |
( |
const char * |
bind_addr, |
|
|
const char * |
group_addr, |
|
|
uint32_t |
ttl |
|
) |
| |
Creates a new UDP multicast sender bound to the specified address and targeting the specified multicast group
Parameters
bind_addr
- C string containing the local address to bind to (e.g., "0.0.0.0:0")
group_addr
- C string containing the multicast group to send to (e.g., "224.0.0.1:4444")
ttl
- Time-to-live value for multicast packets (1-255) This controls how many network hops the packets can traverse Pass 0 to use the default TTL value (5)
Returns
- UdpSenderC struct with a valid internal sender on success
- UdpSenderC struct with a null internal sender on failure (invalid parameters or socket creation failure)
Memory Management
◆ new_unicast_receiver_c()
UdpReceiver * new_unicast_receiver_c |
( |
const char * |
bind_addr | ) |
|
Creates a new UDP unicast receiver bound to the specified address
Parameters
bind_addr
- C string containing the address to bind to (e.g., "0.0.0.0:4444")
Returns
- Pointer to a heap-allocated UdpReceiver on success
- NULL pointer on failure (invalid bind_addr or socket creation failure)
Memory Management
- The returned pointer must be freed using free_receiver()
- Ownership of the UdpReceiver is transferred to the caller
◆ new_unicast_sender_c()
UdpSenderC new_unicast_sender_c |
( |
const char * |
bind_addr, |
|
|
const char * |
target_addr |
|
) |
| |
Creates a new UDP unicast sender bound to the specified address and targeting the specified endpoint
Parameters
bind_addr
- C string containing the local address to bind to (e.g., "0.0.0.0:0")
target_addr
- C string containing the target address to send to (e.g., "192.168.20.100:4444")
Returns
- UdpSenderC struct with a valid internal sender on success
- UdpSenderC struct with a null internal sender on failure (invalid parameters or socket creation failure)
Memory Management
◆ receive_c()
Receives data from a UDP receiver and returns it in a newly allocated buffer
Parameters
receiver
- Pointer to a valid UdpReceiver created by new_unicast_receiver_c or new_multicast_receiver_c
Returns
- A BufferResult struct containing:
- data: Pointer to a newly allocated buffer containing the received data
- len: Length of the received data in bytes
- success: true if data was received successfully, false otherwise
Memory Management
- The returned buffer must be freed using free_buffer()
- Ownership of the buffer is transferred to the caller
Safety
- If the receiver pointer is invalid or null, undefined behavior will occur
◆ send_c()
bool send_c |
( |
const UdpSenderC * |
sender, |
|
|
const uint8_t * |
data, |
|
|
uintptr_t |
len |
|
) |
| |
Sends data using the specified UDP sender
Parameters
sender
- Reference to a valid UdpSenderC created by new_unicast_sender_c or new_multicast_sender_c
data
- Pointer to the data buffer to send
len
- Length of the data buffer in bytes
Returns
- true if the data was sent successfully
- false if the sender is invalid or the send operation failed
Safety
- If the sender is invalid or the data pointer is null/invalid, undefined behavior may occur
- The sender must have been created by new_unicast_sender_c or new_multicast_sender_c
- The data buffer must be valid for at least len bytes