#define strdup(Str) _strdup(_MODULE_NAME_"/"__FILE__, __LINE__, (Str))
extern char *_strdup(const char *File, int Line, const char *Str);
extern char **str_split(const char *__str, char __ch);
+extern char *strchr(const char *__s, int __c);
extern int strpos(const char *Str, char Ch);
extern int strpos8(const char *str, Uint32 search);
extern void itoa(char *buf, Uint num, int base, int minLength, char pad);
extern int WriteUTF8(Uint8 *str, Uint32 Val);
extern int ModUtil_SetIdent(char *Dest, char *Value);
extern int ModUtil_LookupString(char **Array, char *Needle);
+
extern Uint8 ByteSum(void *Ptr, int Size);
+extern int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
/**
* \}
*/
int sprintf(char *__s, const char *__format, ...);
int tolower(int c);
int strucmp(const char *Str1, const char *Str2);
+char *strchr(const char *__s, int __c);
int strpos(const char *Str, char Ch);
Uint8 ByteSum(void *Ptr, int Size);
size_t strlen(const char *__s);
int strpos8(const char *str, Uint32 Search);
int ReadUTF8(Uint8 *str, Uint32 *Val);
int WriteUTF8(Uint8 *str, Uint32 Val);
+
int DivUp(int num, int dem);
Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year);
Uint rand(void);
+
int CheckString(char *String);
int CheckMem(void *Mem, int NumBytes);
+
int ModUtil_LookupString(char **Array, char *Needle);
int ModUtil_SetIdent(char *Dest, char *Value);
+
+ int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
// === EXPORTS ===
EXPORT(atoi);
EXPORT(sprintf);
EXPORT(tolower);
EXPORT(strucmp);
+EXPORT(strchr);
EXPORT(strpos);
EXPORT(ByteSum);
EXPORT(strlen);
EXPORT(CheckMem);
EXPORT(ModUtil_LookupString);
EXPORT(ModUtil_SetIdent);
+EXPORT(UnHex);
// === CODE ===
/**
return tolower(*Str1) - tolower(*Str2);
}
+/**
+ * \brief Locate a byte in a string
+ */
+char *strchr(const char *__s, int __c)
+{
+ for( ; *__s; __s ++ )
+ {
+ if( *__s == __c ) return (char*)__s;
+ }
+ return NULL;
+}
+
/**
* \fn int strpos(const char *Str, char Ch)
* \brief Search a string for an ascii character
strncpy(Dest, Value, 32);
return 1;
}
+
+/**
+ * \brief Convert a string of hexadecimal digits into a byte stream
+ */
+int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString)
+{
+ int i;
+
+ for( i = 0; i < DestSize*2; i += 2 )
+ {
+ Uint8 val = 0;
+
+ if(SourceString[i] == '\0') break;
+
+ if('0' <= SourceString[i] && SourceString[i] <= '9')
+ val |= (SourceString[i]-'0') << 4;
+ else if('A' <= SourceString[i] && SourceString[i] <= 'F')
+ val |= (SourceString[i]-'A'+10) << 4;
+ else if('a' <= SourceString[i] && SourceString[i] <= 'f')
+ val |= (SourceString[i]-'a'+10) << 4;
+
+ if(SourceString[i+1] == '\0') break;
+
+ if('0' <= SourceString[i+1] && SourceString[i+1] <= '9')
+ val |= (SourceString[i+1] - '0');
+ else if('A' <= SourceString[i+1] && SourceString[i+1] <= 'F')
+ val |= (SourceString[i+1] - 'A' + 10);
+ else if('a' <= SourceString[i+1] && SourceString[i+1] <= 'f')
+ val |= (SourceString[i+1] - 'a' + 10);
+
+ Dest[i/2] = val;
+ }
+ return i/2;
+}
\r
// Sanity Check Magic value\r
if(sb.s_magic != 0xEF53) {\r
- Log_Warning("EXT2", "Volume '%s' is not an EXT2 volume", Device);\r
+ Log_Warning("EXT2", "Volume '%s' is not an EXT2 volume (0x%x != 0xEF53)",\r
+ Device, sb.s_magic);\r
VFS_Close(fd);\r
LEAVE('n');\r
return NULL;\r
tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name);
int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data);
- int IPStack_AddInterface(const char *Device, const char *Name);
int IPStack_AddFile(tSocketFile *File);
+tInterface *IPStack_AddInterface(const char *Device, const char *Name);
tAdapter *IPStack_GetAdapter(const char *Path);
char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos);
if( !CheckString( Data ) ) LEAVE_RET('i', -1);
{
char name[4] = "";
- tmp = IPStack_AddInterface(Data, name);
+ tInterface *iface = IPStack_AddInterface(Data, name);
+ tmp = iface->Node.ImplInt;
}
LEAVE_RET('i', tmp);
}
}
/**
- * \fn int IPStack_AddInterface(char *Device)
+ * \fn tInterface *IPStack_AddInterface(char *Device)
* \brief Adds an interface to the list
*/
-int IPStack_AddInterface(const char *Device, const char *Name)
+tInterface *IPStack_AddInterface(const char *Device, const char *Name)
{
tInterface *iface;
tAdapter *card;
card = IPStack_GetAdapter(Device);
if( !card ) {
- LEAVE('i', -1);
- return -1; // ERR_YOURBAD
+ LEAVE('n');
+ return NULL; // ERR_YOURBAD
}
nameLen = sprintf(NULL, "%i", giIP_NextIfaceId);
+ IPStack_GetAddressSize(-1)
);
if(!iface) {
- LEAVE('i', -2);
- return -2; // Return ERR_MYBAD
+ LEAVE('n');
+ return NULL; // Return ERR_MYBAD
}
iface->Next = NULL;
iface->Adapter = IPStack_GetAdapter(Device);
if( !iface->Adapter ) {
free( iface );
- LEAVE('i', -1);
- return -1; // Return ERR_YOUFAIL
+ LEAVE('n');
+ return NULL; // Return ERR_YOUFAIL
}
// Delay setting ImplInt until after the adapter is opened
// gIP_DriverInfo.RootNode.Size ++;
// Success!
- LEAVE('i', iface->Node.ImplInt);
- return iface->Node.ImplInt;
+ LEAVE('p', iface);
+ return iface;
}
/**
Uint32 checksum;
// Wait for a packet (Read on a network device is blocking)
+ Log_Debug("NET", "Waiting on adapter FD#0x%x", Adapter->DeviceFD);
ret = VFS_Read(Adapter->DeviceFD, MAX_PACKET_SIZE, buf);
if(ret == -1) break;
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);
for( i = 0; Arguments[i]; i++ )
{
// TODO:
- // Define interfaces by <Device>,<Type>,<HexStreamAddress>,<Bits>
+ // 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
+ // 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, "");
+ iface->Type = iType;
+ memcpy(iface->Address, addrData, size);
+ iface->SubnetBits = iBits;
+ }
+ }
// I could also define routes using <Interface>,<HexStreamNetwork>,<Bits>,<HexStreamGateway>
- // Example: 1,00000000,0,0A000201
+ // Example: 1:00000000:0:0A000201
}
}
int len = ioctl(fd, call_num, NULL);
char *buf = malloc(len+1);
ioctl(fd, call_num, buf);
- printf("'%s'\t", buf);
+ printf("'%s'\n", buf);
free(buf);
}
+ printf("\t");
// Get the address type
switch(type)
{
{
uint8_t ip[4];
int subnet;
- printf("IPv4\n");
+ printf("IPv4\t");
ioctl(fd, 5, ip); // Get IP Address
subnet = ioctl(fd, 7, NULL); // Get Subnet Bits
- printf("\tAddress: %i.%i.%i.%i/%i\n", ip[0], ip[1], ip[2], ip[3], subnet);
+ printf("%i.%i.%i.%i/%i\n", ip[0], ip[1], ip[2], ip[3], subnet);
}
break;
case 6: // IPv6
{
uint16_t ip[8];
int subnet;
- printf("IPv6\n");
+ printf("IPv6\t");
ioctl(fd, 5, ip); // Get IP Address
subnet = ioctl(fd, 7, NULL); // Get Subnet Bits
- printf("\t%x:%x:%x:%x:%x:%x:%x:%x/%i\n",
+ printf("%x:%x:%x:%x:%x:%x:%x:%x/%i\n",
ntohs(ip[0]), ntohs(ip[1]), ntohs(ip[2]), ntohs(ip[3]),
ntohs(ip[4]), ntohs(ip[5]), ntohs(ip[6]), ntohs(ip[7]),
subnet);
printf("UNKNOWN (%i)\n", type);
break;
}
- printf("\n");
close(fd);
}