Skip to content

File syn_udp.h

FileList > net > syn_udp.h

Go to the source code of this file

Zero-Alloc Native UDP Demuxing Engine & Task-Blocking Layer.

  • #include "syntropic/common/syn_defs.h"
  • #include "syntropic/net/syn_eth.h"
  • #include "syntropic/pt/syn_pt.h"
  • #include "syntropic/sched/syn_sched.h"
  • #include "syntropic/sched/syn_task.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_UDP
UDP protocol stack container instance.
struct SYN_UdpHeader
UDP packet header structure (8 bytes).
struct SYN_UdpSocket
UDP socket slot control block.

Public Functions

Type Name
SYN_UdpSocket * syn_udp_bind (SYN_UDP * udp, uint16_t local_port)
Bind UDP socket to local port.
uint16_t syn_udp_checksum (uint32_t src_ip, uint32_t dst_ip, const uint8_t * udp_seg, size_t len)
Compute UDP 16-bit 1's complement checksum over pseudo-header and segment.
SYN_Status syn_udp_init (SYN_UDP * udp, SYN_ETH * eth)
Initialize UDP Stack.
SYN_Status syn_udp_process_packet (SYN_UDP * udp, const uint8_t * ip_packet, size_t len)
Process incoming UDP IPv4 packet.
int syn_udp_sendto (SYN_UDP * udp, uint16_t src_port, uint32_t dst_ip, uint16_t dst_port, const uint8_t * data, size_t data_len, uint8_t * tx_out, size_t * tx_len)
Construct outbound UDP packet into frame output buffer.
void syn_udp_unbind (SYN_UdpSocket * sock)
Unbind and release a UDP socket slot.

Macros

Type Name
define PT_UDP_BLOCK_READ (pt, task, sock, buf, max_len, bytes_read, src_ip, src_port) /* multi line expression */
Protothread helper macro to block task until UDP packet arrives.
define SYN_UDP_BUF_SIZE 256
define SYN_UDP_MAX_SOCKETS 4

Public Functions Documentation

function syn_udp_bind

Bind UDP socket to local port.

SYN_UdpSocket * syn_udp_bind (
    SYN_UDP * udp,
    uint16_t local_port
) 

Parameters:

  • udp Pointer to UDP stack instance.
  • local_port Port number to bind.

Returns:

Pointer to allocated UDP socket slot, or NULL if capacity exceeded.


function syn_udp_checksum

Compute UDP 16-bit 1's complement checksum over pseudo-header and segment.

uint16_t syn_udp_checksum (
    uint32_t src_ip,
    uint32_t dst_ip,
    const uint8_t * udp_seg,
    size_t len
) 

Parameters:

  • src_ip Source 32-bit IPv4 address.
  • dst_ip Destination 32-bit IPv4 address.
  • udp_seg Pointer to raw UDP segment bytes.
  • len UDP segment length in bytes.

Returns:

Computed 16-bit UDP checksum.


function syn_udp_init

Initialize UDP Stack.

SYN_Status syn_udp_init (
    SYN_UDP * udp,
    SYN_ETH * eth
) 

Parameters:

  • udp Pointer to UDP stack instance.
  • eth Pointer to Ethernet interface instance.

Returns:

SYN_OK on success.


function syn_udp_process_packet

Process incoming UDP IPv4 packet.

SYN_Status syn_udp_process_packet (
    SYN_UDP * udp,
    const uint8_t * ip_packet,
    size_t len
) 

Parameters:

  • udp Pointer to UDP stack instance.
  • ip_packet Pointer to raw IPv4 packet.
  • len IPv4 packet byte length.

Returns:

SYN_OK on success.


function syn_udp_sendto

Construct outbound UDP packet into frame output buffer.

int syn_udp_sendto (
    SYN_UDP * udp,
    uint16_t src_port,
    uint32_t dst_ip,
    uint16_t dst_port,
    const uint8_t * data,
    size_t data_len,
    uint8_t * tx_out,
    size_t * tx_len
) 

Parameters:

  • udp Pointer to UDP stack.
  • src_port Source UDP port.
  • dst_ip Destination IPv4 address.
  • dst_port Destination UDP port.
  • data Pointer to payload data buffer.
  • data_len Payload byte length.
  • tx_out Output Ethernet frame buffer.
  • tx_len Pointer to receive final Ethernet frame length.

Returns:

SYN_OK on success.


function syn_udp_unbind

Unbind and release a UDP socket slot.

void syn_udp_unbind (
    SYN_UdpSocket * sock
) 

Parameters:

  • sock Pointer to UDP socket slot.

Macro Definition Documentation

define PT_UDP_BLOCK_READ

Protothread helper macro to block task until UDP packet arrives.

#define PT_UDP_BLOCK_READ (
    pt,
    task,
    sock,
    buf,
    max_len,
    bytes_read,
    src_ip,
    src_port
) `/* multi line expression */`

Parameters:

  • pt Protothread state.
  • task Task instance.
  • sock UDP socket pointer.
  • buf Destination read buffer.
  • max_len Maximum bytes to read.
  • bytes_read Pointer to output size_t receiving count of read bytes.
  • src_ip Pointer to uint32_t receiving sender IP address.
  • src_port Pointer to uint16_t receiving sender port.

define SYN_UDP_BUF_SIZE

#define SYN_UDP_BUF_SIZE `256`

UDP socket internal RX buffer size in bytes


define SYN_UDP_MAX_SOCKETS

#define SYN_UDP_MAX_SOCKETS `4`

Maximum concurrent UDP bound sockets



The documentation for this class was generated from the following file src/syntropic/net/syn_udp.h