Multi-user testing and bugfixing
[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
17 typedef void    (*tIPCallback)(tInterface *Interface, void *Address, int Length, void *Buffer);
18
19 union uIPv4 {
20         Uint32  L;
21         Uint8   B[4];
22 } __attribute__((packed));
23
24 union uIPv6 {
25         Uint32  L[4];
26         Uint8   B[16];
27 } __attribute__((packed));
28
29 struct sMacAddr {
30         Uint8   B[6];
31 } __attribute__((packed));
32
33 struct sInterface {
34         struct sInterface       *Next;
35         tVFS_Node       Node;
36         tAdapter        *Adapter;
37          int    TimeoutDelay;   // Time in miliseconds before a connection times out
38          int    Type;   // 0 for disabled, 4 for IPv4 and 6 for IPv6
39         union {
40                 struct  {
41                         tIPv6   Address;
42                          int    SubnetBits;     //Should this be outside the union?
43                 }       IP6;
44                 
45                 struct {
46                         tIPv4   Address;
47                         tIPv4   Gateway;
48                          int    SubnetBits;
49                 }       IP4;
50         };
51 };
52
53 /**
54  * \brief Represents a network adapter
55  */
56 struct sAdapter {
57         struct sAdapter *Next;
58         
59          int    DeviceFD;
60          int    NRef;
61         
62         tMacAddr        MacAddr;
63         char    Device[];
64 };
65
66 static const tMacAddr cMAC_BROADCAST = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
67
68 #define MAC_SET(t,v)    memcpy(&(t),&(v),sizeof(tMacAddr))
69 #define IP4_SET(t,v)    (t).L = (v).L;
70 #define IP6_SET(t,v)    memcpy(&(t),&(v),sizeof(tIPv6))
71
72 #define MAC_EQU(a,b)    memcmp(&(a),&(b),sizeof(tMacAddr))
73 #define IP4_EQU(a,b)    ((a).L==(b).L)
74 #define IP6_EQU(a,b)    memcmp(&(a),&(b),sizeof(tIPv6))
75
76 // === FUNCTIONS ===
77 #define htonb(v)        (v)
78 #define htons(in)       BigEndian16(in)
79 #define htonl(in)       BigEndian32(in)
80 #define ntonb(v)        (v)
81 #define ntohs(in)       BigEndian16(in)
82 #define ntohl(in)       BigEndian32(in)
83
84 #endif

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