/// <summary> /// Process request /// </summary> /// <param name="ip">IP</param> /// <param name="id">ID</param> /// <param name="seq">Sequence number</param> /// <param name="data">Packet data</param> /// <param name="length">Packet length</param> private static unsafe void EchoReply(byte[] ip, ushort id, ushort seq, byte *data, int length) { NetPacketDesc *packet = NetPacket.Alloc(); ICMPHeader *hdr = (ICMPHeader *)(packet->buffer + packet->start); hdr->Type = TYPE_ECHO_REPLY; hdr->ID = id; hdr->SeqNum = seq; hdr->Code = 0; hdr->CheckSum = 0; packet->end += (short)sizeof(ICMPHeader); Memory.Memcpy(packet->buffer + packet->end, data, length); packet->end += (short)length; hdr->CheckSum = NetworkTools.Checksum((byte *)(packet->buffer + packet->start), sizeof(ICMPHeader) + length); IPV4.Send(packet, ip, 0x01); NetPacket.Free(packet); }
/// <summary> /// Send UDP packet /// </summary> /// <param name="packet">Packet structure</param> /// <param name="destMac">Destination MAC</param> /// <param name="destIP">Destination IP</param> /// <param name="srcPort">Source port</param> /// <param name="DestPort">Destination port</param> public static unsafe void Send(NetPacketDesc *packet, byte[] destIP, ushort srcPort, ushort DestPort) { /** * No support for packets over 1500 bytes */ if (packet->end - packet->start >= 1500) { return; } addHeader(packet, destIP, srcPort, DestPort); IPV4.Send(packet, destIP, PROTOCOL_UDP); }
/// <summary> /// Send UDP data /// </summary> /// <param name="destMac">Destination MAC</param> /// <param name="destIP">Destination IP</param> /// <param name="srcPort">Source port</param> /// <param name="DestPort">Destination port</param> /// <param name="data">Data pointer</param> /// <param name="size">Data size</param> public static unsafe void Send(byte[] destMac, byte[] destIP, ushort srcPort, ushort DestPort, byte[] data, int size) { /** * No support for packets over 1500 bytes */ if (size >= 1500) { return; } NetPacketDesc *packet = NetPacket.Alloc(); Memory.Memcpy(packet->buffer + packet->start, Util.ObjectToVoidPtr(data), size); addHeader(packet, destIP, srcPort, DestPort); IPV4.Send(packet, destIP, PROTOCOL_UDP); NetPacket.Free(packet); }
/// <summary> /// Send packet to TCP /// </summary> /// <param name="destIP"></param> /// <param name="seqNum"></param> /// <param name="acknumb"></param> /// <param name="srcPort"></param> /// <param name="destPort"></param> /// <param name="flags"></param> /// <param name="data"></param> /// <param name="count"></param> /// <returns></returns> private static unsafe bool SendPacket(byte[] destIP, uint seqNum, uint acknumb, ushort srcPort, ushort destPort, byte flags, byte *data, int count) { NetPacketDesc *packet = NetPacket.Alloc(); if (count > 0) { Memory.Memcpy(packet->buffer + packet->start, data, count); packet->end += (short)count; } TCPHeader *outHeader = addHeader(packet, srcPort, destPort, flags, seqNum, acknumb, 8192); FinishHeader(packet, outHeader, destIP, sizeof(TCPHeader), count); IPV4.Send(packet, destIP, PROTOCOL_TCP); NetPacket.Free(packet); return(true); }