The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
ipv4.h File Reference

IPv4 (RFC 791): the header, the checks, and where a packet goes. More...

#include "netif.h"

Go to the source code of this file.

Data Structures

struct  __attribute__
 ELF32 file header. More...
struct  ipv4_stats_t

Macros

#define IPV4_HEADER_SIZE   20
#define IPV4_BROADCAST   0xFFFFFFFFu
#define IPV4_PACKET_MAX   65535
#define IP_PROTO_ICMP   1
#define IP_PROTO_TCP   6
#define IP_PROTO_UDP   17

Functions

bool ipv4_init (void)
 get the send buffer (from net_init).
void ipv4_receive (netif_t *netif, const uint8_t *packet, uint32_t length)
 a packet from an interface (net_lock held).
bool ipv4_send (uint32_t source, uint32_t dst, uint8_t protocol, const void *payload, uint32_t length)
 send a payload to dst (net_lock held).
uint32_t ipv4_pseudo_sum (uint32_t source, uint32_t dst, uint8_t protocol, uint32_t length)
 the sum of the pseudo-header of UDP and TCP (the addresses, the protocol, the length), to start their checksum with.
uint32_t ipv4_source_for (uint32_t dst)
 the source address a packet to dst gets (net_lock held), 0 if there is no route.
netif_t * ipv4_route (uint32_t dst, uint32_t *next_hop)
 the interface a packet to dst goes out on, and the host it goes to first (dst, or a gateway).

Variables

ipv4_stats_t ipv4_stats

Detailed Description

IPv4 (RFC 791): the header, the checks, and where a packet goes.

routing: 127.0.0.0/8 goes to the loopback interface; an address on the local network of an interface goes straight to it; any other address goes to the gateway of the first interface that has one. 255.255.255.255 goes to all hosts on the first Ethernet interface, also before it has an address (for DHCP).

fragments are not put together: a fragment is dropped and counted, and every packet sent has the "don't fragment" bit set.

Macro Definition Documentation

◆ IPV4_HEADER_SIZE

#define IPV4_HEADER_SIZE   20

◆ IPV4_BROADCAST

#define IPV4_BROADCAST   0xFFFFFFFFu

◆ IPV4_PACKET_MAX

#define IPV4_PACKET_MAX   65535

◆ IP_PROTO_ICMP

#define IP_PROTO_ICMP   1

◆ IP_PROTO_TCP

#define IP_PROTO_TCP   6

◆ IP_PROTO_UDP

#define IP_PROTO_UDP   17

Function Documentation

◆ ipv4_init()

bool ipv4_init ( void )

get the send buffer (from net_init).

Returns
false if there is no memory.

◆ ipv4_receive()

void ipv4_receive ( netif_t * netif,
const uint8_t * packet,
uint32_t length )

a packet from an interface (net_lock held).

◆ ipv4_send()

bool ipv4_send ( uint32_t source,
uint32_t dst,
uint8_t protocol,
const void * payload,
uint32_t length )

send a payload to dst (net_lock held).

Parameters
sourcethe source address, or 0 for the address of the interface the packet goes out on.
Returns
false if there is no route or the device has no room.

◆ ipv4_pseudo_sum()

uint32_t ipv4_pseudo_sum ( uint32_t source,
uint32_t dst,
uint8_t protocol,
uint32_t length )

the sum of the pseudo-header of UDP and TCP (the addresses, the protocol, the length), to start their checksum with.

◆ ipv4_source_for()

uint32_t ipv4_source_for ( uint32_t dst)

the source address a packet to dst gets (net_lock held), 0 if there is no route.

◆ ipv4_route()

netif_t * ipv4_route ( uint32_t dst,
uint32_t * next_hop )

the interface a packet to dst goes out on, and the host it goes to first (dst, or a gateway).

net_lock held.

Returns
NULL if there is no route.

Variable Documentation

◆ ipv4_stats

ipv4_stats_t ipv4_stats
extern