Exemple #1
0
        /// <summary>
        /// Get the adapter id
        /// </summary>
        /// <returns>The adapter id</returns>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// throw when Get adapterId fails
        /// </exception>
        public byte GetAdapterId()
        {
            if (disposed)
            {
                throw new ObjectDisposedException("NetbiosTransport");
            }

            NCB ncb = new NCB();

            try
            {
                NetbiosUtility.InitNcb(ref ncb);
                ncb.ncb_command = (byte)NcbCommand.NCBENUM;
                ncb.ncb_buffer  = Marshal.AllocHGlobal(maxBufferSize);
                ncb.ncb_length  = maxBufferSize;

                InvokeNetBios(ref ncb);

                if (ncb.ncb_retcode != (byte)NcbReturnCode.NRC_GOODRET)
                {
                    throw new InvalidOperationException("Failed in NCBENUM command, error is "
                                                        + ((NcbReturnCode)ncb.ncb_retcode).ToString());
                }

                LANA_ENUM lenum = new LANA_ENUM();
                lenum.length  = Marshal.ReadByte(ncb.ncb_buffer, 0);
                lenum.lanaNum = new byte[lenum.length];

                for (int i = 0; i < lenum.length; i++)
                {
                    lenum.lanaNum[i] = Marshal.ReadByte(ncb.ncb_buffer, i + 1);
                }

                return(lenum.lanaNum[adapterIndex]);
            }
            finally
            {
                NetbiosUtility.FreeNcbNativeFields(ref ncb);
            }
        }
        /// <summary>
        /// Get the adapter id
        /// </summary>
        /// <returns>The adapter id</returns>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// throw when Get adapterId fails
        /// </exception>
        public byte GetAdapterId()
        {
            if (disposed)
            {
                throw new ObjectDisposedException("NetbiosTransport");
            }

            NCB ncb = new NCB();

            try
            {
                NetbiosUtility.InitNcb(ref ncb);
                ncb.ncb_command = (byte)NcbCommand.NCBENUM;
                ncb.ncb_buffer = Marshal.AllocHGlobal(maxBufferSize);
                ncb.ncb_length = maxBufferSize;

                InvokeNetBios(ref ncb);

                if (ncb.ncb_retcode != (byte)NcbReturnCode.NRC_GOODRET)
                {
                    throw new InvalidOperationException("Failed in NCBENUM command, error is "
                        + ((NcbReturnCode)ncb.ncb_retcode).ToString());
                }

                LANA_ENUM lenum = new LANA_ENUM();
                lenum.length = Marshal.ReadByte(ncb.ncb_buffer, 0);
                lenum.lanaNum = new byte[lenum.length];

                for (int i = 0; i < lenum.length; i++)
                {
                    lenum.lanaNum[i] = Marshal.ReadByte(ncb.ncb_buffer, i + 1);
                }

                return lenum.lanaNum[adapterIndex];
            }
            finally
            {
                NetbiosUtility.FreeNcbNativeFields(ref ncb);
            }
        }