SessionRequestPacket.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. int start = bufferIndex;
  47. if (@in.Read(buffer, bufferIndex, Length) != Length)
  48. {
  49. throw new IOException("invalid session request wire format");
  50. }
  51. bufferIndex += _calledName.ReadWireFormat(buffer, bufferIndex);
  52. bufferIndex += _callingName.ReadWireFormat(buffer, bufferIndex);
  53. return bufferIndex - start;
  54. }
  55. }
  56. }