2
0

SessionRequestPacket.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. using System.IO;
  18. using SharpCifs.Util.Sharpen;
  19. namespace SharpCifs.Netbios
  20. {
  21. public class SessionRequestPacket : SessionServicePacket
  22. {
  23. private Name _calledName;
  24. private Name _callingName;
  25. public SessionRequestPacket()
  26. {
  27. _calledName = new Name();
  28. _callingName = new Name();
  29. }
  30. public SessionRequestPacket(Name calledName, Name callingName)
  31. {
  32. Type = SessionRequest;
  33. this._calledName = calledName;
  34. this._callingName = callingName;
  35. }
  36. internal override int WriteTrailerWireFormat(byte[] dst, int dstIndex)
  37. {
  38. int start = dstIndex;
  39. dstIndex += _calledName.WriteWireFormat(dst, dstIndex);
  40. dstIndex += _callingName.WriteWireFormat(dst, dstIndex);
  41. return dstIndex - start;
  42. }
  43. /// <exception cref="System.IO.IOException"></exception>
  44. internal override int ReadTrailerWireFormat(InputStream @in, byte[] buffer, int bufferIndex
  45. )
  46. {
  47. int start = bufferIndex;
  48. if (@in.Read(buffer, bufferIndex, Length) != Length)
  49. {
  50. throw new IOException("invalid session request wire format");
  51. }
  52. bufferIndex += _calledName.ReadWireFormat(buffer, bufferIndex);
  53. bufferIndex += _callingName.ReadWireFormat(buffer, bufferIndex);
  54. return bufferIndex - start;
  55. }
  56. }
  57. }