Skip to content

File syn_icmp.h

FileList > net > syn_icmp.h

Go to the source code of this file

Zero-Heap Native ICMP Protocol Engine. More...

  • #include "syntropic/common/syn_defs.h"
  • #include "syntropic/net/syn_eth.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_ICMP

Public Functions

Type Name
SYN_Status syn_icmp_build_echo_request (SYN_ICMP * icmp, SYN_ETH * eth, uint32_t dst_ip, const uint8_t dst_mac, uint16_t id, uint16_t seq, const uint8_t * payload, size_t payload_len, uint8_t * frame_out, size_t * frame_len)
Construct an outbound ICMP Echo Request frame.
uint16_t syn_icmp_checksum (const void * buf, size_t len)
Compute RFC 1071 Ones-Complement Internet Checksum.
SYN_Status syn_icmp_init (SYN_ICMP * icmp)
Initialize ICMP Engine Context.
SYN_Status syn_icmp_process_packet (SYN_ICMP * icmp, const uint8_t * ip_pkt, size_t len, uint8_t * frame_tx, size_t * tx_len)
Process incoming ICMP packet inside IPv4 payload.

Macros

Type Name
define SYN_ICMP_HEADER_LEN 8U
define SYN_ICMP_TYPE_ECHO_REPLY 0U
define SYN_ICMP_TYPE_ECHO_REQUEST 8U
define SYN_ICMP_TYPE_UNREACHABLE 3U

Detailed Description

Specifications: * RFC 792 Internet Control Message Protocol * Zero dynamic memory allocation (0 bytes heap) * Types: * Type 0: Echo Reply * Type 3: Destination Unreachable * Type 8: Echo Request

Public Functions Documentation

function syn_icmp_build_echo_request

Construct an outbound ICMP Echo Request frame.

SYN_Status syn_icmp_build_echo_request (
    SYN_ICMP * icmp,
    SYN_ETH * eth,
    uint32_t dst_ip,
    const uint8_t dst_mac,
    uint16_t id,
    uint16_t seq,
    const uint8_t * payload,
    size_t payload_len,
    uint8_t * frame_out,
    size_t * frame_len
) 

Parameters:

  • icmp Pointer to ICMP context.
  • eth Pointer to Ethernet context.
  • dst_ip 32-bit IPv4 address of destination.
  • dst_mac 6-byte MAC address of destination.
  • id Identifier.
  • seq Sequence number.
  • payload Pointer to payload data.
  • payload_len Payload length in bytes.
  • frame_out Output frame buffer (must hold at least 60 bytes).
  • frame_len Pointer to receive final Ethernet II frame length.

Returns:

SYN_OK on success.


function syn_icmp_checksum

Compute RFC 1071 Ones-Complement Internet Checksum.

uint16_t syn_icmp_checksum (
    const void * buf,
    size_t len
) 

Parameters:

  • buf Pointer to buffer bytes.
  • len Length in bytes.

Returns:

16-bit Ones-Complement checksum.


function syn_icmp_init

Initialize ICMP Engine Context.

SYN_Status syn_icmp_init (
    SYN_ICMP * icmp
) 

Parameters:

  • icmp Pointer to ICMP context.

Returns:

SYN_OK on success.


function syn_icmp_process_packet

Process incoming ICMP packet inside IPv4 payload.

SYN_Status syn_icmp_process_packet (
    SYN_ICMP * icmp,
    const uint8_t * ip_pkt,
    size_t len,
    uint8_t * frame_tx,
    size_t * tx_len
) 

Automatically generates a matching Type 0 Echo Reply if a Type 8 Echo Request is received.

Parameters:

  • icmp Pointer to ICMP context.
  • ip_pkt Pointer to incoming IPv4 packet (starting at IP header).
  • len IP packet byte length.
  • frame_tx Output buffer to receive constructed Ethernet II reply frame (min 60 bytes).
  • tx_len Pointer to receive byte length of constructed reply frame (0 if none generated).

Returns:

SYN_OK on success.


Macro Definition Documentation

define SYN_ICMP_HEADER_LEN

#define SYN_ICMP_HEADER_LEN `8U`

Standard ICMP header length in bytes (8)


define SYN_ICMP_TYPE_ECHO_REPLY

#define SYN_ICMP_TYPE_ECHO_REPLY `0U`

ICMP Type 0: Echo Reply


define SYN_ICMP_TYPE_ECHO_REQUEST

#define SYN_ICMP_TYPE_ECHO_REQUEST `8U`

ICMP Type 8: Echo Request


define SYN_ICMP_TYPE_UNREACHABLE

#define SYN_ICMP_TYPE_UNREACHABLE `3U`

ICMP Type 3: Destination Unreachable



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