/// <summary> /// Unregister the bios name /// </summary> /// <exception cref="ObjectDisposedException"> /// thrown when this object is disposed. /// </exception> public void UnRegisterName() { if (disposed) { throw new ObjectDisposedException("NetbiosTransport"); } // if the local name in .ctr is null, exception is thrown, // the gc will dispose the object and this method will be invoked. if (this.localNetbiosName == null) { return; } NCB ncb = new NCB(); try { NetbiosUtility.InitNcb(ref ncb); ncb.ncb_command = (byte)NcbCommand.NCBDELNAME; ncb.ncb_lana_num = networkAdapterId; ncb.ncb_num = ncbNum; ncb.ncb_name = NetbiosUtility.ToNetbiosName(localNetbiosName); InvokeNetBios(ref ncb); } finally { NetbiosUtility.FreeNcbNativeFields(ref ncb); } }
/// <summary> /// Listen to local netbios endpoint /// </summary> /// <returns>The connected session id</returns> /// <exception cref="ObjectDisposedException"> /// thrown when this object is disposed. /// </exception> /// <exception cref="InvalidOperationException"> /// throw when listen fails /// </exception> public byte Listen() { if (disposed) { throw new ObjectDisposedException("NetbiosTransport"); } NCB ncb = new NCB(); try { NetbiosUtility.InitNcb(ref ncb); ncb.ncb_command = (byte)NcbCommand.NCBLISTEN; ncb.ncb_lana_num = networkAdapterId; //* means it can accept any connection. ncb.ncb_callname = NetbiosUtility.ToNetbiosName("*"); ncb.ncb_name = NetbiosUtility.ToNetbiosName(localNetbiosName); InvokeNetBios(ref ncb); if (ncb.ncb_retcode != (byte)NcbReturnCode.NRC_GOODRET) { throw new InvalidOperationException("Failed in NCBLISTEN command, error is " + ((NcbReturnCode)ncb.ncb_retcode).ToString()); } } finally { NetbiosUtility.FreeNcbNativeFields(ref ncb); } return(ncb.ncb_lsn); }
/// <summary> /// Register bios name for further call /// </summary> /// <returns>The name index</returns> /// <exception cref="ObjectDisposedException"> /// thrown when this object is disposed. /// </exception> /// <exception cref="InvalidOperationException"> /// throw when register name fails /// </exception> public byte RegisterName() { if (disposed) { throw new ObjectDisposedException("NetbiosTransport"); } NCB ncb = new NCB(); try { NetbiosUtility.InitNcb(ref ncb); ncb.ncb_command = (byte)NcbCommand.NCBADDNAME; ncb.ncb_lana_num = networkAdapterId; ncb.ncb_name = NetbiosUtility.ToNetbiosName(localNetbiosName); InvokeNetBios(ref ncb); if (ncb.ncb_retcode != (byte)NcbReturnCode.NRC_GOODRET) { throw new InvalidOperationException("Failed in NCBADDNAME command, error is " + ((NcbReturnCode)ncb.ncb_retcode).ToString()); } this.ncbNum = ncb.ncb_num; return(ncb.ncb_num); } finally { NetbiosUtility.FreeNcbNativeFields(ref ncb); } }
/// <summary> /// Connect to remote machine /// </summary> /// <param name="remoteName">The remote machine bios name</param> /// <returns>The session id</returns> /// <exception cref="ObjectDisposedException"> /// thrown when this object is disposed. /// </exception> /// <exception cref="InvalidOperationException"> /// throw when connect fails. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown when remoteName is null. /// </exception> public int Connect(string remoteName) { if (disposed) { throw new ObjectDisposedException("NetbiosTransport"); } if (remoteName == null) { throw new ArgumentNullException("remoteName"); } NCB ncb = new NCB(); try { NetbiosUtility.InitNcb(ref ncb); ncb.ncb_command = (byte)NcbCommand.NCBCALL; ncb.ncb_lana_num = networkAdapterId; ncb.ncb_name = NetbiosUtility.ToNetbiosName(localNetbiosName); ncb.ncb_callname = NetbiosUtility.ToNetbiosName(remoteName); InvokeNetBios(ref ncb); if (ncb.ncb_retcode != (byte)NcbReturnCode.NRC_GOODRET) { throw new InvalidOperationException("Failed in NCBCALL command, error is " + ((NcbReturnCode)ncb.ncb_retcode).ToString()); } } finally { NetbiosUtility.FreeNcbNativeFields(ref ncb); } return(ncb.ncb_lsn); }