Exemplo n.º 1
0
        public Pack ToUdp(Pack pack, IPHeader ipHeader)
        {
            UDPHeader udpHeader = new UDPHeader(ipHeader.Data, ipHeader.Length);

            pack.FromPort = udpHeader.FromPort;
            pack.ToPort   = udpHeader.ToPort;
            pack.Data     = udpHeader.Data;
            pack.Length   = udpHeader.Length;
            return(pack);
        }
Exemplo n.º 2
0
        public Pack ToTcp(Pack pack, IPHeader ipHeader)
        {
            TCPHeader tcpHeader = new TCPHeader(ipHeader.Data, ipHeader.Length);

            pack.FromPort = tcpHeader.FromPort;
            pack.ToPort   = tcpHeader.ToPort;
            pack.Data     = tcpHeader.Data;
            pack.Length   = tcpHeader.Length;
            pack.TCP      = tcpHeader;
            return(pack);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 将接收到的数据转换成SWSoft.Net.Pack
        /// </summary>
        /// <param name="buffReceived">接收到的数据</param>
        private Pack Convert(int buffReceived)
        {
            IPHeader ipHeader = new IPHeader(Data, buffReceived);
            Pack     pack     = new Pack {
                Header = ipHeader, FromIP = ipHeader.From, ToIP = ipHeader.To, ProtocolType = ipHeader.ProtocolType
            };

            switch (ipHeader.ProtocolType)
            {
            case ProtocolType.Tcp: return(ToTcp(pack, ipHeader));

            case ProtocolType.Udp: return(ToUdp(pack, ipHeader));

            default: return(pack);
            }
        }