Example #1
0
 /// <summary>
 /// Constructs a client packet.
 /// </summary>
 internal NtpPacket(NtpMode mode, byte versionNumber, NtpTimestamp transmitTimestamp)
     : this()
 {
     _data[0] = SetBits(_data[0], OFFSET_VN, LENGTH_MODE, versionNumber);
     _data[0] = SetBits(_data[0], INDEX_BITFIELD, LENGTH_MODE, (byte)mode);
     CopyTimestampToData(transmitTimestamp, INDEX_TRANSMIT_TIMESTAMP);
 }
Example #2
0
        /// <summary>
        /// Subtracts the specified timestamp from this instance, calculating the time difference between the two timestamps.
        /// </summary>
        /// <param name="value">A timestamp.</param>
        /// <returns>A time difference (positive or negative).</returns>
        public NtpTimestampDifference Subtract(NtpTimestamp value)
        {
            long d;

            if (_timestamp >= value._timestamp)
            {
                d = (long)(_timestamp - value._timestamp);
            }
            else
            {
                d = -(long)(value._timestamp - _timestamp);
            }
            return(new NtpTimestampDifference(d));
        }
Example #3
0
 void CopyTimestampToData(NtpTimestamp ts, int index)
 {
     UpdateData(ts.ToArray(), index, 8);
 }
Example #4
0
        /// <summary>
        /// Minimal size of an NTP packet (they can be larger,
        /// but the optional fields are at the end and this
        /// class ignores them).
        /// </summary>



        /// <summary>
        /// Constructs an empty (i.e. with all bits set to 0) packet.
        /// </summary>
        internal NtpPacket()
        {
            _data = new byte[MinPacketSize];
            _destinationTimestamp = NtpTimestamp.Now;
        }
Example #5
0
 internal void SetDestinationTimestamp(NtpTimestamp timestamp)
 {
     _destinationTimestamp = timestamp;
 }