SpiderScript! (with a sample script)
[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         Uint16  W[8];
27         Uint32  L[4];
28         Uint8   B[16];
29 } __attribute__((packed));
30
31 struct sMacAddr {
32         Uint8   B[6];
33 } __attribute__((packed));
34
35 struct sInterface {
36         struct sInterface       *Next;
37         tVFS_Node       Node;
38         tAdapter        *Adapter;
39          int    TimeoutDelay;   // Time in miliseconds before a packet times out
40          int    Type;   // 0 for disabled, 4 for IPv4 and 6 for IPv6
41         union {
42                 struct  {
43                         tIPv6   Address;
44                          int    SubnetBits;     //Should this be outside the union?
45                 }       IP6;
46                 
47                 struct {
48                         tIPv4   Address;
49                         tIPv4   Gateway;
50                          int    SubnetBits;
51                 }       IP4;
52         };
53 };
54
55 /**
56  * \brief Represents a network adapter
57  */
58 struct sAdapter {
59         struct sAdapter *Next;
60         
61          int    DeviceFD;
62          int    NRef;
63         
64         tMacAddr        MacAddr;
65          int    DeviceLen;
66         char    Device[];
67 };
68
69 /**
70  * \brief Describes a socket file definition
71  */
72 struct sSocketFile
73 {
74         struct sSocketFile      *Next;
75         const char      *Name;
76         
77         tVFS_Node       *(*Init)(tInterface *Interface);
78 };
79
80 static const tMacAddr cMAC_BROADCAST = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
81
82 #define MAC_SET(t,v)    memcpy(&(t),&(v),sizeof(tMacAddr))
83 #define IP4_SET(t,v)    (t).L = (v).L;
84 #define IP6_SET(t,v)    memcpy(&(t),&(v),sizeof(tIPv6))
85
86 #define MAC_EQU(a,b)    (memcmp(&(a),&(b),sizeof(tMacAddr))==0)
87 #define IP4_EQU(a,b)    ((a).L==(b).L)
88 #define IP6_EQU(a,b)    (memcmp(&(a),&(b),sizeof(tIPv6))==0)
89
90 // === FUNCTIONS ===
91 #define htonb(v)        (v)
92 #define htons(v)        BigEndian16(v)
93 #define htonl(v)        BigEndian32(v)
94 #define ntonb(v)        (v)
95 #define ntohs(v)        BigEndian16(v)
96 #define ntohl(v)        BigEndian32(v)
97
98 extern int      IPStack_AddFile(tSocketFile *File);
99
100 #endif

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