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.Close();
}
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.Close();
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);
}