61#define IP_VERSION_MASK (0xF0)
62#define IP_VERSION_IPv4 (0x40)
63#define IP_VERSION_IPv6 (0x60)
69#define IP_HEADER_LENGTH_MASK (0x0F)
70#define IP_HEADER_LENGTH_NO_OPTIONS (0x05)
76#define IP_FLAGS_MASK (0xE000)
77#define IP_FRAGMENT_OFFSET_MASK (0x1FFF)
85#define IP_PROTOCOL_ICMP (0x01)
86#define IP_PROTOCOL_IGMP (0x02)
87#define IP_PROTOCOL_INTERNET (0x04)
88#define IP_PROTOCOL_TCP (0x06)
89#define IP_PROTOCOL_UDP (0x11)
97#define ICMP_TYPE_ECHO_REPLY (0)
98#define ICMP_CODE_ECHO_REPLY (0)
99#define ICMP_TYPE_DEST_UNREACHABLE (3)
100#define ICMP_CODE_PORT_UNREACHABLE (3)
101#define ICMP_TYPE_SOURCE_QUENCH (4)
102#define ICMP_CODE_SOURCE_QUENCH (0)
103#define ICMP_TYPE_REDIRECT_MESSAGE (5)
104#define ICMP_TYPE_ECHO_REQUEST (8)
105#define ICMP_CODE_ECHO_REQUEST (0)
113#define IANA_ECHO_PORT (7)
114#define IANA_DISCARD_PORT (9)
115#define IANA_SSH_PORT (22)
116#define IANA_TELNET_PORT (23)
118#define IANA_NETBIOS_NAME_SERVICE_PORT (137)
121#define ICMP_PING_DATA_SIZE (32)
184} __attribute__((packed))
IPPKT;
210} __attribute__((packed))
UDPPKT;
293 uint16_t
GetSum(puint16_t addr, uint16_t count);
634 return (p == NULL) ? NULL : (
PIPPKT)(p->
pData + 14);
647 return (
PIPPKT)(pFrame->pData);
660 return (
PIPPKT)(pFrame->pData);
678 if (pIp == NULL) {
return NULL; }
827typedef int(TaskPacketFunc)(
UDPPacket &pkt,
int ifn);
907int Ping4(
IPADDR4 to, uint16_t
id, uint16_t seq, uint16_t maxwaitticks);
965int Ping6(
const IPADDR &to, uint16_t
id, uint16_t seq, uint16_t maxwaitticks,
int size = 32);
1008inline int Ping(
const IPADDR &to, uint16_t
id, uint16_t seq, uint16_t maxwaitticks,
int size = 32)
1010 return Ping6(to,
id, seq, maxwaitticks, size);
1050inline int Ping(
IPADDR4 to, uint16_t
id, uint16_t seq, uint16_t maxwaitticks)
1052 return Ping4(to,
id, seq, maxwaitticks);
1132#if defined MULTIHOME || defined AUTOIP
1263#error Got to pick an IP version
1269#error Must select IPV4ONLY or IPV6 but not both
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
UDP Packet Class - Complete UDP packet management.
Definition udp.h:602
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 AddInterface(IPADDR4 addr, IPADDR4 mask, IPADDR4 gateway, int root_if=0)
Add a new network interface with the specified configuration.
Definition multihome.h:151
int GetProperInterface4(IPADDR4 dst)
Get the appropriate interface number for reaching a destination.
void FixHeaderAndSend(PoolPtr p, PIPPKT pIp)
Complete IP header fields and send packet on primary interface.
IPADDR GetSrcIp(const IPADDR &dst)
Generic function to get source IP address for reaching a destination (IPv6 version).
Definition ip.h:450
BOOL bQuietStart
When TRUE, suppresses startup messages during network initialization. Set before calling init().
void FixHeaderAndSendViaInterface(PoolPtr p, PIPPKT pIp, int Interface)
Complete IP header fields and send packet via specified interface.
int GetLocalIPInterface4(IPADDR4 ipa)
Get the local interface number for a specific IPv4 address.
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.
uint16_t GetEphemeralPort()
Generate a random ephemeral port number.
struct _IpHeaderIPv4 IpHeaderIPv4
IP Header Structure (IPv4)
void InitializeStack()
Initialize the IP protocol stack.
FragmentProcessFunction * pFragFunc
Global function pointer for fragment processing callback.
PIPPKT GetIpPkt(PoolPtr p)
Get IP packet pointer from network buffer pool buffer.
Definition ip.h:632
uint16_t wArpLifetime
ARP cache entry lifetime in seconds. Entries older than this are refreshed. Typical value is 300-1200...
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.
IPADDR GetSrcIp6(const IPADDR &dst)
Get the appropriate source IPv6 address for reaching a destination.
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.
void SendICMPError(PoolPtr pBadPacket, uint8_t type, uint8_t code)
Send an ICMP error message in response to a bad packet.
IPADDR GetSrcIpwIf(int ifn, const IPADDR &dst)
Generic function to get source IP address for an interface (IPv6 version).
Definition ip.h:485
TaskPacketFunc * pTaskPacketFunc
Global function pointer for UDP task packet processing callback.
BOOL IsMyIp6(const IPADDR &ip, int ifc=-1)
Check if the specified IPv6 address belongs to this device.
IPADDR4 GetSrcIp4(IPADDR4 dst)
Get the appropriate source IPv4 address for reaching a destination.
uint16_t GetSum20(puint32_t addr)
Calculate Internet checksum for exactly 20 bytes of data.
void FragmentProcessFunction(PoolPtr pp)
User-defined function pointer type for processing fragmented IP packets.
Definition ip.h:730
BOOL IsMyIp(const IPADDR &ip, int ifc=-1)
Generic function to check if IP address belongs to this device (uses IPv6 when available)
Definition ip.h:416
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).
Definition ip.h:1229
int GetMultiHomeInterface(IPADDR4 ipa, int norgif)
Get the multi-home interface for a specific IP address.
IPADDR GetSrcIp6wIf(int ifn, const IPADDR &dst)
Get the source IPv6 address for a specific interface and destination.
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.
Definition ip.h:1008
IPADDR4 GetSrcIpwIf4(int ifn, const IPADDR4 dst)
Get the source IPv4 address for a specific interface and destination.
BOOL IsLocal4(IPADDR4 ip, int ifc)
Check if an IPv4 address is on the local network segment.
void ShowIPBuffer(PoolPtr rp)
Display the contents of a network buffer for diagnostic purposes.
uint16_t GetSumHdr(PsudeoHeader &hdr, puint16_t addr, uint16_t count)
Calculate Internet checksum using a pseudo-header.
PUDPPKT GetUdpPkt(PIPPKT pIp)
Get UDP packet pointer from IP packet pointer.
Definition ip.h:676
void IpProcessEthernetPacket(PoolPtr poolPtr, uint16_t packetSizeInBytes)
Process an Ethernet packet for IP layer handling.
PromisciousPacketFunc * pPromisciousPacketFunc
Global function pointer for promiscuous packet processing callback.
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.
Definition ip.h:1030
uint16_t GetSum(puint16_t addr, uint16_t count)
Calculate Internet checksum for the specified data.
void PromisciousPacketFunc(PoolPtr pp)
User-defined function pointer type for processing promiscuous packets.
Definition ip.h:778
BOOL IsMyIp4(IPADDR4 ip, int ifc=-1)
Check if the specified IPv4 address belongs to this device.
uint8_t bTTL_Default
Default Time To Live (hop count) for outgoing IP packets. Typical value is 64 or 128.
Internal IPv4 Header Representation.
Definition ip.h:169
uint16_t hCSum
Header checksum.
Definition ip.h:180
IPADDR4 ipSrc
Source IP address.
Definition ip.h:181
uint8_t proto
Protocol number (TCP, UDP, ICMP, etc.)
Definition ip.h:176
uint8_t DATA[]
Flexible array member - payload data follows header (actual length varies by packet)
Definition ip.h:183
beuint16_t wLength
Total packet length in bytes including header.
Definition ip.h:172
uint8_t bTTL
Time To Live / hop count.
Definition ip.h:175
uint8_t bTos
Type of Service / Differentiated Services field (same as diffServNEcn)
Definition ip.h:171
beuint16_t wpktId
Packet identification for fragment reassembly.
Definition ip.h:173
uint8_t bVerHdrLen
Version and header length (same as versionNLength in IpHeaderIPv4)
Definition ip.h:170
IPADDR4 ipDst
Destination IP address.
Definition ip.h:182
beuint16_t wFlags_Frag
Flags and fragment offset combined.
Definition ip.h:174
Internal UDP Packet Header Structure.
Definition ip.h:201
beuint16_t dstPort
Destination port number (0-65535)
Definition ip.h:203
beuint16_t srcPort
Source port number (0-65535)
Definition ip.h:202
uint16_t UdpCSum
UDP checksum (optional in IPv4, mandatory in IPv6)
Definition ip.h:208
beuint16_t UdpLen
Datagram length in bytes including UDP header and data (minimum 8 bytes)
Definition ip.h:204
Main buffer structure for network and serial communication.
Definition buffers.h:90
uint8_t pData[ETHER_BUFFER_SIZE]
Buffer data payload (1548 bytes)
Definition buffers.h:104