Beispiel #1
0
        /// <summary>
        /// Writes the optional and variable length parameters to a Type-Length-Value (TLV)
        /// parameter list.
        /// </summary>
        /// <returns>A TLV parameter list holding the optional and variable length parameters.</returns>
        private List <SctpTlvChunkParameter> GetVariableParameters()
        {
            List <SctpTlvChunkParameter> varParams = new List <SctpTlvChunkParameter>();

            // Add the optional and variable length parameters as Type-Length-Value (TLV) formatted.
            foreach (var address in Addresses)
            {
                ushort addrParamType = (ushort)(address.AddressFamily == AddressFamily.InterNetwork ?
                                                SctpInitChunkParameterType.IPv4Address : SctpInitChunkParameterType.IPv6Address);
                var addrParam = new SctpTlvChunkParameter(addrParamType, address.GetAddressBytes());
                varParams.Add(addrParam);
            }

            if (CookiePreservative > 0)
            {
                varParams.Add(
                    new SctpTlvChunkParameter((ushort)SctpInitChunkParameterType.CookiePreservative,
                                              NetConvert.GetBytes(CookiePreservative)
                                              ));
            }

            if (!string.IsNullOrEmpty(HostnameAddress))
            {
                varParams.Add(
                    new SctpTlvChunkParameter((ushort)SctpInitChunkParameterType.HostNameAddress,
                                              Encoding.UTF8.GetBytes(HostnameAddress)
                                              ));
            }

            if (SupportedAddressTypes.Count > 0)
            {
                byte[] paramVal     = new byte[SupportedAddressTypes.Count * 2];
                int    paramValPosn = 0;
                foreach (var supAddr in SupportedAddressTypes)
                {
                    NetConvert.ToBuffer((ushort)supAddr, paramVal, paramValPosn);
                    paramValPosn += 2;
                }
                varParams.Add(
                    new SctpTlvChunkParameter((ushort)SctpInitChunkParameterType.SupportedAddressTypes, paramVal));
            }

            if (StateCookie != null)
            {
                varParams.Add(
                    new SctpTlvChunkParameter((ushort)SctpInitChunkParameterType.StateCookie, StateCookie));
            }

            foreach (var unrecognised in UnrecognizedPeerParameters)
            {
                varParams.Add(
                    new SctpTlvChunkParameter((ushort)SctpInitChunkParameterType.UnrecognizedParameter, unrecognised.GetBytes()));
            }

            return(varParams);
        }
Beispiel #2
0
 public STUNAttribute(STUNAttributeTypesEnum attributeType, ulong value)
 {
     AttributeType = attributeType;
     Value         = NetConvert.GetBytes(value);
 }