Esempio n. 1
0
        //这个是把ip部分转为字节数组用的
        public Int32 pshto(psdHeader psh, byte[] buffer, int size)
        {
            Int32 rtn;
            int   index = 0;

            byte[] b_psh_saddr = BitConverter.GetBytes(psh.saddr);
            byte[] b_psh_daddr = BitConverter.GetBytes(psh.daddr);
            byte[] b_psh_mbz   = new byte[1];
            b_psh_mbz[0] = psh.mbz;
            byte[] b_psh_ptcl = new byte[1];
            b_psh_ptcl[0] = psh.ptcl;
            byte[] b_psh_tcpl = BitConverter.GetBytes(psh.tcpl);
            Array.Copy(b_psh_saddr, 0, buffer, index, b_psh_saddr.Length);
            index += b_psh_saddr.Length;
            Array.Copy(b_psh_daddr, 0, buffer, index, b_psh_daddr.Length);
            index += b_psh_daddr.Length;
            Array.Copy(b_psh_mbz, 0, buffer, index, b_psh_mbz.Length);
            index += b_psh_mbz.Length;
            Array.Copy(b_psh_ptcl, 0, buffer, index, b_psh_ptcl.Length);
            index += b_psh_ptcl.Length;
            Array.Copy(b_psh_tcpl, 0, buffer, index, b_psh_tcpl.Length);
            index += b_psh_tcpl.Length;
            if (index != size)
            {
                rtn = -1;
                return(rtn);
            }
            else
            {
                rtn = index;
                return(rtn);
            }
        }
Esempio n. 2
0
        //这个使用来计算校验码的我照抄c#实现ping那文章的方法,反正ip协议计算校验码方法都一样
        public syn(uint _ip, ushort _port, EndPoint _ep, Random _rand)
        {
            ip   = _ip;
            port = _port;
            ep   = _ep;
            rand = _rand;
            ipHeader iph = new ipHeader();

            psh  = new psdHeader();
            tch  = new tcpHeader();
            sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
            sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
            //这2个挺重要,必须这样才可以自己提供ip头
        }
Esempio n. 3
0
 //这个使用来计算校验码的我照抄c#实现ping那文章的方法,反正ip协议计算校验码方法都一样
 public syn(uint _ip, ushort _port, EndPoint _ep, Random _rand)
 {
     ip = _ip;
     port = _port;
     ep = _ep;
     rand = _rand;
     ipHeader iph = new ipHeader();
     psh = new psdHeader();
     tch = new tcpHeader();
     sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
     sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
     //这2个挺重要,必须这样才可以自己提供ip头
 }
Esempio n. 4
0
 //这个是把ip部分转为字节数组用的
 public Int32 pshto(psdHeader psh, byte[] buffer, int size)
 {
     Int32 rtn;
     int index = 0;
     byte[] b_psh_saddr = BitConverter.GetBytes(psh.saddr);
     byte[] b_psh_daddr = BitConverter.GetBytes(psh.daddr);
     byte[] b_psh_mbz = new byte[1];
     b_psh_mbz[0] = psh.mbz;
     byte[] b_psh_ptcl = new byte[1];
     b_psh_ptcl[0] = psh.ptcl;
     byte[] b_psh_tcpl = BitConverter.GetBytes(psh.tcpl);
     Array.Copy(b_psh_saddr, 0, buffer, index, b_psh_saddr.Length);
     index += b_psh_saddr.Length;
     Array.Copy(b_psh_daddr, 0, buffer, index, b_psh_daddr.Length);
     index += b_psh_daddr.Length;
     Array.Copy(b_psh_mbz, 0, buffer, index, b_psh_mbz.Length);
     index += b_psh_mbz.Length;
     Array.Copy(b_psh_ptcl, 0, buffer, index, b_psh_ptcl.Length);
     index += b_psh_ptcl.Length;
     Array.Copy(b_psh_tcpl, 0, buffer, index, b_psh_tcpl.Length);
     index += b_psh_tcpl.Length;
     if (index != size)
     {
         rtn = -1;
         return rtn;
     }
     else
     {
         rtn = index;
         return rtn;
     }
 }