// Route for addrData/iBits, no next hop, default metric
IPStack_AddRoute(iface->Name, iface->Address, iBits, NULL, 0);
}
+
+ continue;
}
- // I could also define routes using <Interface>,<HexStreamNetwork>,<Bits>,<HexStreamGateway>
+ // I could also define routes using <Interface>:<HexStreamNetwork>:<Bits>[:<HexStreamGateway>]
// Example: 1:00000000:0:0A000201
+ if( '0' <= Arguments[i][0] && Arguments[i][0] <= '9' )
+ {
+ // Define Interface
+ char *ifaceName, *network, *bits, *gateway;
+
+ // Read definition
+ ifaceName = Arguments[i];
+
+ network = strchr(ifaceName, ':');
+ if( !network ) {
+ Log_Warning("IPStack", "<iface>:<HexStreamNetwork>:<Bits>:<HexStreamGateway>");
+ continue;
+ }
+ *network = '\0'; network ++;
+
+ bits = strchr(network, ':');
+ if( !bits ) {
+ Log_Warning("IPStack", "<Device>:<Type>:<HexStreamAddress>:<Bits>");
+ continue;
+ }
+ *bits = '\0'; bits ++;
+
+ gateway = strchr(bits, ':');
+ if( gateway ) {
+ *gateway = '\0'; gateway ++;
+ }
+
+ // Define route
+ {
+ tVFS_Node *node = IPStack_Root_FindDir(NULL, ifaceName);
+ if( !node ) {
+ Log_Warning("IPStack", "Unknown interface '%s' in arg %i", ifaceName, i);
+ continue ;
+ }
+ tInterface *iface = node->ImplPtr;
+
+ int size = IPStack_GetAddressSize(iface->Type);
+ Uint8 netData[size];
+ Uint8 gwData[size];
+ int iBits = atoi(bits);
+
+ UnHex(netData, size, network);
+ if( gateway )
+ UnHex(gwData, size, gateway);
+ else
+ memset(gwData, 0, size);
+
+ IPStack_AddRoute(ifaceName, netData, iBits, gwData, 30);
+ }
+
+ continue;
+ }
}
}
tTCPListener *srv;
tTCPConnection *conn;
- Log_Log("TCP", "SourcePort = %i, DestPort = %i",
+ Log_Log("TCP", "TCP_GetPacket: SourcePort = %i, DestPort = %i",
ntohs(hdr->SourcePort), ntohs(hdr->DestPort));
/*
- Log_Log("TCP", "SequenceNumber = 0x%x", ntohl(hdr->SequenceNumber));
- Log_Log("TCP", "AcknowlegementNumber = 0x%x", ntohl(hdr->AcknowlegementNumber));
- Log_Log("TCP", "DataOffset = %i", hdr->DataOffset >> 4);
- Log_Log("TCP", "Flags = {");
- Log_Log("TCP", " CWR = %B, ECE = %B",
+ Log_Log("TCP", "TCP_GetPacket: SequenceNumber = 0x%x", ntohl(hdr->SequenceNumber));
+ Log_Log("TCP", "TCP_GetPacket: AcknowlegementNumber = 0x%x", ntohl(hdr->AcknowlegementNumber));
+ Log_Log("TCP", "TCP_GetPacket: DataOffset = %i", hdr->DataOffset >> 4);
+ Log_Log("TCP", "TCP_GetPacket: Flags = {");
+ Log_Log("TCP", "TCP_GetPacket: CWR = %B, ECE = %B",
!!(hdr->Flags & TCP_FLAG_CWR), !!(hdr->Flags & TCP_FLAG_ECE));
- Log_Log("TCP", " URG = %B, ACK = %B",
+ Log_Log("TCP", "TCP_GetPacket: URG = %B, ACK = %B",
!!(hdr->Flags & TCP_FLAG_URG), !!(hdr->Flags & TCP_FLAG_ACK));
- Log_Log("TCP", " PSH = %B, RST = %B",
+ Log_Log("TCP", "TCP_GetPacket: PSH = %B, RST = %B",
!!(hdr->Flags & TCP_FLAG_PSH), !!(hdr->Flags & TCP_FLAG_RST));
- Log_Log("TCP", " SYN = %B, FIN = %B",
+ Log_Log("TCP", "TCP_GetPacket: SYN = %B, FIN = %B",
!!(hdr->Flags & TCP_FLAG_SYN), !!(hdr->Flags & TCP_FLAG_FIN));
- Log_Log("TCP", "}");
- Log_Log("TCP", "WindowSize = %i", htons(hdr->WindowSize));
- Log_Log("TCP", "Checksum = 0x%x", htons(hdr->Checksum));
- Log_Log("TCP", "UrgentPointer = 0x%x", htons(hdr->UrgentPointer));
+ Log_Log("TCP", "TCP_GetPacket: }");
+ Log_Log("TCP", "TCP_GetPacket: WindowSize = %i", htons(hdr->WindowSize));
+ Log_Log("TCP", "TCP_GetPacket: Checksum = 0x%x", htons(hdr->Checksum));
+ Log_Log("TCP", "TCP_GetPacket: UrgentPointer = 0x%x", htons(hdr->UrgentPointer));
*/
- Log_Log("TCP", "Flags = %s%s%s%s%s%s",
+ Log_Log("TCP", "TCP_GetPacket: Flags = %s%s%s%s%s%s",
(hdr->Flags & TCP_FLAG_CWR) ? "CWR " : "",
(hdr->Flags & TCP_FLAG_ECE) ? "ECE " : "",
(hdr->Flags & TCP_FLAG_URG) ? "URG " : "",
// Check the destination port
if(srv->Port != htons(hdr->DestPort)) continue;
- Log_Log("TCP", "Matches server %p", srv);
+ Log_Log("TCP", "TCP_GetPacket: Matches server %p", srv);
// Is this in an established connection?
for( conn = srv->Connections; conn; conn = conn->Next )
{
- Log_Log("TCP", "conn->Interface(%p) == Interface(%p)",
+ Log_Log("TCP", "TCP_GetPacket: conn->Interface(%p) == Interface(%p)",
conn->Interface, Interface);
// Check that it is coming in on the same interface
if(conn->Interface != Interface) continue;
// Check Source Port
- Log_Log("TCP", "conn->RemotePort(%i) == hdr->SourcePort(%i)",
+ Log_Log("TCP", "TCP_GetPacket: conn->RemotePort(%i) == hdr->SourcePort(%i)",
conn->RemotePort, ntohs(hdr->SourcePort));
if(conn->RemotePort != ntohs(hdr->SourcePort)) continue;
if(conn->Interface->Type == 4 && !IP4_EQU(conn->RemoteIP.v4, *(tIPv4*)Address))
continue;
- Log_Log("TCP", "Matches connection %p", conn);
+ Log_Log("TCP", "TCP_GetPacket: Matches connection %p", conn);
// We have a response!
TCP_INT_HandleConnectionPacket(conn, hdr, Length);
return;
}
- Log_Log("TCP", "Opening Connection");
+ Log_Log("TCP", "TCP_GetPacket: Opening Connection");
// Open a new connection (well, check that it's a SYN)
if(hdr->Flags != TCP_FLAG_SYN) {
- Log_Log("TCP", "Packet is not a SYN");
+ Log_Log("TCP", "TCP_GetPacket: Packet is not a SYN");
return ;
}
}
}
- Log_Log("TCP", "No Match");
+ Log_Log("TCP", "TCP_GetPacket: No Match");
}
/**
int TCP_Client_IOCtl(tVFS_Node *Node, int ID, void *Data)
{
tTCPConnection *conn = Node->ImplPtr;
+
+ ENTER("pNode iID pData", Node, ID, Data);
switch(ID)
{
case 4: // Get/Set local port
if(!Data)
- return conn->LocalPort;
+ LEAVE_RET('i', conn->LocalPort);
if(conn->State != TCP_ST_CLOSED)
- return -1;
+ LEAVE_RET('i', -1);
if(!CheckMem(Data, sizeof(Uint16)))
- return -1;
+ LEAVE_RET('i', -1);
if(Threads_GetUID() != 0 && *(Uint16*)Data < 1024)
- return -1;
+ LEAVE_RET('i', -1);
conn->LocalPort = *(Uint16*)Data;
- return 0;
+ LEAVE_RET('i', conn->LocalPort);
case 5: // Get/Set remote port
- if(!Data) return conn->RemotePort;
- if(conn->State != TCP_ST_CLOSED) return -1;
- if(!CheckMem(Data, sizeof(Uint16))) return -1;
+ if(!Data) LEAVE_RET('i', conn->RemotePort);
+ if(conn->State != TCP_ST_CLOSED) LEAVE_RET('i', -1);
+ if(!CheckMem(Data, sizeof(Uint16))) LEAVE_RET('i', -1);
conn->RemotePort = *(Uint16*)Data;
- return conn->RemotePort;
+ LEAVE_RET('i', conn->RemotePort);
case 6: // Set Remote IP
if( conn->State != TCP_ST_CLOSED )
- return -1;
+ LEAVE_RET('i', -1);
if( conn->Interface->Type == 4 )
{
- if(!CheckMem(Data, sizeof(tIPv4))) return -1;
+ if(!CheckMem(Data, sizeof(tIPv4))) LEAVE_RET('i', -1);
conn->RemoteIP.v4 = *(tIPv4*)Data;
}
else if( conn->Interface->Type == 6 )
{
- if(!CheckMem(Data, sizeof(tIPv6))) return -1;
+ if(!CheckMem(Data, sizeof(tIPv6))) LEAVE_RET('i', -1);
conn->RemoteIP.v6 = *(tIPv6*)Data;
}
- return 0;
+ LEAVE_RET('i', 0);
case 7: // Connect
if(conn->LocalPort == 0xFFFF)
conn->LocalPort = TCP_GetUnusedPort();
if(conn->RemotePort == -1)
- return 0;
+ LEAVE_RET('i', 0);
TCP_StartConnection(conn);
- return 1;
+ LEAVE_RET('i', 1);
// Get recieve buffer length
case 8:
- return conn->RecievedBuffer->Length;
+ LEAVE_RET('i', conn->RecievedBuffer->Length);
}
return 0;
tTCPConnection *conn = Node->ImplPtr;
tTCPHeader packet;
+ ENTER("pNode", Node);
+
packet.SourcePort = htons(conn->LocalPort);
packet.DestPort = htons(conn->RemotePort);
packet.DataOffset = (sizeof(tTCPHeader)/4)*16;
while( conn->State == TCP_ST_FIN_SENT ) Threads_Yield();
free(conn);
+
+ LEAVE('-');
}
}\r
\r
printf("Connection opened\n");\r
+ ProcessIncoming(&srv);\r
\r
writef(srv.FD, "USER %s %s %s : %s\n", gsUsername, gsHostname, gsRemoteAddress, gsRealName);\r
- writef(srv.FD, "NICK %s", gsNickname);\r
+ writef(srv.FD, "NICK %s\n", gsNickname);\r
\r
- ProcessIncoming(&srv);\r
+ printf("Processing\n");\r
+ \r
+ for( ;; )\r
+ {\r
+ ProcessIncoming(&srv);\r
+ }\r
\r
close(srv.FD);\r
return 0;\r
char *ret = Src + pos;\r
char *end;\r
\r
+ if( !Src ) return NULL;\r
+ \r
while( *ret == ' ' ) ret ++;\r
\r
end = strchr(ret, ' ');\r
*/\r
void ParseServerLine(tServer *Server, char *Line)\r
{\r
- int pos;\r
+ int pos = 0;\r
char *ident, *cmd;\r
if( *Line == ':' ) {\r
// Message\r
// process it line by line\r
// ioctl#8 on a TCP client gets the number of bytes in the recieve buffer\r
// - Used to avoid blocking\r
- while( ioctl(Server->FD, 8, NULL) )\r
+ #if NON_BLOCK_READ\r
+ while( (len = ioctl(Server->FD, 8, NULL)) > 0 )\r
{\r
+ #endif\r
// Read data\r
- len = read(Server->FD, BUFSIZ - Server->ReadPos, Server->InBuf + Server->ReadPos);\r
+ len = read(Server->FD, BUFSIZ - Server->ReadPos, &Server->InBuf[Server->ReadPos]);\r
Server->InBuf[Server->ReadPos + len] = '\0';\r
\r
// Break into lines\r
\r
// Handle incomplete lines\r
if( ptr - Server->InBuf < len + Server->ReadPos ) {\r
- Server->ReadPos = ptr - Server->InBuf;\r
+ // Update the read position\r
+ // InBuf ReadPos ptr ReadPos+len\r
+ // | old | new used | new unused |\r
+ Server->ReadPos = len + Server->ReadPos - (ptr - Server->InBuf);\r
+ // Copy stuff back (moving "new unused" to the start of the buffer)\r
memcpy(Server->InBuf, ptr, Server->ReadPos);\r
}\r
else {\r
Server->ReadPos = 0;\r
}\r
+ #if NON_BLOCK_READ\r
}\r
+ #endif\r
}\r
\r
/**\r