NameServiceClient.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. using System;
  18. using System.Collections.Generic;
  19. using System.IO;
  20. using System.Net;
  21. using System.Net.Sockets;
  22. using System.Linq;
  23. using System.Threading;
  24. using SharpCifs.Smb;
  25. using SharpCifs.Util;
  26. using SharpCifs.Util.DbsHelper;
  27. using SharpCifs.Util.Sharpen;
  28. using Thread = SharpCifs.Util.Sharpen.Thread;
  29. using System.Threading.Tasks;
  30. namespace SharpCifs.Netbios
  31. {
  32. internal class NameServiceClient : IRunnable
  33. {
  34. internal const int DefaultSoTimeout = 5000;
  35. internal const int DefaultRcvBufSize = 576;
  36. internal const int DefaultSndBufSize = 576;
  37. internal const int NameServiceUdpPort = 137;
  38. internal const int DefaultRetryCount = 2;
  39. internal const int DefaultRetryTimeout = 3000;
  40. internal const int ResolverLmhosts = 1;
  41. internal const int ResolverBcast = 2;
  42. internal const int ResolverWins = 3;
  43. private static readonly int SndBufSize
  44. = Config.GetInt("jcifs.netbios.snd_buf_size", DefaultSndBufSize);
  45. private static readonly int RcvBufSize
  46. = Config.GetInt("jcifs.netbios.rcv_buf_size", DefaultRcvBufSize);
  47. private static readonly int SoTimeout
  48. = Config.GetInt("jcifs.netbios.soTimeout", DefaultSoTimeout);
  49. private static readonly int RetryCount
  50. = Config.GetInt("jcifs.netbios.retryCount", DefaultRetryCount);
  51. private static readonly int RetryTimeout
  52. = Config.GetInt("jcifs.netbios.retryTimeout", DefaultRetryTimeout);
  53. private static readonly int Lport
  54. = Config.GetInt("jcifs.netbios.lport", 137);
  55. private static readonly IPAddress Laddr
  56. = Config.GetInetAddress("jcifs.netbios.laddr", null);
  57. private static readonly string Ro
  58. = Config.GetProperty("jcifs.resolveOrder");
  59. private static LogStream _log = LogStream.GetInstance();
  60. private readonly object _lock = new object();
  61. private int _lport;
  62. private int _closeTimeout;
  63. private byte[] _sndBuf;
  64. private byte[] _rcvBuf;
  65. private SocketEx _socketSender;
  66. private Hashtable _responseTable = new Hashtable();
  67. private Thread _thread;
  68. private int _nextNameTrnId;
  69. private int[] _resolveOrder;
  70. private bool _waitResponse = true;
  71. private bool _isActive = false;
  72. private AutoResetEvent _autoResetWaitReceive;
  73. internal IPAddress laddr;
  74. internal IPAddress Baddr;
  75. public NameServiceClient()
  76. : this(Lport, Laddr)
  77. {
  78. }
  79. internal NameServiceClient(int lport, IPAddress laddr)
  80. {
  81. this._lport = lport;
  82. this.laddr = laddr
  83. ?? Config.GetLocalHost()
  84. ?? Extensions.GetLocalAddresses()?.FirstOrDefault();
  85. if (this.laddr == null)
  86. throw new ArgumentNullException("IPAddress NOT found. if exec on localhost, set vallue to [jcifs.smb.client.laddr]");
  87. try
  88. {
  89. Baddr = Config.GetInetAddress("jcifs.netbios.baddr",
  90. Extensions.GetAddressByName("255.255.255.255"));
  91. }
  92. catch (Exception ex)
  93. {
  94. }
  95. _sndBuf = new byte[SndBufSize];
  96. _rcvBuf = new byte[RcvBufSize];
  97. if (string.IsNullOrEmpty(Ro))
  98. {
  99. if (NbtAddress.GetWinsAddress() == null)
  100. {
  101. _resolveOrder = new int[2];
  102. _resolveOrder[0] = ResolverLmhosts;
  103. _resolveOrder[1] = ResolverBcast;
  104. }
  105. else
  106. {
  107. _resolveOrder = new int[3];
  108. _resolveOrder[0] = ResolverLmhosts;
  109. _resolveOrder[1] = ResolverWins;
  110. _resolveOrder[2] = ResolverBcast;
  111. }
  112. }
  113. else
  114. {
  115. int[] tmp = new int[3];
  116. StringTokenizer st = new StringTokenizer(Ro, ",");
  117. int i = 0;
  118. while (st.HasMoreTokens())
  119. {
  120. string s = st.NextToken().Trim();
  121. if (Runtime.EqualsIgnoreCase(s, "LMHOSTS"))
  122. {
  123. tmp[i++] = ResolverLmhosts;
  124. }
  125. else
  126. {
  127. if (Runtime.EqualsIgnoreCase(s, "WINS"))
  128. {
  129. if (NbtAddress.GetWinsAddress() == null)
  130. {
  131. if (_log.Level > 1)
  132. {
  133. _log.WriteLine("NetBIOS resolveOrder specifies WINS however the "
  134. + "jcifs.netbios.wins property has not been set");
  135. }
  136. continue;
  137. }
  138. tmp[i++] = ResolverWins;
  139. }
  140. else
  141. {
  142. if (Runtime.EqualsIgnoreCase(s, "BCAST"))
  143. {
  144. tmp[i++] = ResolverBcast;
  145. }
  146. else
  147. {
  148. if (Runtime.EqualsIgnoreCase(s, "DNS"))
  149. {
  150. }
  151. else
  152. {
  153. // skip
  154. if (_log.Level > 1)
  155. {
  156. _log.WriteLine("unknown resolver method: " + s);
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. _resolveOrder = new int[i];
  164. Array.Copy(tmp, 0, _resolveOrder, 0, i);
  165. }
  166. }
  167. internal virtual int GetNextNameTrnId()
  168. {
  169. if ((++_nextNameTrnId & unchecked(0xFFFF)) == 0)
  170. {
  171. _nextNameTrnId = 1;
  172. }
  173. return _nextNameTrnId;
  174. }
  175. /// <exception cref="System.IO.IOException"></exception>
  176. internal virtual void EnsureOpen(int timeout)
  177. {
  178. //Log.Out($"NameServiceClient.EnsureOpen");
  179. _closeTimeout = 0;
  180. if (SoTimeout != 0)
  181. {
  182. _closeTimeout = Math.Max(SoTimeout, timeout);
  183. }
  184. var localPort = (SmbConstants.Lport == 0) ? _lport : SmbConstants.Lport;
  185. // If socket is still good, the new closeTimeout will
  186. // be ignored; see tryClose comment.
  187. if (
  188. _socketSender == null
  189. || _socketSender.LocalEndPoint == null
  190. || _socketSender.GetLocalPort() != localPort
  191. || !IPAddress.Any.Equals(_socketSender.GetLocalInetAddress())
  192. )
  193. {
  194. if (_socketSender != null)
  195. {
  196. _socketSender.Dispose();
  197. _socketSender = null;
  198. }
  199. _socketSender = new SocketEx(AddressFamily.InterNetwork,
  200. SocketType.Dgram,
  201. ProtocolType.Udp);
  202. _socketSender.Bind(new IPEndPoint(IPAddress.Any, localPort));
  203. if (_waitResponse)
  204. {
  205. if (_thread != null)
  206. {
  207. _thread.Cancel(true);
  208. _thread.Dispose();
  209. }
  210. _thread = new Thread(this);
  211. _thread.SetDaemon(true);
  212. _thread.Start(true);
  213. }
  214. }
  215. }
  216. internal virtual void TryClose()
  217. {
  218. //Log.Out("NameSerciceClient.TryClose");
  219. if (this._isActive)
  220. {
  221. //Log.Out("NameSerciceClient.TryClose - Now in Processing... Exit.");
  222. return;
  223. }
  224. lock (_lock)
  225. {
  226. if (_socketSender != null)
  227. {
  228. _socketSender.Dispose();
  229. _socketSender = null;
  230. //Log.Out("NameSerciceClient.TryClose - _socketSender.Disposed");
  231. }
  232. if (_thread != null)
  233. {
  234. _thread.Cancel(true);
  235. _thread.Dispose();
  236. _thread = null;
  237. //Log.Out("NameSerciceClient.TryClose - _thread.Aborted");
  238. }
  239. if (_waitResponse)
  240. {
  241. _responseTable.Clear();
  242. }
  243. else
  244. {
  245. _autoResetWaitReceive.Set();
  246. }
  247. }
  248. }
  249. private int _recievedLength = -1;
  250. public virtual void Run()
  251. {
  252. int nameTrnId;
  253. NameServicePacket response;
  254. try
  255. {
  256. while (Thread.CurrentThread().Equals(_thread))
  257. {
  258. if (_thread.IsCanceled)
  259. break;
  260. var localPort = (SmbConstants.Lport == 0) ? _lport : SmbConstants.Lport;
  261. var sockEvArg = new SocketAsyncEventArgs();
  262. sockEvArg.RemoteEndPoint = new IPEndPoint(IPAddress.Any, localPort);
  263. sockEvArg.SetBuffer(_rcvBuf, 0, RcvBufSize);
  264. sockEvArg.Completed += this.OnReceiveCompleted;
  265. _socketSender.SoTimeOut = _closeTimeout;
  266. this._recievedLength = -1;
  267. //Log.Out($"NameServiceClient.Run - Wait Recieve: {IPAddress.Any}: {localPort}");
  268. _socketSender.ReceiveFromAsync(sockEvArg);
  269. while (this._recievedLength == -1)
  270. {
  271. if (_thread.IsCanceled)
  272. break;
  273. Task.Delay(300).GetAwaiter().GetResult();
  274. }
  275. sockEvArg?.Dispose();
  276. if (_thread.IsCanceled)
  277. break;
  278. if (_log.Level > 3)
  279. {
  280. _log.WriteLine("NetBIOS: new data read from socket");
  281. }
  282. nameTrnId = NameServicePacket.ReadNameTrnId(_rcvBuf, 0);
  283. response = (NameServicePacket)_responseTable.Get(nameTrnId);
  284. if (response == null || response.Received)
  285. {
  286. continue;
  287. }
  288. lock (response)
  289. {
  290. if (_thread.IsCanceled)
  291. break;
  292. response.ReadWireFormat(_rcvBuf, 0);
  293. if (_log.Level > 3)
  294. {
  295. _log.WriteLine(response);
  296. Hexdump.ToHexdump(_log, _rcvBuf, 0, this._recievedLength);
  297. }
  298. if (response.IsResponse)
  299. {
  300. response.Received = true;
  301. Runtime.Notify(response);
  302. }
  303. }
  304. }
  305. }
  306. catch (TimeoutException) { }
  307. catch (Exception ex)
  308. {
  309. if (_log.Level > 2)
  310. {
  311. Runtime.PrintStackTrace(ex, _log);
  312. }
  313. }
  314. finally
  315. {
  316. TryClose();
  317. }
  318. }
  319. private void OnReceiveCompleted(object sender, SocketAsyncEventArgs e)
  320. {
  321. //Log.Out("NameServiceClient.OnReceiveCompleted");
  322. this._recievedLength = e.BytesTransferred;
  323. }
  324. /// <exception cref="System.IO.IOException"></exception>
  325. internal virtual void Send(NameServicePacket request,
  326. NameServicePacket response,
  327. int timeout)
  328. {
  329. //Log.Out("NameSerciceClient.Send - Start");
  330. int nid = 0;
  331. int max = NbtAddress.Nbns.Length;
  332. if (max == 0)
  333. {
  334. max = 1;
  335. }
  336. lock (response)
  337. {
  338. this._isActive = true;
  339. while (max-- > 0)
  340. {
  341. try
  342. {
  343. lock (_lock)
  344. {
  345. request.NameTrnId = GetNextNameTrnId();
  346. nid = request.NameTrnId;
  347. response.Received = false;
  348. _responseTable.Put(nid, response);
  349. //Log.Out($"NameSerciceClient.Send - timeout = {timeout}");
  350. EnsureOpen(timeout + 1000);
  351. int requestLenght = request.WriteWireFormat(_sndBuf, 0);
  352. byte[] msg = new byte[requestLenght];
  353. Array.Copy(_sndBuf, msg, requestLenght);
  354. _socketSender.SetSocketOption(SocketOptionLevel.Socket,
  355. SocketOptionName.Broadcast,
  356. request.IsBroadcast
  357. ? 1
  358. : 0);
  359. _socketSender.SendTo(msg, new IPEndPoint(request.Addr, _lport));
  360. //Log.Out("NameSerciceClient.Send - Sended");
  361. if (_log.Level > 3)
  362. {
  363. _log.WriteLine(request);
  364. Hexdump.ToHexdump(_log, _sndBuf, 0, requestLenght);
  365. }
  366. }
  367. if (_waitResponse)
  368. {
  369. long start = Runtime.CurrentTimeMillis();
  370. var isRecieved = false;
  371. var startTime = DateTime.Now;
  372. while (timeout > 0)
  373. {
  374. Runtime.Wait(response, timeout);
  375. if (response.Received && request.QuestionType == response.RecordType)
  376. {
  377. //return;
  378. isRecieved = true;
  379. break;
  380. }
  381. response.Received = false;
  382. timeout -= (int)(Runtime.CurrentTimeMillis() - start);
  383. //if (timeout <= 0)
  384. //{
  385. // Log.Out($"NameSerciceClient.Send Timeout! - {(DateTime.Now - startTime).TotalMilliseconds} msec");
  386. //}
  387. }
  388. if (isRecieved)
  389. break;
  390. }
  391. }
  392. catch (Exception ie)
  393. {
  394. if (_waitResponse)
  395. _responseTable.Remove(nid);
  396. //Log.Out("NameSerciceClient.Send - IOException");
  397. throw new IOException(ie.Message);
  398. }
  399. finally
  400. {
  401. if (_waitResponse)
  402. _responseTable.Remove(nid);
  403. }
  404. if (_waitResponse)
  405. {
  406. lock (_lock)
  407. {
  408. if (NbtAddress.IsWins(request.Addr) == false)
  409. {
  410. break;
  411. }
  412. if (request.Addr == NbtAddress.GetWinsAddress())
  413. {
  414. NbtAddress.SwitchWins();
  415. }
  416. request.Addr = NbtAddress.GetWinsAddress();
  417. }
  418. }
  419. }
  420. this._isActive = false;
  421. //Log.Out("NameSerciceClient.Send - Normaly Ended.");
  422. }
  423. }
  424. /// <exception cref="UnknownHostException"></exception>
  425. internal virtual NbtAddress[] GetAllByName(Name name, IPAddress addr)
  426. {
  427. //Log.Out("NameSerciceClient.GetAllByName");
  428. int n;
  429. NameQueryRequest request = new NameQueryRequest(name);
  430. NameQueryResponse response = new NameQueryResponse();
  431. request.Addr = addr ?? NbtAddress.GetWinsAddress();
  432. request.IsBroadcast = (request.Addr == null
  433. || request.Addr.ToString() == Baddr.ToString());
  434. if (request.IsBroadcast)
  435. {
  436. request.Addr = Baddr;
  437. n = RetryCount;
  438. }
  439. else
  440. {
  441. request.IsBroadcast = false;
  442. n = 1;
  443. }
  444. do
  445. {
  446. try
  447. {
  448. Send(request, response, RetryTimeout);
  449. }
  450. catch (IOException ioe)
  451. {
  452. if (_log.Level > 1)
  453. {
  454. Runtime.PrintStackTrace(ioe, _log);
  455. }
  456. throw new UnknownHostException(ioe);
  457. }
  458. if (response.Received && response.ResultCode == 0)
  459. {
  460. return response.AddrEntry;
  461. }
  462. }
  463. while (--n > 0 && request.IsBroadcast);
  464. throw new UnknownHostException();
  465. }
  466. /// <exception cref="UnknownHostException"></exception>
  467. internal virtual NbtAddress GetByName(Name name, IPAddress addr)
  468. {
  469. //Log.Out("NameSerciceClient.GetByName");
  470. int n;
  471. NameQueryRequest request = new NameQueryRequest(name);
  472. NameQueryResponse response = new NameQueryResponse();
  473. if (addr != null)
  474. {
  475. request.Addr = addr;
  476. request.IsBroadcast = (addr.GetAddressBytes()[3] == unchecked(unchecked(0xFF)));
  477. n = RetryCount;
  478. do
  479. {
  480. try
  481. {
  482. Send(request, response, RetryTimeout);
  483. }
  484. catch (IOException ioe)
  485. {
  486. if (_log.Level > 1)
  487. {
  488. Runtime.PrintStackTrace(ioe, _log);
  489. }
  490. throw new UnknownHostException(ioe);
  491. }
  492. if (response.Received
  493. && response.ResultCode == 0
  494. && response.IsResponse)
  495. {
  496. int last = response.AddrEntry.Length - 1;
  497. response.AddrEntry[last].HostName.SrcHashCode = addr.GetHashCode();
  498. return response.AddrEntry[last];
  499. }
  500. }
  501. while (--n > 0 && request.IsBroadcast);
  502. throw new UnknownHostException();
  503. }
  504. for (int i = 0; i < _resolveOrder.Length; i++)
  505. {
  506. try
  507. {
  508. switch (_resolveOrder[i])
  509. {
  510. case ResolverLmhosts:
  511. {
  512. NbtAddress ans = Lmhosts.GetByName(name);
  513. if (ans != null)
  514. {
  515. ans.HostName.SrcHashCode = 0;
  516. // just has to be different
  517. // from other methods
  518. return ans;
  519. }
  520. break;
  521. }
  522. case ResolverWins:
  523. case ResolverBcast:
  524. {
  525. if (_resolveOrder[i] == ResolverWins
  526. && name.name != NbtAddress.MasterBrowserName
  527. && name.HexCode != unchecked(0x1d))
  528. {
  529. request.Addr = NbtAddress.GetWinsAddress();
  530. request.IsBroadcast = false;
  531. }
  532. else
  533. {
  534. request.Addr = Baddr;
  535. request.IsBroadcast = true;
  536. }
  537. n = RetryCount;
  538. while (n-- > 0)
  539. {
  540. try
  541. {
  542. Send(request, response, RetryTimeout);
  543. }
  544. catch (IOException ioe)
  545. {
  546. if (_log.Level > 1)
  547. {
  548. Runtime.PrintStackTrace(ioe, _log);
  549. }
  550. throw new UnknownHostException(ioe);
  551. }
  552. if (response.Received
  553. && response.ResultCode == 0
  554. && response.IsResponse)
  555. {
  556. response.AddrEntry[0].HostName.SrcHashCode
  557. = request.Addr.GetHashCode();
  558. return response.AddrEntry[0];
  559. }
  560. if (_resolveOrder[i] == ResolverWins)
  561. {
  562. break;
  563. }
  564. }
  565. break;
  566. }
  567. }
  568. }
  569. catch (IOException)
  570. {
  571. }
  572. }
  573. throw new UnknownHostException();
  574. }
  575. /// <exception cref="UnknownHostException"></exception>
  576. internal virtual NbtAddress[] GetNodeStatus(NbtAddress addr)
  577. {
  578. //Log.Out("NameSerciceClient.GetNodeStatus");
  579. int n;
  580. int srcHashCode;
  581. NodeStatusRequest request;
  582. NodeStatusResponse response;
  583. response = new NodeStatusResponse(addr);
  584. request = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName, unchecked(0x00), null));
  585. request.Addr = addr.GetInetAddress();
  586. n = RetryCount;
  587. while (n-- > 0)
  588. {
  589. try
  590. {
  591. Send(request, response, RetryTimeout);
  592. }
  593. catch (IOException ioe)
  594. {
  595. if (_log.Level > 1)
  596. {
  597. Runtime.PrintStackTrace(ioe, _log);
  598. }
  599. throw new UnknownHostException(ioe);
  600. }
  601. if (response.Received && response.ResultCode == 0)
  602. {
  603. srcHashCode = request.Addr.GetHashCode();
  604. for (int i = 0; i < response.AddressArray.Length; i++)
  605. {
  606. response.AddressArray[i].HostName.SrcHashCode = srcHashCode;
  607. }
  608. return response.AddressArray;
  609. }
  610. }
  611. throw new UnknownHostException();
  612. }
  613. internal virtual NbtAddress[] GetHosts()
  614. {
  615. //Log.Out("NbtServiceClient.GetHosts");
  616. try
  617. {
  618. _waitResponse = false;
  619. byte[] bAddrBytes = laddr.GetAddressBytes();
  620. for (int i = 1; i <= 254; i++)
  621. {
  622. //Log.Out($"NbtServiceClient.GetHosts - {i}");
  623. NodeStatusRequest request;
  624. NodeStatusResponse response;
  625. byte[] addrBytes = {
  626. bAddrBytes[0],
  627. bAddrBytes[1],
  628. bAddrBytes[2],
  629. (byte)i
  630. };
  631. IPAddress addr = new IPAddress(addrBytes);
  632. response = new NodeStatusResponse(
  633. new NbtAddress(NbtAddress.UnknownName,
  634. BitConverter.ToInt32(addr.GetAddressBytes(), 0),
  635. false,
  636. 0x20)
  637. );
  638. request = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName,
  639. unchecked(0x20),
  640. null))
  641. {
  642. Addr = addr
  643. };
  644. Send(request, response, 0);
  645. }
  646. }
  647. catch (IOException ioe)
  648. {
  649. //Log.Out(ioe);
  650. if (_log.Level > 1)
  651. {
  652. Runtime.PrintStackTrace(ioe, _log);
  653. }
  654. throw new UnknownHostException(ioe);
  655. }
  656. _autoResetWaitReceive = new AutoResetEvent(false);
  657. if (_thread != null)
  658. {
  659. _thread.Cancel(true);
  660. _thread.Dispose();
  661. }
  662. _thread = new Thread(this);
  663. _thread.SetDaemon(true);
  664. _thread.Start(true);
  665. _autoResetWaitReceive.WaitOne();
  666. var result = new List<NbtAddress>();
  667. foreach (var key in _responseTable.Keys)
  668. {
  669. var resp = (NodeStatusResponse)_responseTable[key];
  670. if (!resp.Received || resp.ResultCode != 0)
  671. continue;
  672. result.AddRange(resp.AddressArray
  673. .Where(entry => entry.HostName.HexCode == 0x20));
  674. }
  675. _responseTable.Clear();
  676. _waitResponse = true;
  677. return result.Count > 0 ? result.ToArray() : null;
  678. }
  679. }
  680. }