IPv6, and I need to learn to compile before commiting
[tpg/acess2.git] / Modules / IPStack / ipstack.h
1 /*
2  * Acess2 IP Stack
3  * - Common Header
4  */
5 #ifndef _IPSTACK_H_
6 #define _IPSTACK_H_
7
8 #include <acess.h>
9 #include <vfs.h>
10
11 typedef union uIPv4     tIPv4;
12 typedef union uIPv6     tIPv6;
13 typedef struct sMacAddr tMacAddr;
14 typedef struct sAdapter tAdapter;
15 typedef struct sInterface       tInterface;
16 typedef struct sSocketFile      tSocketFile;
17
18 typedef void    (*tIPCallback)(tInterface *Interface, void *Address, int Length, void *Buffer);
19
20 union uIPv4 {
21         Uint32  L;
22         Uint8   B[4];
23 } __attribute__((packed));
24
25 union uIPv6 {
26         Uint32  L[4];
27         Uint8   B[16];
28 } __attribute__((packed));
29
30 struct sMacAddr {
31         Uint8   B[6];
32 } __attribute__((packed));
33
34 struct sInterface {
35         struct sInterface       *Next;
36         tVFS_Node       Node;
37         tAdapter        *Adapter;
38          int    TimeoutDelay;   // Time in miliseconds before a connection times out
39          int    Type;   // 0 for disabled, 4 for IPv4 and 6 for IPv6
40         union {
41                 struct  {
42                         tIPv6   Address;
43                          int    SubnetBits;     //Should this be outside the union?
44                 }       IP6;
45                 
46                 struct {
47                         tIPv4   Address;
48                         tIPv4   Gateway;
49                          int    SubnetBits;
50                 }       IP4;
51         };
52 };
53
54 /**
55  * \brief Represents a network adapter
56  */
57 struct sAdapter {
58         struct sAdapter *Next;
59         
60          int    DeviceFD;
61          int    NRef;
62         
63         tMacAddr        MacAddr;
64         char    Device[];
65 };
66
67 /**
68  * \brief Describes a socket file definition
69  */
70 struct sSocketFile
71 {
72         struct sSocketFile      *Next;
73         const char      *Name;
74         
75         tVFS_Node       *(*Init)(tInterface *Interface);
76 };
77
78 static const tMacAddr cMAC_BROADCAST = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
79
80 #define MAC_SET(t,v)    memcpy(&(t),&(v),sizeof(tMacAddr))
81 #define IP4_SET(t,v)    (t).L = (v).L;
82 #define IP6_SET(t,v)    memcpy(&(t),&(v),sizeof(tIPv6))
83
84 #define MAC_EQU(a,b)    memcmp(&(a),&(b),sizeof(tMacAddr))
85 #define IP4_EQU(a,b)    ((a).L==(b).L)
86 #define IP6_EQU(a,b)    memcmp(&(a),&(b),sizeof(tIPv6))
87
88 // === FUNCTIONS ===
89 #define htonb(v)        (v)
90 #define htons(in)       BigEndian16(in)
91 #define htonl(in)       BigEndian32(in)
92 #define ntonb(v)        (v)
93 #define ntohs(in)       BigEndian16(in)
94 #define ntohl(in)       BigEndian32(in)
95
96 extern int      IPStack_AddFile(tSocketFile *File);
97
98 #endif

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