예제 #1
0
 public byte[] ToArray()
 {
     using (var buffer = new MemoryStream())
     {
         using (var bw = new BinaryWriter(buffer))
         {
             bw.Write((byte)Action);     // action
             bw.Write((byte)PrivLvl);    // priv_lvl
             bw.Write((byte)AuthenType); // authen_type
             bw.Write((byte)Service);    // authen_service
             bw.Write(UserLen);          // user_len
             bw.Write(PortLen);          // port_len
             bw.Write(RemAddrLen);       // remote address len
             bw.Write(DataLen);          // data_len
             if (UserLen > 0)
             {
                 bw.Write(Encoding.ASCII.GetBytes(User));
             }
             if (PortLen > 0)
             {
                 bw.Write(Encoding.ASCII.GetBytes(Port));             // port
             }
             if (RemAddrLen > 0)
             {
                 bw.Write(Encoding.ASCII.GetBytes(RemAddr.ToString()));                // remote address
             }
             if (DataLen > 0)
             {
                 bw.Write(Encoding.ASCII.GetBytes(Data));
             }
         }
         return(buffer.ToArray());
     }
 }
 public byte[] ToArray()
 {
     using (var buffer = new MemoryStream())
     {
         using (var bw = new BinaryWriter(buffer))
         {
             bw.Write((byte)AuthenMethod);
             bw.Write((byte)PrivLvl);
             bw.Write((byte)AuthenType);
             bw.Write((byte)Service);
             bw.Write(UserLen);
             bw.Write(PortLen);
             bw.Write(RemAddrLen);
             bw.Write(ArgCnt);
             foreach (var arg in Args)
             {
                 bw.Write((byte)arg.Length);
             }
             if (UserLen > 0)
             {
                 bw.Write(Encoding.ASCII.GetBytes(User));
             }
             if (PortLen > 0)
             {
                 bw.Write(Encoding.ASCII.GetBytes(Port));
             }
             if (RemAddrLen > 0)
             {
                 bw.Write(Encoding.ASCII.GetBytes(RemAddr.ToString()));
             }
             foreach (var arg in Args)
             {
                 bw.Write(Encoding.ASCII.GetBytes(arg));
             }
         }
         return(buffer.ToArray());
     }
 }