NetBurner 3.5.6
PDF Version |
Core IP layer definitions, structures, and functions for IPv4/IPv6 networking. More...
Topics | |
IPADDR4 Class | |
IPADDR6 Class | |
Classes | |
struct | _IpHeaderIPv4 |
IP Header Structure (IPv4) More... | |
struct | IPPKT |
Internal IPv4 Header Representation. More... | |
struct | UDPPKT |
Internal UDP Packet Header Structure. More... | |
struct | PsudeoHeader |
UDP/TCP IPv4 Pseudo-header Structure (bits 0 through 95 of the pseudo-header) More... | |
Macros | |
#define | ICMP_PING_DATA_SIZE (32) |
Default data payload size for ICMP echo request and reply packets (32 bytes) | |
Typedefs | |
typedef struct _IpHeaderIPv4 | IpHeaderIPv4 |
IP Header Structure (IPv4) | |
typedef void | FragmentProcessFunction(PoolPtr pp) |
User-defined function pointer type for processing fragmented IP packets. | |
typedef void | PromisciousPacketFunc(PoolPtr pp) |
User-defined function pointer type for processing promiscuous packets. | |
Functions | |
void | IpProcessEthernetPacket (PoolPtr poolPtr, uint16_t packetSizeInBytes) |
Process an Ethernet packet for IP layer handling. | |
uint16_t | GetSum (puint16_t addr, uint16_t count) |
Calculate Internet checksum for the specified data. | |
uint16_t | GetSum20 (puint32_t addr) |
Calculate Internet checksum for exactly 20 bytes of data. | |
uint16_t | GetSumHdr (PsudeoHeader &hdr, puint16_t addr, uint16_t count) |
Calculate Internet checksum using a pseudo-header. | |
BOOL | IsMyIp4 (IPADDR4 ip, int ifc=-1) |
Check if the specified IPv4 address belongs to this device. | |
IPADDR4 | GetSrcIp4 (IPADDR4 dst) |
Get the appropriate source IPv4 address for reaching a destination. | |
IPADDR4 | GetSrcIpwIf4 (int ifn, const IPADDR4 dst) |
Get the source IPv4 address for a specific interface and destination. | |
BOOL | IsMyIp6 (const IPADDR &ip, int ifc=-1) |
Check if the specified IPv6 address belongs to this device. | |
BOOL | IsMyIp (const IPADDR &ip, int ifc=-1) |
Generic function to check if IP address belongs to this device (uses IPv6 when available) | |
IPADDR | GetSrcIp6 (const IPADDR &dst) |
Get the appropriate source IPv6 address for reaching a destination. | |
IPADDR | GetSrcIp (const IPADDR &dst) |
Generic function to get source IP address for reaching a destination (IPv6 version). | |
IPADDR | GetSrcIp6wIf (int ifn, const IPADDR &dst) |
Get the source IPv6 address for a specific interface and destination. | |
IPADDR | GetSrcIpwIf (int ifn, const IPADDR &dst) |
Generic function to get source IP address for an interface (IPv6 version). | |
void | SendICMPError (PoolPtr pBadPacket, uint8_t type, uint8_t code) |
Send an ICMP error message in response to a bad packet. | |
void | FixHeaderAndSend (PoolPtr p, PIPPKT pIp) |
Complete IP header fields and send packet on primary interface. | |
void | FixHeaderAndSendViaInterface (PoolPtr p, PIPPKT pIp, int Interface) |
Complete IP header fields and send packet via specified interface. | |
void | InitializeStack () |
Initialize the IP protocol stack. | |
void | ShowIPBuffer (PoolPtr rp) |
Display the contents of a network buffer for diagnostic purposes. | |
int | Ping4 (IPADDR4 to, uint16_t id, uint16_t seq, uint16_t maxwaitticks) |
Send a "ping" packet and wait the specified timeout for a response. | |
int | Ping4ViaInterface (IPADDR4 to, uint16_t id, uint16_t seq, uint16_t wait, int interface) |
Send a "ping" packet via a specific network interface and wait for a response. | |
int | Ping6 (const IPADDR &to, uint16_t id, uint16_t seq, uint16_t maxwaitticks, int size=32) |
Send an IPv6 "ping" packet and wait the specified timeout for a response. | |
int | Ping6ViaInterface (const IPADDR &to, uint16_t id, uint16_t seq, uint16_t wait, int interface, int size=32) |
Send an IPv6 "ping" packet via a specific network interface. | |
int | Ping (const IPADDR &to, uint16_t id, uint16_t seq, uint16_t maxwaitticks, int size=32) |
Generic ping function that uses IPv6 when IPv6 is enabled. | |
int | PingViaInterface (const IPADDR &to, uint16_t id, uint16_t seq, uint16_t wait, int interface, int size=32) |
Generic ping via interface function that uses IPv6 when IPv6 is enabled. | |
BOOL | IsLocal4 (IPADDR4 ip, int ifc) |
Check if an IPv4 address is on the local network segment. | |
int | GetProperInterface4 (IPADDR4 dst) |
Get the appropriate interface number for reaching a destination. | |
int | AddInterface (IPADDR4 addr, IPADDR4 mask, IPADDR4 gateway, int root_if=0) |
Add a new network interface with the specified configuration. | |
int | GetMultiHomeInterface (IPADDR4 ipa, int norgif) |
Get the multi-home interface for a specific IP address. | |
int | GetLocalIPInterface4 (IPADDR4 ipa) |
Get the local interface number for a specific IPv4 address. | |
int | GetLocalIPInterface6 (const IPADDR &ipa) |
Get the local interface number for a specific IPv6 address. | |
int | GetLocalIPInterface (const IPADDR &ipa) |
Generic function to get local interface for an IP address (IPv6 version). | |
uint16_t | GetEphemeralPort () |
Generate a random ephemeral port number. | |
Variables | |
FragmentProcessFunction * | pFragFunc |
Global function pointer for fragment processing callback. | |
PromisciousPacketFunc * | pPromisciousPacketFunc |
Global function pointer for promiscuous packet processing callback. | |
TaskPacketFunc * | pTaskPacketFunc |
Global function pointer for UDP task packet processing callback. | |
Global Configuration Variables | |
These global variables control various IP stack behaviors and can be modified by the application to customize network behavior. | |
uint8_t | bTTL_Default |
Default Time To Live (hop count) for outgoing IP packets. Typical value is 64 or 128. | |
uint16_t | wArpLifetime |
ARP cache entry lifetime in seconds. Entries older than this are refreshed. Typical value is 300-1200 seconds. | |
BOOL | bQuietStart |
When TRUE, suppresses startup messages during network initialization. Set before calling init(). | |
Get Packet Functions | |
These inline functions provide convenient access to packet structures at various layers of the network stack. They handle the pointer arithmetic needed to locate specific headers within network buffer pool buffers.
| |
PIPPKT | GetIpPkt (PoolPtr p) |
Get IP packet pointer from network buffer pool buffer. | |
PIPPKT | GetIpPkt (PEFRAME pFrame) |
Get IP packet pointer from pointer to Ethernet frame. | |
PIPPKT | GetIpPkt (PVLEFRAME pFrame) |
Get IP packet pointer from pointer to VLAN-tagged Ethernet frame. | |
PUDPPKT | GetUdpPkt (PIPPKT pIp) |
Get UDP packet pointer from IP packet pointer. | |
Core IP layer definitions, structures, and functions for IPv4/IPv6 networking.
#include< ip.h>
This module provides comprehensive support for IP networking including:
typedef void FragmentProcessFunction(PoolPtr pp) |
#include <ip.h>
User-defined function pointer type for processing fragmented IP packets.
This callback function is called only for IP packets that have the fragmentation flag set in the IP header. Applications can implement this function to handle packet fragmentation and reassembly according to their specific requirements.
Typical implementations would:
pp | Packet pointer from network buffer pool containing the fragmented packet |
typedef struct _IpHeaderIPv4 IpHeaderIPv4 |
#include <ip.h>
IP Header Structure (IPv4)
Standard IPv4 packet header as defined in IETF RFC 791 (September 1981) and MIL-STD-1777. This structure represents the 20-byte minimum IP header. IP options, if present, follow this structure and are indicated by a header length value greater than 5.
All multi-byte fields are in network byte order (big-endian) and use the beuint types for automatic endianness handling.
typedef void PromisciousPacketFunc(PoolPtr pp) |
#include <ip.h>
User-defined function pointer type for processing promiscuous packets.
This callback function is called for packets that fail the "IP address == my address" test. This enables applications to receive and process packets not specifically addressed to this device, useful for:
pp | Packet pointer from network buffer pool containing the promiscuous packet |
#include <ip.h>
Add a new network interface with the specified configuration.
Dynamically adds a new network interface to the system with the specified IP address, subnet mask, gateway, and root interface configuration. This is used in multi-homed systems to configure additional network interfaces at runtime.
Typical uses:
addr | IP address for the new interface |
mask | Subnet mask for the new interface |
gateway | Gateway IP address for the new interface (0.0.0.0 for none) |
root_if | Root interface number this interface is associated with (physical interface) |
Add a new network interface with the specified configuration.
addr | IP address of new interface |
mask | IP mask |
gateway | IP gateway |
root_if | Optional root physical interface number. If not specified the default is 0, for Ethernt 0. |
#include <ip.h>
Complete IP header fields and send packet on primary interface.
Fills in remaining IP header fields (checksum, fragmentation info, etc.) and transmits the packet via the primary network interface. This function handles the final steps of IP packet transmission including:
p | Network buffer pool pointer containing the packet |
pIp | Pointer to IP header within the packet |
#include <ip.h>
Complete IP header fields and send packet via specified interface.
Similar to FixHeaderAndSend(), but allows specification of which network interface to use for transmission. This is useful in multi-homed systems where you need explicit control over the egress interface.
p | Network buffer pool pointer containing the packet |
pIp | Pointer to IP header within the packet |
Interface | Interface number to use for transmission (0-based) |
uint16_t GetEphemeralPort | ( | ) |
#include <ip.h>
Generate a random ephemeral port number.
Returns a random port number suitable for use as a local port in client connections. The port number is selected from the ephemeral (dynamic) port range and avoids well-known ports (0-1023) and registered ports (1024-49151).
Ephemeral ports are temporary ports used by the client side of a connection. Each call returns a different random port number to avoid conflicts with other active connections.
|
inline |
#include <ip.h>
Get IP packet pointer from pointer to Ethernet frame.
Returns a pointer to the IP header located immediately after the Ethernet header.
pFrame | Pointer to Ethernet frame structure |
#include <ip.h>
Get IP packet pointer from network buffer pool buffer.
Calculates the location of the IP header within a network buffer by adding the Ethernet header size (14 bytes) to the buffer's data pointer.
p | Network buffer pool pointer |
|
inline |
#include <ip.h>
Get IP packet pointer from pointer to VLAN-tagged Ethernet frame.
Returns a pointer to the IP header located after the VLAN Ethernet header.
pFrame | Pointer to VLAN Ethernet frame structure |
|
inline |
#include <ip.h>
Generic function to get local interface for an IP address (IPv6 version).
This inline function provides a generic interface that automatically uses the IPv6 version when IPv6 support is compiled in.
ipa | IP address to look up |
int GetLocalIPInterface4 | ( | IPADDR4 | ipa | ) |
#include <ip.h>
Get the local interface number for a specific IPv4 address.
Determines which local interface is associated with the specified IPv4 address. Searches all interfaces (physical and virtual) to find the one with the matching address.
ipa | IPv4 address to look up |
int GetLocalIPInterface6 | ( | const IPADDR & | ipa | ) |
#include <ip.h>
Get the local interface number for a specific IPv6 address.
Determines which local interface is associated with the specified IPv6 address. Checks both link-local and global IPv6 addresses on all interfaces.
ipa | IPv6 address to look up |
int GetMultiHomeInterface | ( | IPADDR4 | ipa, |
int | norgif ) |
#include <ip.h>
Get the multi-home interface for a specific IP address.
Finds the appropriate interface number for the specified IP address in a multi-homed system configuration. This searches through all configured interfaces (including virtual interfaces) to find a match.
ipa | IP address to look up |
norgif | Original interface number (for fallback if address not found) |
int GetProperInterface4 | ( | IPADDR4 | dst | ) |
#include <ip.h>
Get the appropriate interface number for reaching a destination.
Performs routing table lookup to determine which interface should be used to reach the specified IPv4 destination address. This considers:
dst | Destination IPv4 address |
#include <ip.h>
Generic function to get source IP address for reaching a destination (IPv6 version).
This inline function provides a generic interface that automatically uses the IPv6 version when IPv6 support is compiled in.
dst | Destination IP address |
#include <ip.h>
Get the appropriate source IPv4 address for reaching a destination.
Determines which local IPv4 address should be used as the source address when sending packets to the specified destination. This performs routing table lookup and interface selection based on the destination address.
dst | Destination IPv4 address |
#include <ip.h>
Get the appropriate source IPv6 address for reaching a destination.
Determines which local IPv6 address should be used as the source address when sending packets to the specified destination. This performs routing table lookup and interface selection.
dst | Destination IPv6 address |
#include <ip.h>
Get the source IPv6 address for a specific interface and destination.
Returns the IPv6 address that should be used as the source address when sending packets to the specified destination via the specified interface.
ifn | Interface number to use |
dst | Destination IPv6 address |
#include <ip.h>
Generic function to get source IP address for an interface (IPv6 version).
This inline function provides a generic interface that automatically uses the IPv6 version when IPv6 support is compiled in.
ifn | Interface number to use |
dst | Destination IP address |
#include <ip.h>
Get the source IPv4 address for a specific interface and destination.
Returns the IPv4 address that should be used as the source address when sending packets to the specified destination via the specified interface. This bypasses routing table lookup and uses the specified interface directly.
ifn | Interface number to use |
dst | Destination IPv4 address |
uint16_t GetSum | ( | puint16_t | addr, |
uint16_t | count ) |
#include <ip.h>
Calculate Internet checksum for the specified data.
Computes the standard Internet checksum (RFC 1071) over the specified data. This is the standard checksum algorithm used in IP, TCP, UDP, and ICMP headers.
The algorithm sums all 16-bit words using one's complement arithmetic, then returns the one's complement of the sum.
addr | Pointer to data to checksum (must be 16-bit aligned) |
count | Number of bytes to include in checksum (should be even) |
uint16_t GetSum20 | ( | puint32_t | addr | ) |
#include <ip.h>
Calculate Internet checksum for exactly 20 bytes of data.
Optimized checksum calculation for exactly 20 bytes (5 32-bit words), which is the standard size of an IP header without options. This function is significantly faster than GetSum() for this common case.
addr | Pointer to 20 bytes of data to checksum (must be 32-bit aligned) |
uint16_t GetSumHdr | ( | PsudeoHeader & | hdr, |
puint16_t | addr, | ||
uint16_t | count ) |
#include <ip.h>
Calculate Internet checksum using a pseudo-header.
Computes the Internet checksum over a pseudo-header followed by data. This is used for TCP and UDP checksum calculation, which includes a pseudo-header containing source/destination IP addresses and protocol information.
The pseudo-header protects against misrouted packets but is not actually transmitted on the wire.
hdr | Reference to pseudo-header structure (UDP/TCP pseudo-header) |
addr | Pointer to data to checksum following the pseudo-header |
count | Number of bytes in the data portion |
#include <ip.h>
Get UDP packet pointer from IP packet pointer.
Calculates the location of the UDP header by skipping past the IP header. This function accounts for variable-length IP headers (with or without options) by examining the header length field.
pIp | Pointer to IP header |
void InitializeStack | ( | ) |
#include <ip.h>
Initialize the IP protocol stack.
Initializes the IP layer and underlying network infrastructure. This function should be called once during system startup, before the application calls init() or configures network interfaces.
This function:
void IpProcessEthernetPacket | ( | PoolPtr | poolPtr, |
uint16_t | packetSizeInBytes ) |
#include <ip.h>
Process an Ethernet packet for IP layer handling.
This internal function is called by the Ethernet layer to insert received packets into the IP processing pipeline. It handles the transition from Ethernet frame processing to IP packet processing.
poolPtr | Pointer to network buffer pool buffer containing the packet |
packetSizeInBytes | Total size of the packet in bytes |
BOOL IsLocal4 | ( | IPADDR4 | ip, |
int | ifc ) |
#include <ip.h>
Check if an IPv4 address is on the local network segment.
Determines if the specified IPv4 address is on the same network segment as the specified interface by comparing network portions of the addresses using the interface's subnet mask. This is useful for:
ip | IPv4 address to check |
ifc | Interface number to check against |
BOOL IsMyIp4 | ( | IPADDR4 | ip, |
int | ifc = -1 ) |
#include <ip.h>
Check if the specified IPv4 address belongs to this device.
Determines whether the given IPv4 address is assigned to any interface on this device. Optionally checks only a specific interface.
ip | IPv4 address to check |
ifc | Interface number to check (default: -1 for all interfaces) |
BOOL IsMyIp6 | ( | const IPADDR & | ip, |
int | ifc = -1 ) |
#include <ip.h>
Check if the specified IPv6 address belongs to this device.
Determines whether the given IPv6 address is assigned to any interface on this device. Optionally checks only a specific interface.
ip | IPv6 address to check |
ifc | Interface number to check (default: -1 for all interfaces) |
|
inline |
#include <ip.h>
Generic ping function that uses IPv6 when IPv6 is enabled.
This inline function provides a generic ping interface that automatically uses the appropriate IPv6 ping function when IPv6 support is compiled in.
to | Destination IP address to ping |
id | ICMP identifier field |
seq | ICMP sequence number field |
maxwaitticks | Maximum wait time in system time ticks |
size | Size of ping data payload in bytes (default: 32) |
int Ping4 | ( | IPADDR4 | to, |
uint16_t | id, | ||
uint16_t | seq, | ||
uint16_t | maxwaitticks ) |
#include <ip.h>
Send a "ping" packet and wait the specified timeout for a response.
Sends an ICMP echo request packet to the specified destination address and waits for an echo reply. The ping uses the primary network interface (usually Ethernet). For interface selection, use Ping4ViaInterface().
The ping packet contains 32 bytes of ASCII data (starting with 'a' (0x61) through 0xFF) and expects an echo reply with the same data. This follows the standard ICMP echo request/reply protocol defined in RFC 792.
to | Destination IPv4 address to ping |
id | ICMP identifier field (typically process ID or sequence) |
seq | ICMP sequence number field (typically increments per ping) |
maxwaitticks | Maximum wait time in system time ticks. Use TICKS_PER_SECOND macro for conversion (e.g., TICKS_PER_SECOND * 5 for 5 seconds) |
int Ping4ViaInterface | ( | IPADDR4 | to, |
uint16_t | id, | ||
uint16_t | seq, | ||
uint16_t | wait, | ||
int | interface ) |
#include <ip.h>
Send a "ping" packet via a specific network interface and wait for a response.
Similar to Ping4(), but allows selection of a specific network interface for sending the ICMP echo request. This is useful in multi-homed systems where you need to control which interface is used for the ping, such as:
to | Destination IPv4 address to ping |
id | ICMP identifier field (typically process ID) |
seq | ICMP sequence number field |
wait | Maximum wait time in system time ticks |
interface | Network interface number to use for sending the ping (0-based) |
int Ping6 | ( | const IPADDR & | to, |
uint16_t | id, | ||
uint16_t | seq, | ||
uint16_t | maxwaitticks, | ||
int | size = 32 ) |
#include <ip.h>
Send an IPv6 "ping" packet and wait the specified timeout for a response.
Sends an ICMPv6 echo request packet to the specified IPv6 destination address and waits for an echo reply. The ping uses the primary network interface. This follows the ICMPv6 echo request/reply protocol defined in RFC 4443.
to | Destination IPv6 address to ping |
id | ICMP identifier field (typically process ID) |
seq | ICMP sequence number field (typically increments per ping) |
maxwaitticks | Maximum wait time in system time ticks |
size | Size of ping data payload in bytes (default: 32) |
int Ping6ViaInterface | ( | const IPADDR & | to, |
uint16_t | id, | ||
uint16_t | seq, | ||
uint16_t | wait, | ||
int | interface, | ||
int | size = 32 ) |
#include <ip.h>
Send an IPv6 "ping" packet via a specific network interface.
Similar to Ping6(), but allows selection of a specific network interface for sending the ICMPv6 echo request. This is particularly important for IPv6 where link-local addresses are interface-specific.
to | Destination IPv6 address to ping |
id | ICMP identifier field (typically process ID) |
seq | ICMP sequence number field |
wait | Maximum wait time in system time ticks |
interface | Network interface number to use for sending the ping |
size | Size of ping data payload in bytes (default: 32) |
|
inline |
#include <ip.h>
Generic ping via interface function that uses IPv6 when IPv6 is enabled.
This inline function provides a generic ping via interface that automatically uses the appropriate IPv6 ping function when IPv6 support is compiled in.
to | Destination IP address to ping |
id | ICMP identifier field |
seq | ICMP sequence number field |
wait | Maximum wait time in system time ticks |
interface | Network interface number to use |
size | Size of ping data payload in bytes (default: 32) |
void SendICMPError | ( | PoolPtr | pBadPacket, |
uint8_t | type, | ||
uint8_t | code ) |
#include <ip.h>
Send an ICMP error message in response to a bad packet.
Generates and sends an appropriate ICMP error message in response to a malformed or problematic IP packet. The original packet data is included in the ICMP error message as required by the ICMP specification (typically the first 8 bytes of the original packet's payload).
pBadPacket | Pointer to the buffer containing the problematic packet |
type | ICMP error type code (e.g., ICMP_TYPE_DEST_UNREACHABLE) |
code | ICMP error code within the type (e.g., ICMP_CODE_PORT_UNREACHABLE) |
void ShowIPBuffer | ( | PoolPtr | rp | ) |
#include <ip.h>
Display the contents of a network buffer for diagnostic purposes.
This function provides a formatted dump of the packet contents in the specified network buffer pool buffer. The output is sent using iprintf() and includes both hexadecimal and ASCII representations of the packet data, making it easy to analyze packet structure and contents.
Typical output format:
rp | Packet pointer from network buffer pool to display |
|
extern |
#include <ip.h>
Global function pointer for fragment processing callback.
Set this pointer to your FragmentProcessFunction implementation to handle fragmented IP packets. Set to NULL (default) to disable fragment processing callbacks, in which case fragmented packets will be silently dropped.
|
extern |
#include <ip.h>
Global function pointer for promiscuous packet processing callback.
Set this pointer to your PromisciousPacketFunc implementation to handle packets not addressed to this device. Set to NULL (default) to disable promiscuous mode, in which case non-local packets will be silently dropped.
|
extern |
#include <ip.h>
Global function pointer for UDP task packet processing callback.
Set this pointer to your TaskPacketFunc implementation to handle UDP packets in task context. Set to NULL (default) to disable task-level UDP packet processing.