/* This file is part of PacketDotNet PacketDotNet is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. PacketDotNet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with PacketDotNet. If not, see . */ /* * Copyright 2010 Evan Plaice */ using System; using MiscUtil.Conversion; using PacketDotNet.Utils; namespace PacketDotNet.Tcp { /// /// User Timeout Option /// The TCP user timeout controls how long transmitted data may remain /// unacknowledged before a connection is forcefully closed /// /// /// References: /// http://datatracker.ietf.org/doc/rfc5482/ /// public class UserTimeout: Option { #region Constructors /// /// Creates a User Timeout Option /// /// /// A /// /// /// A /// /// /// A /// public UserTimeout(byte[] bytes, int offset, int length) : base(bytes, offset, length) { } #endregion #region Properties /// /// The Granularity /// public bool Granularity { get { int granularity = ((int)Values >> 15); return (granularity != 0); } } /// /// The User Timeout /// public ushort Timeout { get { return (ushort)((int)Values & TimeoutMask); } } // a convenient property to grab the value fields for further processing private ushort Values { get { return EndianBitConverter.Big.ToUInt16(Bytes, ValuesFieldOffset); } } #endregion #region Methods /// /// Returns the Option info as a string /// /// /// A /// public override string ToString() { return "[" + Kind.ToString() + ": Granularity=" + (Granularity ? "minutes" : "seconds") + " Timeout=" + Timeout + "]"; } #endregion #region Members // the offset (in bytes) of the Value Fields const int ValuesFieldOffset = 2; // the mask used to strip the Granularity field from the // Values filed to expose the UserTimeout field const int TimeoutMask = 0x7FFF; #endregion } }