Exemple #1
0
        // Several functions relating to printing have been ommited for now


        ///<summary>
        ///  Lists all computers of the specified type or types that are visible
        ///  in the specified domain.  It may also enumerate domains.
        ///</summary>
        ///<param name = "domain">The name of the workgroup in which to enumerate computers
        ///  of the specified type or types.  If domain is nul, servers
        ///  are enumerated for the current domain of the computer</param>
        ///<param name = "types">The type or types of computer to enumerate.  Computers that
        ///  match at least one of the specified types are returned (SV_*)</param>
        public CifsServerInfo[] ListServersInfo(string domain, uint types)
        {
            if (Debug.DebugOn)
            {
                Debug.WriteLine(Debug.Info, "listServersInfo");
            }

            var param = new MarshalBuffer(100);
            var data  = new MarshalBuffer(1000);

            DoNetServerEnum2(domain, types, 1, param, data);

            int pos = 0;

            pos += 2;

            // converter
            int converter = param.GetShortAt(pos);

            pos += 2;

            // number of entries
            int counter = param.GetShortAt(pos);

            pos += 2;

            int maxcounter = param.GetShortAt(pos);

            pos += 2;


            if (maxcounter > counter)
            {
                if (Debug.DebugOn)
                {
                    Debug.WriteLine(Debug.Warning, "The buffer for NetServerEnum2 was too small.");
                }
            }

            /*
             * struct SERVER_INFO_1 {
             *  char			sv1_name[16];
             *  char			sv1_version_major;
             *  char			sv1_version_minor;
             *  unsigned long	sv1_type;
             *  char        *sv1_comment_or_master_browser;
             * };
             */

            var infolist = new CifsServerInfo[counter];

            pos = 0;
            for (int i = 0; i < counter; i++)
            {
                var info = new CifsServerInfo();

                info.ComputerName = data.GetZtAsciiStringAt(pos, 16);
                pos += 16;

                info.MajorVersion = data.GetByteAt(pos) & 0xff;
                pos += 1;

                info.MinorVersion = data.GetByteAt(pos) & 0xff;
                pos += 1;

                info.ServerType = (UInt32)(data.GetIntAt(pos));
                pos            += 4;

                int rptr = (data.GetIntAt(pos) & 0xffff);
                pos += 4;

                if (rptr != 0)
                {
                    info.Comment = data.GetZtAsciiStringAt(rptr - converter, 255);
                }

                infolist[i] = info;
            }

            return(infolist);
        }