- //if(strcmp(Arguments[i], "Device") == '=') {
- //
- //}
- }
- }
-
- DevFS_AddDevice( &gIP_DriverInfo );
-
- return 1;
-}
-
-/**
- * \brief Adds a file to the socket list
- */
-int IPStack_AddFile(tSocketFile *File)
-{
- File->Next = gIP_FileTemplates;
- gIP_FileTemplates = File;
- return 0;
-}
-
-/**
- * \brief Read from the IP Stack's Device Directory
- */
-char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos)
-{
- tInterface *iface;
- char *name;
- ENTER("pNode iPos", Node, Pos);
-
- // Traverse the list
- for( iface = gIP_Interfaces; iface && Pos--; iface = iface->Next ) ;
-
- // Did we run off the end?
- if(!iface) {
- LEAVE('n');
- return NULL;
- }
-
- name = malloc(6);
- name[0] = 'i';
- name[1] = 'p';
-
- // Create the name
- Pos = iface->Node.ImplInt;
- if(Pos < 10) {
- name[2] = '0' + Pos;
- name[3] = '\0';
- }
- else if(Pos < 100) {
- name[2] = '0' + Pos/10;
- name[3] = '0' + Pos%10;
- name[4] = '\0';
- }
- else {
- name[2] = '0' + Pos/100;
- name[3] = '0' + (Pos/10)%10;
- name[4] = '0' + Pos%10;
- name[5] = '\0';
- }
-
- LEAVE('s', name);
- // Return the pre-generated name
- return name;
-}
+ // TODO:
+ // Define interfaces by <Device>:<Type>:<HexStreamAddress>:<Bits>
+ // Where:
+ // - <Device> is the device path (E.g. /Devices/ne2k/0)
+ // - <Type> is a number (e.g. 4) or symbol (e.g. AF_INET4)
+ // - <HexStreamAddress> is a condensed hexadecimal stream (in big endian)
+ // (E.g. 0A000201 for 10.0.2.1 IPv4)
+ // - <Bits> is the number of subnet bits (E.g. 24 for an IPv4 Class C)
+ // Example: /Devices/ne2k/0:4:0A00020A:24
+ // would define an interface with the address 10.0.2.10/24
+ if( Arguments[i][0] == '/' ) {
+ // Define Interface
+ char *dev, *type, *addr, *bits;
+
+ // Read definition
+ dev = Arguments[i];
+ type = strchr(dev, ':');
+ if( !type ) {
+ Log_Warning("IPStack", "<Device>:<Type>:<HexStreamAddress>:<Bits>");
+ continue;
+ }
+ *type = '\0'; type ++;
+
+ addr = strchr(type, ':');
+ if( !addr ) {
+ Log_Warning("IPStack", "<Device>:<Type>:<HexStreamAddress>:<Bits>");
+ continue;
+ }
+ *addr = '\0'; addr ++;
+
+ bits = strchr(addr, ':');
+ if( !bits ) {
+ Log_Warning("IPStack", "<Device>:<Type>:<HexStreamAddress>:<Bits>");
+ continue;
+ }
+ *bits = '\0'; bits ++;
+
+ // Define interface
+ {
+ int iType = atoi(type);
+ int size = IPStack_GetAddressSize(iType);
+ Uint8 addrData[size];
+ int iBits = atoi(bits);
+
+ UnHex(addrData, size, addr);
+
+ tInterface *iface = IPStack_AddInterface(dev, "");
+ if( !iface ) {
+ Log_Warning("IPStack", "Unable to add interface on '%s'", dev);
+ continue ;
+ }
+ iface->Type = iType;
+ memcpy(iface->Address, addrData, size);
+ iface->SubnetBits = iBits;
+
+ // Route for addrData/iBits, no next hop, default metric
+ IPStack_AddRoute(iface->Name, iface->Address, iBits, NULL, 0);