My Kernel v0.1.0
Collaboration diagram for Packet:

Data Structures

struct  packet
 A network packet. More...
 

Macros

#define packet_put_literal(packet, data)   packet_put(packet, &data, sizeof(data))
 Append new data of literal type to the packet (e.g. More...
 
#define packet_peek_literal(packet, data)    packet_peek(packet, &data, sizeof(data))
 Read literal from the packet (e.g. More...
 
#define packet_pop_literal(packet, data)   packet_pop(packet, &data, sizeof(data))
 Pop literal from the packet (e.g. More...
 

Functions

struct packetpacket_new (size_t packet_size)
 Create a new packet.
 
struct packetpacket_clone (const struct packet *packet)
 Clone a packet. More...
 
void packet_free (struct packet *packet)
 Free a packet.
 
error_t packet_send (struct packet *packet)
 Send the packet.
 
static void * packet_start (const struct packet *packet)
 Find the start of the actual packet's content.
 
static size_t packet_size (const struct packet *packet)
 
static size_t packet_read_size (const struct packet *packet)
 
static void * packet_end (const struct packet *packet)
 Find the end of the actual packet's content.
 
error_t packet_put (struct packet *packet, const void *data, size_t size)
 Append new data to the packet.
 
size_t packet_peek (struct packet *packet, void *data, size_t size)
 Read data from the packet. More...
 
size_t packet_pop (struct packet *packet, void *data, size_t size)
 Read data from the packet. More...
 
static void packet_mark_l2_start (struct packet *packet)
 Set the current end of the packet as the start of the link layer.
 
static void packet_set_l2_size (struct packet *packet, size_t size)
 Set the start of the network layer N bytes after the link layer.
 
static void packet_mark_l3_start (struct packet *packet)
 Set the current end of the packet as the start of the network layer.
 
static void packet_set_l3_size (struct packet *packet, size_t size)
 Set the start of the packet payload N bytes after the network layer.
 
static void * packet_payload (const struct packet *packet)
 
static size_t packet_header_size (const struct packet *packet)
 
static size_t packet_payload_size (const struct packet *packet)
 

Detailed Description

Network Packet

The network packet is the core of the network API. Each time we send or receive a packet, a new packet is created to hold its data and be passed to the API's function.

This packet's design is inspired by Linux's socket buffer interface. Even though this is a heavily simplified version of it, the philosophy remains the same:

Macro Definition Documentation

◆ packet_peek_literal

#define packet_peek_literal (   packet,
  data 
)     packet_peek(packet, &data, sizeof(data))

integers)

◆ packet_pop_literal

#define packet_pop_literal (   packet,
  data 
)    packet_pop(packet, &data, sizeof(data))

integers)

◆ packet_put_literal

#define packet_put_literal (   packet,
  data 
)    packet_put(packet, &data, sizeof(data))

integers)

Function Documentation

◆ packet_clone()

struct packet * packet_clone ( const struct packet packet)

The packet's content as well as the current offsets will be duplicated, so that one can use a duplicated packet just like the original one.

◆ packet_header_size()

static size_t packet_header_size ( const struct packet packet)
inlinestatic
Returns
the size of the packet's header

◆ packet_payload()

static void * packet_payload ( const struct packet packet)
inlinestatic
Returns
the sart of the packet's payload (L4)

◆ packet_payload_size()

static size_t packet_payload_size ( const struct packet packet)
inlinestatic
Returns
the size of the packet's payload

◆ packet_peek()

size_t packet_peek ( struct packet packet,
void *  data,
size_t  size 
)
Returns
The number of bytes actually read.

◆ packet_pop()

size_t packet_pop ( struct packet packet,
void *  data,
size_t  size 
)

Popped data cannot be re-read afterwards.

Returns
The number of bytes actually read.

◆ packet_read_size()

static size_t packet_read_size ( const struct packet packet)
inlinestatic
Returns
The current number of bytes that can be read from the packet

◆ packet_size()

static size_t packet_size ( const struct packet packet)
inlinestatic
Returns
The current number of bytes placed into the packet