3 * - Stack Initialisation
6 #define VERSION VER2(0,10)
13 extern int ARP_Initialise();
14 extern void UDP_Initialise();
15 extern void TCP_Initialise();
16 extern int IPv4_Initialise();
17 extern int IPv6_Initialise();
19 extern tAdapter *IPStack_GetAdapter(const char *Path);
20 extern char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos);
21 extern tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name);
22 extern int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data);
23 extern tInterface gIP_LoopInterface;
26 int IPStack_Install(char **Arguments);
27 int IPStack_CompareAddress(int AddressType, void *Address1, void *Address2, int CheckBits);
30 MODULE_DEFINE(0, VERSION, IPStack, IPStack_Install, NULL, NULL);
31 tDevFS_Driver gIP_DriverInfo = {
34 .Size = -1, // Number of interfaces
36 .ACLs = &gVFS_ACL_EveryoneRX,
37 .Flags = VFS_FFLAG_DIRECTORY,
38 .ReadDir = IPStack_Root_ReadDir,
39 .FindDir = IPStack_Root_FindDir,
40 .IOCtl = IPStack_Root_IOCtl
46 * \fn int IPStack_Install(char **Arguments)
47 * \brief Intialise the relevant parts of the stack and register with DevFS
49 int IPStack_Install(char **Arguments)
53 // Layer 3 - Network Layer Protocols
57 // Layer 4 - Transport Layer Protocols
63 // Parse module arguments
64 for( i = 0; Arguments[i]; i++ )
67 // Define interfaces by <Device>,<Type>,<HexStreamAddress>,<Bits>
69 // - <Device> is the device path (E.g. /Devices/ne2k/0)
70 // - <Type> is a number (e.g. 4) or symbol (e.g. AF_INET4)
71 // - <HexStreamAddress> is a condensed hexadecimal stream (in big endian)
72 // (E.g. 0A000201 for 10.0.2.1 IPv4)
73 // - <Bits> is the number of subnet bits (E.g. 24 for an IPv4 Class C)
77 gIP_LoopInterface.Adapter = IPStack_GetAdapter("/Devices/fifo/anon");
79 DevFS_AddDevice( &gIP_DriverInfo );
85 * \brief Gets the size (in bytes) of a specified form of address
87 int IPStack_GetAddressSize(int AddressType)
102 * \brief Compare two IP Addresses masked by CheckBits
104 int IPStack_CompareAddress(int AddressType, void *Address1, void *Address2, int CheckBits)
106 int size = IPStack_GetAddressSize(AddressType);
108 Uint8 *addr1 = Address1, *addr2 = Address2;
111 if( CheckBits < 0 ) CheckBits = 0;
112 if( CheckBits > size*8 ) CheckBits = size*8;
114 // Check first bits/8 bytes
115 if( memcmp(Address1, Address2, CheckBits/8) != 0 ) return 0;
117 // Check if the mask is a multiple of 8
118 if( CheckBits % 8 == 0 ) return 1;
121 mask = 0xFF << (8 - (CheckBits % 8));
122 if( (addr1[CheckBits/8] & mask) == (addr2[CheckBits/8] & mask) )