X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Fmain.c;h=6dac9382728bba9dc57e60afa1102329f1ac7bad;hb=7758e1bf2e2a1ad35def1eb8cf9aab55d13e05a0;hp=ef1a2cd84df09ec7afb949322d961f2f4f6cb8d6;hpb=41769c02317835472d7678d3531ecfc23df8e17a;p=tpg%2Facess2.git diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index ef1a2cd8..6dac9382 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -21,6 +21,7 @@ extern char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos); extern tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name); extern int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data); extern tInterface gIP_LoopInterface; +extern tInterface *IPStack_AddInterface(const char *Device, const char *Name); // === PROTOTYPES === int IPStack_Install(char **Arguments); @@ -64,17 +65,60 @@ int IPStack_Install(char **Arguments) for( i = 0; Arguments[i]; i++ ) { // TODO: - // Define interfaces by ,,, + // Define interfaces by ::: // Where: // - is the device path (E.g. /Devices/ne2k/0) // - is a number (e.g. 4) or symbol (e.g. AF_INET4) // - is a condensed hexadecimal stream (in big endian) // (E.g. 0A000201 for 10.0.2.1 IPv4) // - is the number of subnet bits (E.g. 24 for an IPv4 Class C) - // Example: /Devices/ne2k/0,4,0A00020A,24 + // 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", ":::"); + continue; + } + *type = '\0'; type ++; + + addr = strchr(type, ':'); + if( !addr ) { + Log_Warning("IPStack", ":::"); + continue; + } + *addr = '\0'; addr ++; + + bits = strchr(addr, ':'); + if( !bits ) { + Log_Warning("IPStack", ":::"); + 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, ""); + iface->Type = iType; + memcpy(iface->Address, addrData, size); + iface->SubnetBits = iBits; + } + } // I could also define routes using ,,, - // Example: 1,00000000,0,0A000201 + // Example: 1:00000000:0:0A000201 } } @@ -122,7 +166,7 @@ int IPStack_CompareAddress(int AddressType, void *Address1, void *Address2, int if( CheckBits < 0 ) CheckBits = 0; if( CheckBits > size*8 ) CheckBits = size*8; - if( CheckBits == 0 ) return 1; // /0 matches anythin + if( CheckBits == 0 ) return 1; // /0 matches anythin0 // Check first bits/8 bytes if( memcmp(Address1, Address2, CheckBits/8) != 0 ) return 0;