Esempio n. 1
0
 /// <summary>
 ///   Clears the name resolver chache and reloads LMHosts file
 /// </summary>
 public static void ClearNameResolverCache()
 {
     NbtNameResolver.ClearCache();
 }
Esempio n. 2
0
        public void DoCall(string netbiosname)
        {
            lock (this)  // This entire method needs to be synchronized
            {
                // int retry_count = 0;
                int port = SSN_SRVC_TCP_PORT;

                InetAddress = NbtNameResolver.Resolve(netbiosname);

                // Get the real NetBIOS name & Workgroup from an IP
                NBTNameService ns   = new NBTNameService();
                NbInfo         info = ns.queryStatus(InetAddress);
                NetBiosName   = info.Name;
                WorkgroupName = info.Workgroup;

                // If we couldn't resolve the name, then the host either doesn't
                // exist or does not support CIFS.
                if (NetBiosName == null)
                {
                    throw new CifsIoException("CM2", InetAddress.ToString());
                }


                DoConnect(InetAddress, port);
                byte[] packet = MakeRequestPacket(NetBiosName);

                if (Debug.DebugOn && Debug.DebugLevel >= Debug.Info)
                {
                    Debug.WriteLine(Debug.Info, "NetBIOS: doCall");
                    Debug.WriteLine(Debug.Info, "Called name=" + NetBiosName);
                    Debug.WriteLine(Debug.Info, "Calling name=" + fCallingName);
                    Debug.WriteLine(Debug.Info, "Called addr=" + InetAddress.ToString());

                    if (Debug.DebugLevel >= Debug.Buffer)
                    {
                        Debug.WriteLine(Debug.Buffer, "Packet to send:");
                        Debug.WriteLine(Debug.Buffer, packet, 0, packet.Length);
                    }
                }

                try
                {
                    fOutput.Write(packet, 0, packet.Length);
                    fOutput.Flush();
                }
                catch (IOException e)
                {
                    DoHangup();
                    throw new CifsIoException("NB500").setDetail(e);
                }

                // read header
                try
                {
                    int count = Read(packet, 0, HDR_SIZE);


                    if (Debug.DebugOn && Debug.DebugLevel >= Debug.Buffer)
                    {
                        Debug.WriteLine(Debug.Buffer, "Recieved packet:");
                        Debug.WriteLine(Debug.Buffer, packet, 0, packet.Length);
                    }



                    if (count < HDR_SIZE)
                    {
                        DoHangup();
                        throw new CifsIoException("NB501");
                    }

                    byte type = packet[HDR_TYPE_1];

                    switch (type)
                    {
                    case SPT_POS_RESPONSE:
                        /*
                         *  POSITIVE SESSION RESPONSE PACKET
                         *
                         *                      1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                         *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |      TYPE     |     FLAGS     |            LENGTH             |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         */
                        break;

                    case SPT_NEG_RESPONSE:
                        /*
                         *  NEGATIVE SESSION RESPONSE PACKET
                         *
                         *                      1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                         *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |      TYPE     |     FLAGS     |            LENGTH             |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |   ERROR_CODE  |
                         +-+-+-+-+-+-+-+-+
                         */

                        int rc = fInput.ReadByte();
                        Debug.WriteLine(Debug.Error, "NetBIOS: Negative response: " + rc);

                        DoHangup();
                        throw CifsIoException.getNBException(rc & 0xff);

                    case SPT_RTG_RESPONSE:
                        /*
                         * SESSION RETARGET RESPONSE PACKET
                         *
                         *     1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                         * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |      TYPE     |     FLAGS     |            LENGTH             |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |                      RETARGET_IP_ADDRESS                      |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |           PORT                |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         */
                        count = Read(packet, 0, RT_SIZE);
                        DoHangup();
                        throw new CifsIoException("NB502");

                    default:
                        DoHangup();
                        throw new CifsRuntimeException("NB503", (Int32)type);
                    }
                }
                catch (IOException e)
                {
                    DoHangup();
                    throw new CifsIoException("NB501").setDetail(e);
                }
            }
        }