Exemple #1
0
        /// <summary>
        /// Find route "mac" address
        /// </summary>
        /// <param name="ip"></param>
        public unsafe static bool FindRoute(byte[] ip, byte *DestMac)
        {
            if (InLocalNetwork(ip))
            {
                ARP.Lookup(ip, DestMac);

                if (DestMac[0] == 0x00 && DestMac[1] == 0x00 && DestMac[2] == 0x00 && DestMac[3] == 0x00 && DestMac[4] == 0x00 && DestMac[5] == 0x00)
                {
                    byte[] mac = new byte[6];
                    for (int i = 0; i < 6; i++)
                    {
                        mac[i] = 0xFF;
                    }

                    ARP.ArpSend(ARP.OP_REQUEST, mac, ip);

                    return(false);
                }
            }
            else
            {
                for (int i = 0; i < 6; i++)
                {
                    DestMac[i] = m_gateway_mac[i];
                }
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// FS finddir
        /// </summary>
        /// <param name="node">The node</param>
        /// <param name="name">The name to look for</param>
        /// <returns>The node</returns>
        private static unsafe Node findDirImpl(Node node, string name)
        {
            byte[] ip = NetworkTools.StringToIp(name);
            if (ip == null)
            {
                return(null);
            }

            byte *dstMac = (byte *)Heap.Alloc(6);

            Memory.Memset(dstMac, 0, 6);

            ARP.Lookup(ip, dstMac);

            if (dstMac[0] == 0x00 && dstMac[1] == 0x00 && dstMac[2] == 0x00 && dstMac[3] == 0x00 && dstMac[4] == 0x00 && dstMac[5] == 0x00)
            {
                byte[] mac = new byte[6];
                for (int i = 0; i < 6; i++)
                {
                    mac[i] = 0xFF;
                }

                ARP.ArpSend(ARP.OP_REQUEST, mac, ip);
                Heap.Free(mac);

                return(null);
            }
            Heap.Free(dstMac);

            return(new Node());
        }
Exemple #3
0
        /// <summary>
        /// Connection to IP
        /// </summary>
        /// <param name="ip">IP</param>
        /// <param name="port">Port</param>
        /// <returns></returns>
        public static unsafe TCPConnection Connect(byte[] ip, ushort port)
        {
            ushort inPort   = RequestPort();
            int    startSeq = Random.Rand();

            if (!ARP.IpExists(ip))
            {
                byte[] mac = new byte[6];
                for (int i = 0; i < 6; i++)
                {
                    mac[i] = 0xFF;
                }

                ARP.ArpSend(ARP.OP_REQUEST, mac, ip);
                Heap.Free(mac);
            }

            while (!ARP.IpExists(ip))
            {
                Tasking.Yield();
            }

            TCPConnection con = new TCPConnection();

            con.DestPort           = port;
            con.InPort             = inPort;
            con.State              = TCPConnectionState.CLOSED;
            con.XID                = Random.Rand();
            con.SequenceNumber     = (uint)startSeq;
            con.NextSequenceNumber = Byte.ReverseBytes(Byte.ReverseBytes(con.SequenceNumber) + 1);
            con.Type               = TCPConnectionType.CONNECTION;
            con.ReceiveQueue       = new Queue();

            for (int i = 0; i < 4; i++)
            {
                con.IP[i] = ip[i];
            }

            m_connections[inPort] = con;

            handleConnection(con, null, null, 0);

            return(con);
        }