/// <summary>
        /// This routine builds the appropriate ICMP echo packet depending on the
        /// protocol family requested.
        /// </summary>
        public void BuildPingPacket()
        {
            // Initialize the socket if it hasn't already been done

            if (pingSocket == null)
            {
                InitializeSocket();
            }

            // Create the ICMP header and initialize the members

            icmpHeader = new IcmpHeader()
            {
                Id = pingId, Sequence = pingSequence, Type = IcmpHeader.EchoRequestType, Code = IcmpHeader.EchoRequestCode
            };

            // Build the data payload of the ICMP echo request

            pingPayload = new byte[pingPayloadLength];

            for (int i = 0; i < pingPayload.Length; i++)
            {
                pingPayload[i] = (byte)'e';
            }
        }
        private DateTime pingSentTime;        // Timestamp of when ping request was sent

        /// <summary>
        /// Base constructor that initializes the member variables to default values. It also
        /// creates the events used and initializes the async callback function.
        /// </summary>
        public RawSocketPing()
        {
            pingSocket         = null;
            pingTtl            = 8;
            pingPayloadLength  = 8;
            pingSequence       = 0;
            pingReceiveTimeout = 2000;
            destEndPoint       = new IPEndPoint(IPAddress.Loopback, 0);
            icmpHeader         = null;
        }
        public byte[] BuildPacket(ushort pingID, byte[] payLoad)
        {
            IcmpHeader protocolHeader = new IcmpHeader()
            {
                Id = pingID, Sequence = 0, Type = IcmpHeader.EchoRequestType, Code = IcmpHeader.EchoRequestCode
            };;

            payLoad = protocolHeader.GetProtocolPacketBytes(payLoad);

            return(payLoad);
        }