Modules/IPStack - Add structure for propagating ICMP errors
[tpg/acess2.git] / KernelLand / Modules / IPStack / ipv4.h
1 /*
2  * Acess2 IP Stack
3  * - IPv4 Definitions
4  */
5 #ifndef _IPV4_H_
6 #define _IPV4_H_
7
8 #include "ipstack.h"
9 #include "include/buffer.h"
10
11 typedef struct sIPv4Header      tIPv4Header;
12
13 struct sIPv4Header
14 {
15         struct {
16                 // Spec says Version is first, but stupid bit ordering
17                 unsigned HeaderLength:  4;      // in 4-byte chunks
18                 unsigned Version:       4;      // = 4
19         } __attribute__((packed));
20         Uint8   DiffServices;   // Differentiated Services
21         Uint16  TotalLength;
22         Uint16  Identifcation;
23         
24         struct {
25                 unsigned Reserved:      1;
26                 unsigned DontFragment:  1;
27                 unsigned MoreFragments: 1;
28                 unsigned FragOffLow:    5;
29         } __attribute__((packed));
30         Uint8   FragOffHi;      // Number of 8-byte blocks from the original start
31         
32         Uint8   TTL;    // Max number of hops, effectively
33         Uint8   Protocol;
34         Uint16  HeaderChecksum; // One's Complement Sum of the entire header must equal zero
35         
36         tIPv4   Source;
37         tIPv4   Destination;
38         
39         Uint8   Options[];
40 } __attribute__((packed));
41
42 #define IP4PROT_ICMP    1
43 #define IP4PROT_TCP     6
44 #define IP4PROT_UDP     17
45 #define IPV4_BUFFERS    3       // 1 + Link
46
47 #define IPV4_ETHERNET_ID        0x0800
48
49 // === FUNCTIONS ===
50 extern int      IPv4_RegisterCallback(int ID, tIPRxCallback *RxCallback, tIPErrorCallback *ErrCallback);
51 extern Uint16   IPv4_Checksum(const void *Buf, size_t Length);
52 extern Uint32   IPv4_Netmask(int FixedBits);
53 extern int      IPv4_SendPacket(tInterface *Iface, tIPv4 Address, int Protocol, int ID, tIPStackBuffer *Buffer);
54
55 extern void     IPv4_HandleError(tInterface *Iface, tIPErrorMode Mode, size_t Length, const void *Buf);
56
57 #endif

UCC git Repository :: git.ucc.asn.au