⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionfield.cs

📁 pureIRCd是一个用c语音写的irc(RFC459)服务,可以给您带来很多的方便
💻 CS
字号:
using System;
using System.Net;
namespace SDP
{
    /// <summary>
    /// A Connection represents the c= field and identifies a network address on which media
    /// can be recieved.
    /// 
    /// The Connection the SessionDescription is mandatory if it is not present in all 
    /// MediaDescriptions.
    /// </summary>
    public class ConnectionField : Field
    {
        /// <summary>
        /// Defines the constant for the Internet network type.
        /// </summary>
        public const string InterNetwork = "IN";

        /// <summary>
        /// Defines the constant for the IP version 4 network address type.
        /// </summary>
        public const string IPv4 = "IP4";

        /// <summary>
        /// Defines the constant for the IP version 6 network address type.
        /// </summary>
        public const string IPv6 = "IP6";

        private AddressRange address;
        /// <summary>
        /// Gets or sets the address.
        /// </summary>
        public AddressRange Address
        {
            get { return this.address; }
        }

        private string addressType;
        /// <summary>
        /// Gets the address type. Is either "IP4" or "IP6"
        /// </summary>
        public string AddressType
        {
            get { return this.addressType; }
        }

        private string networkType;
        /// <summary>
        /// Gets the network type. For this specification the value should
        /// always be "IN" for Internet.
        /// </summary>
        public string NetworkType
        {
            get { return this.networkType; }
        }

        /// <summary>
        /// Creates a new ConnectionField.
        /// </summary>
        /// <param name="value">The value portion of the field.</param>
        public ConnectionField(string value)
            : base("c=" + value)
        {
            string[] parts = base.value.Split(' ');
            if (parts.Length != 3) throw new ArgumentException("Invalid connection field.");

            this.networkType = parts[0];
            this.addressType = parts[1];

            string[] aparts = parts[2].Split('/');
            if (aparts.Length == 1)
                this.address = new AddressRange(IPAddress.Parse(aparts[0]));
            else if (aparts.Length == 2)
                this.address = new AddressRange(IPAddress.Parse(aparts[0]), byte.Parse(aparts[1]));
            else if (aparts.Length == 3)
                this.address = new AddressRange(IPAddress.Parse(aparts[0]), uint.Parse(aparts[2]), byte.Parse(aparts[1]));
            else throw new ArgumentException("Invalid Address");
        }

        /// <summary>
        /// Creates a new ConnectionField.
        /// </summary>
        /// <param name="address">The address of the connection.</param>
        public ConnectionField(AddressRange address)
            : this("c=IN IP4 " + address.ToString()) { }

        /// <summary>
        /// Creates a new ConnectionField.
        /// </summary>
        /// <param name="address">The address of the connection.</param>
        /// <param name="networkType">The network type.</param>
        /// <param name="addressType">The address type.</param>
        public ConnectionField(AddressRange address, string networkType, string addressType)
            : this("c=" + String.Format("{0} {1} {2}", networkType, addressType, address.ToString())) { }

        /// <summary>
        /// Gets the value portion of the field.
        /// </summary>
        public override string Value
        {
            get { return String.Format("{0} {1} {2}", this.networkType, this.addressType, this.address.ToString()); }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -