コード例 #1
0
ファイル: IPV4.cs プロジェクト: valentinbreiz/Sharpen
        /// <summary>
        /// Send IPV4 packet
        /// </summary>
        /// <param name="packet">Packet structure</param>
        /// <param name="destMac">Destination mac</param>
        /// <param name="destIP">Destination IP</param>
        /// <param name="protocol">Protocol</param>
        public static unsafe void Send(NetPacketDesc *packet, byte[] destIP, byte protocol)
        {
            byte[] sourceIP = Util.PtrToArray(Network.Settings->IP);
            addHeader(packet, sourceIP, destIP, protocol);

            Ethernet.Send(packet, destIP, EthernetTypes.IPV4);
        }
コード例 #2
0
ファイル: ARP.cs プロジェクト: valentinbreiz/Sharpen
        public static unsafe void ArpSend(ushort op, byte[] hwAddr, byte[] ip)
        {
            byte *mac = (byte *)Heap.Alloc(6);

            Network.GetMac(mac);

            NetPacketDesc *packet = NetPacket.Alloc();

            ARPHeader *hdr = (ARPHeader *)(packet->buffer + packet->end);

            hdr->HardwareType = Byte.ReverseBytes(0x01);
            hdr->ProtocolType = Byte.ReverseBytes(0x800);

            hdr->HardwareAdrLength = 6;
            hdr->ProtocolAdrLength = 4;

            hdr->Opcode = Byte.ReverseBytes(op);

            Memory.Memcpy(hdr->SrcIP, Network.Settings->IP, 4);
            Memory.Memcpy(hdr->SrcHw, mac, 6);
            Memory.Memcpy(hdr->DstIP, Util.ObjectToVoidPtr(ip), 4);

            if (op == OP_REPLY)
            {
                Memory.Memcpy(hdr->DstHw, Util.ObjectToVoidPtr(hwAddr), 6);
            }
            else
            {
                Memory.Memset(hdr->DstHw, 0, 6);
            }

            packet->end += (short)sizeof(ARPHeader);
            Ethernet.SendMAC(packet, hwAddr, EthernetTypes.ARP);

            NetPacket.Free(packet);
            Heap.Free(mac);
        }