Kernel/armv7 - Bugfixes
[tpg/acess2.git] / 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
10 typedef struct sIPv4Header      tIPv4Header;
11
12 struct sIPv4Header
13 {
14         struct {
15                 // Spec says Version is first, but stupid bit ordering
16                 unsigned HeaderLength:  4;      // in 4-byte chunks
17                 unsigned Version:       4;      // = 4
18         } __attribute__((packed));
19         Uint8   DiffServices;   // Differentiated Services
20         Uint16  TotalLength;
21         Uint16  Identifcation;
22         
23         struct {
24                 unsigned Reserved:      1;
25                 unsigned DontFragment:  1;
26                 unsigned MoreFragments: 1;
27                 unsigned FragOffLow:    5;
28         } __attribute__((packed));
29         Uint8   FragOffHi;      // Number of 8-byte blocks from the original start
30         
31         Uint8   TTL;    // Max number of hops, effectively
32         Uint8   Protocol;
33         Uint16  HeaderChecksum; // One's Complement Sum of the entire header must equal zero
34         
35         tIPv4   Source;
36         tIPv4   Destination;
37         
38         Uint8   Options[];
39 } __attribute__((packed));
40
41 #define IP4PROT_ICMP    1
42 #define IP4PROT_TCP     6
43 #define IP4PROT_UDP     17
44
45 #define IPV4_ETHERNET_ID        0x0800
46
47 // === FUNCTIONS ===
48 extern int      IPv4_RegisterCallback(int ID, tIPCallback Callback);
49 extern Uint16   IPv4_Checksum(const void *Buf, size_t Length);
50 extern int      IPv4_SendPacket(tInterface *Iface, tIPv4 Address, int Protocol, int ID, int Length, const void *Data);
51
52 #endif

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