コード例 #1
0
ファイル: NetClient.cs プロジェクト: lanicon/HavokNet
        public void SendLayer3Packet(OSI.Layer3Packet packet, PacketSentHandler callback)
        {
            IpV4Layer ipV4Layer = new IpV4Layer
            {
                Source = new IpV4Address(packet.SourceIP.AsString),
                Ttl    = packet.Ttl,
                // The rest of the important parameters will be set for each packet
            };

            Common.IPv4Address ip = null;

            try
            {
                System.Net.IPAddress.Parse(packet.Destination);
                ip = new Common.IPv4Address(packet.Destination);
            }
            catch
            {
                ip = Dns.ResolveHost(packet.Destination).IPs[0];
            }

            ipV4Layer.CurrentDestination = new IpV4Address(ip.AsString);

            OSI.Layer2Packet l2 = new OSI.Layer2Packet();
            l2.SourceMac      = Configuration.MacAddress;
            l2.DestinationMac = Arp.ResolveIP(ip);

            foreach (ILayer layer in packet.NextLayers)
            {
                l2.NextLayers.Add(layer);
            }
            l2.NextLayers.Insert(0, ipV4Layer);

            SendLayer2Packet(l2, callback);
        }