Cleanups & Implementations to allow IPStack to compile
[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 <common.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 };
23
24 union uIPv6 {
25         Uint32  L[4];
26         Uint8   B[16];
27 };
28
29 struct sMacAddr {
30         Uint8   B[6];
31 };
32
33 struct sInterface {
34         struct sInterface       *Next;
35         tVFS_Node       Node;
36         tAdapter        *Adapter;
37          int    Type;   // 4 for IPv4 and 6 for IPv6
38         union {
39                 struct  {
40                         tIPv6   Address;
41                          int    SubnetBits;
42                 }       IP6;
43                 
44                 struct {
45                         tIPv4   Address;
46                         tIPv4   Gateway;
47                          int    SubnetBits;
48                 }       IP4;
49         };
50 };
51
52 /**
53  * \brief Represents a network adapter
54  */
55 struct sAdapter {
56         struct sAdapter *Next;
57         
58          int    DeviceFD;
59          int    NRef;
60         
61         tMacAddr        MacAddr;
62         char    Device[];
63 };
64
65 static const tMacAddr cMAC_BROADCAST = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
66
67 #define MAC_SET(t,v)    memcpy(&(t),&(v),sizeof(tMacAddr))
68 #define IP4_SET(t,v)    (t).L = (v).L;
69 #define IP6_SET(t,v)    memcpy(&(t),&(v),sizeof(tIPv6))
70
71 #define MAC_EQU(a,b)    memcmp(&(a),&(b),sizeof(tMacAddr))
72 #define IP4_EQU(a,b)    ((a).L==(b).L)
73 #define IP6_EQU(a,b)    memcmp(&(a),&(b),sizeof(tIPv6))
74
75 // === FUNCTIONS ===
76 #define htonb(v)        (v)
77 #define htons(in)       BigEndian16(in)
78 #define htonl(in)       BigEndian32(in)
79 #define ntonb(v)        (v)
80 #define ntohs(in)       BigEndian16(in)
81 #define ntohl(in)       BigEndian16(in)
82
83 #endif

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