public override int Read(byte[] buffer, int offset, int count) { int res = _ist.Read(buffer, offset, count); if (res != -1) { _position += res; return(res); } return(0); }
/// <exception cref="System.IO.IOException"></exception> internal override int ReadTrailerWireFormat(InputStream @in, byte[] buffer, int bufferIndex ) { int start = bufferIndex; if (@in.Read(buffer, bufferIndex, Length) != Length) { throw new IOException("invalid session request wire format"); } bufferIndex += _calledName.ReadWireFormat(buffer, bufferIndex); bufferIndex += _callingName.ReadWireFormat(buffer, bufferIndex); return bufferIndex - start; }
/// <exception cref="System.IO.IOException"></exception> internal override int ReadTrailerWireFormat(InputStream @in, byte[] buffer, int bufferIndex ) { if (@in.Read(buffer, bufferIndex, Length) != Length) { throw new IOException("unexpected EOF reading netbios retarget session response"); } int addr = ReadInt4(buffer, bufferIndex); bufferIndex += 4; _retargetAddress = new NbtAddress(null, addr, false, NbtAddress.BNode); _retargetPort = ReadInt2(buffer, bufferIndex); return Length; }
/// <exception cref="System.IO.IOException"></exception> internal static int Readn(InputStream @in, byte[] b, int off, int len) { int i = 0; int n; while (i < len) { n = @in.Read(b, off + i, len - i); if (n <= 0) { break; } i += n; } return i; }
/// <exception cref="System.IO.IOException"></exception> internal virtual void Ssn139() { Name calledName = new Name(Address.FirstCalledName(), 0x20, null ); do { Socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); if (LocalAddr != null) { Socket.Bind2(new IPEndPoint(LocalAddr, LocalPort)); } Socket.Connect(new IPEndPoint(IPAddress.Parse(Address.GetHostAddress()), 139), SmbConstants.ConnTimeout); Socket.SoTimeOut = SmbConstants.SoTimeout; Out = Socket.GetOutputStream(); In = Socket.GetInputStream(); SessionServicePacket ssp = new SessionRequestPacket(calledName, NbtAddress.GetLocalName ()); Out.Write(Sbuf, 0, ssp.WriteWireFormat(Sbuf, 0)); if (Readn(In, Sbuf, 0, 4) < 4) { try { Socket.Dispose(); } catch (IOException) { } throw new SmbException("EOF during NetBIOS session request"); } switch (Sbuf[0] & 0xFF) { case SessionServicePacket.PositiveSessionResponse: { if (Log.Level >= 4) { Log.WriteLine("session established ok with " + Address); } return; } case SessionServicePacket.NegativeSessionResponse: { int errorCode = In.Read() & 0xFF; switch (errorCode) { case NbtException.CalledNotPresent: case NbtException.NotListeningCalled: { Socket.Dispose(); break; } default: { Disconnect(true); throw new NbtException(NbtException.ErrSsnSrvc, errorCode); } } break; } case -1: { Disconnect(true); throw new NbtException(NbtException.ErrSsnSrvc, NbtException.ConnectionRefused ); } default: { Disconnect(true); throw new NbtException(NbtException.ErrSsnSrvc, 0); } } } while ((calledName.name = Address.NextCalledName()) != null); throw new IOException("Failed to establish session with " + Address); }