📄 requirmentsocks4message.cs
字号:
namespace Imps.Client.CommLayer.SocksSipConnection
{
using Imps.Client.CommLayer;
using System;
using System.IO;
using System.Net;
using System.Text;
internal abstract class RequirmentSocks4Message : Socks4Message
{
private RequirementType _cmd;
private string _dstAddr = "0.0.0.0";
private int _dstPort;
private string _userId = string.Empty;
public RequirmentSocks4Message(RequirementType cmd, string dstAddr, int dstPort)
{
this.Cmd = cmd;
this.DstAddr = dstAddr;
this.DstPort = dstPort;
}
public override byte[] ToBinary()
{
byte[] buffer3;
try
{
using (MemoryStream stream = new MemoryStream())
{
stream.WriteByte((byte) base.Ver);
stream.WriteByte((byte) this.Cmd);
stream.WriteByte((byte) (this.DstPort >> 8));
stream.WriteByte((byte) this.DstPort);
byte[] addressBytes = Dns.GetHostEntry(this.DstAddr).AddressList[0].GetAddressBytes();
if (addressBytes.Length != 4)
{
throw new NotSupportedException("Socks4仅支持IP4方式登录");
}
stream.Write(addressBytes, 0, addressBytes.Length);
byte[] buffer = Encoding.UTF8.GetBytes(this.UserId);
stream.Write(buffer, 0, buffer.Length);
stream.WriteByte(0);
buffer3 = stream.ToArray();
}
}
catch (Exception exception)
{
throw new SipConnectionException("产生序列化错误", exception);
}
return buffer3;
}
public override string ToString()
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat("VER : {0}\n", base.Ver);
builder.AppendFormat("CMD : {0}\n", this.Cmd);
builder.AppendFormat("DST.ADDR : {0}\n", this.DstAddr);
builder.AppendFormat("DST.PORT : {0}", this.DstPort);
return builder.ToString();
}
public RequirementType Cmd
{
get
{
return this._cmd;
}
set
{
this._cmd = value;
}
}
public string DstAddr
{
get
{
return this._dstAddr;
}
set
{
if (value == null)
{
throw new ArgumentNullException("DstAddr");
}
this._dstAddr = value;
}
}
public int DstPort
{
get
{
return this._dstPort;
}
set
{
this._dstPort = value;
}
}
public string UserId
{
get
{
return this._userId;
}
set
{
if (value == null)
{
throw new ArgumentNullException("UserId");
}
this._userId = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -