/**
* \brief Creates and sends an IPv4 Packet
+ * \param Iface Interface
+ * \param Address Destination IP
+ * \param Protocol Protocol ID
+ * \param ID Some random ID number
+ * \param Length Data Length
+ * \param Data Packet Data
*/
int IPv4_SendPacket(tInterface *Iface, tIPv4 Address, int Protocol, int ID, int Length, void *Data)
{
hdr->HeaderChecksum = 0; // Will be set later
hdr->Source = Iface->IP4.Address;
hdr->Destination = Address;
- hdr->HeaderChecksum = htons( IPv4_Checksum(hdr, sizeof(tIPv4Header)) );
+ hdr->HeaderChecksum = IPv4_Checksum(hdr, sizeof(tIPv4Header));
Log("[IPv4 ] Sending packet to %i.%i.%i.%i",
Address.B[0], Address.B[1], Address.B[2], Address.B[3]);
sum ++; // Simulate 1's complement
sum += arr[i];
}
- return htons( ~sum );
+ return ~sum ;
}
/**
hdr->SourcePort = Conn->LocalPort;
hdr->DestPort = Conn->RemotePort;
- hdr->SequenceNumber = rand();
+ Conn->NextSequenceSend = rand();
+ hdr->SequenceNumber = Conn->NextSequenceSend;
hdr->DataOffset = (sizeof(tTCPHeader)+3)/4;
hdr->Flags = TCP_FLAG_SYN;
+ hdr->WindowSize = 0; // TODO
+ hdr->Checksum = 0; // TODO
+ hdr->UrgentPointer = 0;
// SEND PACKET
- // Send a TCP SYN to the target to open the connection
+ TCP_SendPacket( Conn, sizeof(tTCPHeader), &hdr );
return ;
}
+/**
+ * \brief Sends a packet from the specified connection, calculating the checksums
+ * \param Conn Connection
+ * \param Length Length of data
+ * \param Data Packet data
+ */
+void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data )
+{
+ size_t buflen;
+ Uint32 *buf;
+ switch( Conn->Interface.Type )
+ {
+ case 4:
+ buflen = 4 + 4 + 4 + ((Length+1)&1);
+ buf = malloc( buflen );
+ buf[0] = Conn->Interface.IP4.Address.L;
+ buf[1] = Conn->RemoteIP.v4.L;
+ buf[2] = (htons(Length)<<16) | (6<<8) | 0;
+ Data->Checksum = 0;
+ memcpy( &buf[3], Data, buflen );
+ Data->Checksum = IPv4_Checksum( buf, buflen );
+ free(buf);
+ IPv4_SendPacket(Conn->Interface, Conn->RemoteIP.v4, IP4PROT_TCP, 0, sizeof(tTCPHeader), &hdr);
+ break;
+ }
+}
+
/**
* \fn void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer)
* \brief Handles a packet from the IP Layer
/**
* \file udi.h
*/
-#ifndef _UDI_ARCH_H_
-#define _UDI_ARCH_H_
+#ifndef _UDI_H_
+#define _UDI_H_
// Use the core acess file to use the specific size types (plus va_arg)
#include <acess.h>
-typedef Sint8 udi_sbit8_t; /* signed 8-bit: -2^7..2^7-1 */
-typedef Sint16 udi_sbit16_t; /* signed 16-bit: -2^15..2^15-1 */
-typedef Sint32 udi_sbit32_t; /* signed 32-bit: -2^31..2^31-1 */
-typedef Uint8 udi_ubit8_t; /* unsigned 8-bit: 0..28-1 */
-typedef Uint16 udi_ubit16_t; /* unsigned 16-bit: 0..216-1 */
-typedef Uint32 udi_ubit32_t; /* unsigned 32-bit: 0..232-1 */
-
-typedef udi_ubit8_t udi_boolean_t; /* 0=False; 1..28-1=True */
-#define FALSE 0
-#define TRUE 1
-
-typedef size_t udi_size_t; /* buffer size */
-typedef size_t udi_index_t; /* zero-based index type */
-
-typedef void *_udi_handle_t;
-#define _NULL_HANDLE NULL
-
-/* Channel Handle */
-typedef _udi_handle_t *udi_channel_t;
-#define UDI_NULL_CHANNEL _NULL_HANDLE
-
-/**
- * \brief Buffer Path
- */
-typedef _udi_handle_t udi_buf_path_t;
-#define UDI_NULL_BUF_PATH _NULL_HANDLE
-
-typedef _udi_handle_t udi_origin_t;
-#define UDI_NULL_ORIGIN _NULL_HANDLE
-
-typedef Sint64 udi_timestamp_t;
-
-#define UDI_HANDLE_IS_NULL(handle, handle_type) (handle == NULL)
-#define UDI_HANDLE_ID(handle, handle_type) ((Uint32)handle)
-
-/**
- * \name va_arg wrapper
- * \{
- */
-#define UDI_VA_ARG(pvar, type, va_code) va_arg(pvar,type)
-#define UDI_VA_UBIT8_T
-#define UDI_VA_SBIT8_T
-#define UDI_VA_UBIT16_T
-#define UDI_VA_SBIT16_T
-#define UDI_VA_UBIT32_T
-#define UDI_VA_SBIT32_T
-#define UDI_VA_BOOLEAN_T
-#define UDI_VA_INDEX_T
-#define UDI_VA_SIZE_T
-#define UDI_VA_STATUS_T
-#define UDI_VA_CHANNEL_T
-#define UDI_VA_ORIGIN_T
-#define UDI_VA_POINTER
-/**
- * \}
- */
-
-/**
- * \brief Status Type
- */
-typedef udi_ubit32_t udi_status_t;
+#include "udi/arch/x86.h"
/**
* \name Values and Flags for udi_status_t
--- /dev/null
+
+#ifndef _UDI_ARCH_x86_H_
+#define _UDI_ARCH_x86_H_
+
+typedef Sint8 udi_sbit8_t; /* signed 8-bit: -2^7..2^7-1 */
+typedef Sint16 udi_sbit16_t; /* signed 16-bit: -2^15..2^15-1 */
+typedef Sint32 udi_sbit32_t; /* signed 32-bit: -2^31..2^31-1 */
+typedef Uint8 udi_ubit8_t; /* unsigned 8-bit: 0..28-1 */
+typedef Uint16 udi_ubit16_t; /* unsigned 16-bit: 0..216-1 */
+typedef Uint32 udi_ubit32_t; /* unsigned 32-bit: 0..232-1 */
+
+typedef udi_ubit8_t udi_boolean_t; /* 0=False; 1..28-1=True */
+#define FALSE 0
+#define TRUE 1
+
+typedef size_t udi_size_t; /* buffer size */
+typedef size_t udi_index_t; /* zero-based index type */
+
+typedef void *_udi_handle_t;
+#define _NULL_HANDLE NULL
+
+/* Channel Handle */
+typedef _udi_handle_t *udi_channel_t;
+#define UDI_NULL_CHANNEL _NULL_HANDLE
+
+/**
+ * \brief Buffer Path
+ */
+typedef _udi_handle_t udi_buf_path_t;
+#define UDI_NULL_BUF_PATH _NULL_HANDLE
+
+typedef _udi_handle_t udi_origin_t;
+#define UDI_NULL_ORIGIN _NULL_HANDLE
+
+typedef Sint64 udi_timestamp_t;
+
+#define UDI_HANDLE_IS_NULL(handle, handle_type) (handle == NULL)
+#define UDI_HANDLE_ID(handle, handle_type) ((Uint32)handle)
+
+/**
+ * \name va_arg wrapper
+ * \{
+ */
+#define UDI_VA_ARG(pvar, type, va_code) va_arg(pvar,type)
+#define UDI_VA_UBIT8_T
+#define UDI_VA_SBIT8_T
+#define UDI_VA_UBIT16_T
+#define UDI_VA_SBIT16_T
+#define UDI_VA_UBIT32_T
+#define UDI_VA_SBIT32_T
+#define UDI_VA_BOOLEAN_T
+#define UDI_VA_INDEX_T
+#define UDI_VA_SIZE_T
+#define UDI_VA_STATUS_T
+#define UDI_VA_CHANNEL_T
+#define UDI_VA_ORIGIN_T
+#define UDI_VA_POINTER
+/**
+ * \}
+ */
+
+/**
+ * \brief Status Type
+ */
+typedef udi_ubit32_t udi_status_t;
+
+#endif
{
switch(Msg->ID)
{
- case MSG_REQ_PING:
- Msg->ID = MSG_RSP_PONG;
+ case MSG_SREQ_PING:
+ Msg->ID = MSG_SRSP_PONG;
Respond(ID, sizeof(Msg->ID), Msg);
break;
default:
- fprintf(stderr, "WARNING: Unknown message %i from %i (%p)\n",
- Msg->ID, ID, Respond);
+ fprintf(stderr, "WARNING: Unknown message %i from %i (%p)\n", Msg->ID, ID, Respond);
+ _SysDebug("WARNING: Unknown message %i from %i (%p)\n", Msg->ID, ID, Respond);
break;
}
}