Cleanup Commit
[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          int    DeviceLen;
65         char    Device[];
66 };
67
68 /**
69  * \brief Describes a socket file definition
70  */
71 struct sSocketFile
72 {
73         struct sSocketFile      *Next;
74         const char      *Name;
75         
76         tVFS_Node       *(*Init)(tInterface *Interface);
77 };
78
79 static const tMacAddr cMAC_BROADCAST = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
80
81 #define MAC_SET(t,v)    memcpy(&(t),&(v),sizeof(tMacAddr))
82 #define IP4_SET(t,v)    (t).L = (v).L;
83 #define IP6_SET(t,v)    memcpy(&(t),&(v),sizeof(tIPv6))
84
85 #define MAC_EQU(a,b)    memcmp(&(a),&(b),sizeof(tMacAddr))
86 #define IP4_EQU(a,b)    ((a).L==(b).L)
87 #define IP6_EQU(a,b)    memcmp(&(a),&(b),sizeof(tIPv6))
88
89 // === FUNCTIONS ===
90 #define htonb(v)        (v)
91 #define htons(in)       BigEndian16(in)
92 #define htonl(in)       BigEndian32(in)
93 #define ntonb(v)        (v)
94 #define ntohs(in)       BigEndian16(in)
95 #define ntohl(in)       BigEndian32(in)
96
97 extern int      IPStack_AddFile(tSocketFile *File);
98
99 #endif

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