Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

638 lines
20 KiB

  1. #include "ipxdefs.h"
  2. #if DBG
  3. #define ASSERTERR(exp) \
  4. if (!(exp)) { \
  5. DbgPrint("Get last error= %d\n", GetLastError ()); \
  6. RtlAssert( #exp, __FILE__, __LINE__, NULL ); \
  7. }
  8. #else
  9. #define ASSERTERR(exp)
  10. #endif
  11. #if DBG
  12. #define ASSERTERRMSG(msg,exp) \
  13. if (!(exp)) { \
  14. DbgPrint("Get last error= %d\n", GetLastError ()); \
  15. RtlAssert( #exp, __FILE__, __LINE__, msg ); \
  16. }
  17. #else
  18. #define ASSERTERRMSG(msg,exp)
  19. #endif
  20. typedef struct _SERVICE_ENTRY {
  21. USHORT type;
  22. BYTE name[48];
  23. IPX_ADDRESS_BLOCK addr;
  24. USHORT hops;
  25. } SERVICE_ENTRY, *PSERVICE_ENTRY;
  26. typedef struct _SAP_PACKET {
  27. OVERLAPPED ovrp;
  28. ADDRESS_RESERVED rsvd;
  29. IPX_HEADER hdr;
  30. union {
  31. UCHAR data[576-sizeof(IPX_HEADER)];
  32. struct {
  33. USHORT operation;
  34. SERVICE_ENTRY entry[7];
  35. } sap;
  36. };
  37. } SAP_PACKET, *PSAP_PACKET;
  38. #define SAP_SOCKET_NUM 0x0452
  39. VOID CALLBACK
  40. SendCompletion (
  41. DWORD status,
  42. DWORD cbBytes,
  43. LPOVERLAPPED context
  44. );
  45. VOID CALLBACK
  46. RecvCompletion (
  47. DWORD status,
  48. DWORD cbBytes,
  49. LPOVERLAPPED context
  50. );
  51. BOOL WINAPI
  52. CtrlHandler (
  53. DWORD fdwCtrlType
  54. );
  55. static BOOL *AdapterArr;
  56. static SAP_PACKET recvPacket;
  57. static HANDLE hdl[2];
  58. static ULONG CurAdapter;
  59. static LONG NumActiveAdapters;
  60. static ADAPTERS_GLOBAL_PARAMETERS gParam;
  61. static HANDLE sockPort=INVALID_HANDLE_VALUE;
  62. static BOOL Stop;
  63. static LONG Flags = 0;
  64. #define FWD_IF_TEST 0x1
  65. #define SAP_SOCKET_TEST 0x2
  66. #define SEND_RECV_TEST 0x4
  67. int __cdecl main (
  68. int argc,
  69. char **argv
  70. ) {
  71. HANDLE cfgHdl;
  72. WCHAR name[64];
  73. ULONG i, len=sizeof (name);
  74. ADAPTER_INFO params;
  75. DWORD status;
  76. ULONG adpStatus;
  77. PSAP_PACKET sendPacket;
  78. FW_IF_INFO info;
  79. FW_IF_STATS stats;
  80. IPX_ADAPTER_BINDING_INFO binfo;
  81. ULONG dstNet;
  82. ULONG nodeLow;
  83. USHORT nodeHigh;
  84. UCHAR dstNode[6];
  85. USHORT dstSocket;
  86. RTM_IPX_ROUTE route;
  87. for (i=1; (INT)i<argc; i++) {
  88. _strupr (argv[i]);
  89. if (strcmp (argv[i], "FWD")==0) {
  90. Flags |= FWD_IF_TEST;
  91. printf ("Test forwarder interface.\n");
  92. }
  93. else if (!(Flags & SEND_RECV_TEST)
  94. && (strcmp (argv[i], "SAP")==0)) {
  95. Flags |= SAP_SOCKET_TEST;
  96. printf ("Test by sending and listening on sap socket.\n");
  97. }
  98. else if (!(Flags & SAP_SOCKET_TEST)
  99. && (sscanf ("%8lX:%8lX%4hX:%4hX", argv[i],
  100. &dstNet, &nodeLow, nodeHigh,
  101. &dstSocket)==4)) {
  102. Flags |= SEND_RECV_TEST;
  103. PUTULONG2LONG (&dstNode[0], nodeLow);
  104. PUTUSHORT2SHORT (&dstNode[4], nodeHigh);
  105. printf ("Test by sending to %08lx:%02x%02x%02x%02x%02x%02x:%04x and"
  106. " listening on socket %04x.\n", dstNet,
  107. dstNode[0], dstNode[1], dstNode[2],
  108. dstNode[3], dstNode[4], dstNode[5],
  109. dstSocket, dstSocket);
  110. }
  111. else {
  112. printf ("Usage: %s [fwd] [ [sap] | [xxxxxxxx:xxxxxxxxxxx:xxxx] ]\n", argv[0]);
  113. return 1;
  114. }
  115. }
  116. printf ("**** Starting Up...\n\n");
  117. hdl[0] = CreateEvent (NULL, // def security
  118. TRUE, // manual reset
  119. FALSE, // initially non-signaled
  120. NULL);
  121. ASSERTERRMSG ("Can't create Ipx event. ", hdl[0]!=NULL);
  122. hdl[1] = CreateEvent (NULL, // def security
  123. TRUE, // manual reset
  124. FALSE, // initially non-signaled
  125. NULL);
  126. ASSERTERRMSG ("Can't create console event. ", hdl[0]!=NULL);
  127. Stop = FALSE;
  128. status = SetConsoleCtrlHandler (
  129. &CtrlHandler,
  130. TRUE
  131. );
  132. ASSERTERRMSG ("Can't set console ctrl handler. ", status);
  133. printf ("Press CTRL+C at any time to terminate this program\n.");
  134. if (Flags & FWD_IF_TEST) {
  135. status = FwStart (257, TRUE);
  136. ASSERTMSG ("Could not start forwarder " , status==NO_ERROR);
  137. }
  138. cfgHdl = IpxCreateAdapterConfigurationPort (
  139. hdl[0],
  140. &gParam);
  141. ASSERTERRMSG ("Can't create config port. ",
  142. cfgHdl!=INVALID_HANDLE_VALUE);
  143. ASSERTMSG ("No adapters available. ", gParam.AdaptersCount>0);
  144. AdapterArr = (BOOL *)GlobalAlloc (GMEM_FIXED, sizeof (BOOL)*(gParam.AdaptersCount+1));
  145. ASSERTERRMSG ("Can't allocate adapter array. ", AdapterArr!=NULL);
  146. for (i=0; i<=gParam.AdaptersCount; i++)
  147. AdapterArr[i] = FALSE;
  148. CurAdapter = 0xFFFFFFFF;
  149. NumActiveAdapters = -1;
  150. while (!Stop) {
  151. status=WaitForMultipleObjectsEx (
  152. 2,
  153. hdl,
  154. FALSE, // Wait for any object to complete
  155. INFINITE,
  156. TRUE // Alertable wait
  157. );
  158. switch (status) {
  159. case WAIT_IO_COMPLETION:
  160. break;
  161. case WAIT_OBJECT_0:
  162. while (IpxGetQueuedAdapterConfigurationStatus (
  163. cfgHdl,
  164. &i,
  165. &adpStatus,
  166. &params)==NO_ERROR) {
  167. switch (adpStatus) {
  168. case ADAPTER_DELETED:
  169. case ADAPTER_DOWN:
  170. printf ("\n*****Adapter # %d %s.*****", i,
  171. (adpStatus==ADAPTER_DELETED)
  172. ? "deleted" : "down");
  173. if (AdapterArr[i]) {
  174. AdapterArr[i] = FALSE;
  175. printf ("\n******Stopping adapter # %d******\n\n", i);
  176. if (Flags & FWD_IF_TEST) {
  177. status = FwUnbindFwInterfaceFromAdapter (i);
  178. ASSERTMSG ("Could not unbind fwif ",
  179. status==NO_ERROR);
  180. status = FwDeleteInterface (i);
  181. ASSERTMSG ("Could not delete fwif ",
  182. status==NO_ERROR);
  183. }
  184. if (i!=0) {
  185. if (InterlockedDecrement (&NumActiveAdapters)<0) {
  186. printf ("\n******Deleting socket port******\n\n");
  187. DeleteSocketPort (sockPort);
  188. sockPort = INVALID_HANDLE_VALUE;
  189. }
  190. }
  191. }
  192. break;
  193. case ADAPTER_CREATED:
  194. case ADAPTER_UP:
  195. len = sizeof (name);
  196. status = GetAdapterNameW (i, &len, name);
  197. ASSERTMSG ("GetAdapterNameW failed ", status==NO_ERROR);
  198. printf ("\n*****Adapter # %d (%ls) %s!*****\n\n",i,name,
  199. (adpStatus==ADAPTER_CREATED)
  200. ? "created" : "up");
  201. AdapterArr[i] = TRUE;
  202. if (Flags & FWD_IF_TEST) {
  203. info.NetbiosAccept = ADMIN_STATE_ENABLED;
  204. info.NetbiosDeliver = ADMIN_STATE_ENABLED;
  205. binfo.AdapterIndex = i;
  206. IPX_NETNUM_CPY (binfo.Network, params.Network);
  207. IPX_NODENUM_CPY (binfo.LocalNode, params.LocalNode);
  208. IPX_NODENUM_CPY (binfo.RemoteNode, params.RemoteNode);
  209. binfo.MaxPacketSize = params.MaxPacketSize;
  210. binfo.LinkSpeed = params.LinkSpeed;
  211. route.RR_RoutingProtocol = 0;
  212. route.RR_InterfaceID =
  213. (params.NdisMedium==NdisMediumWan)
  214. ? params.InterfaceIndex
  215. : i;
  216. memset (&route.RR_ProtocolSpecificData,
  217. 0,
  218. sizeof (route.RR_ProtocolSpecificData));
  219. GETLONG2ULONG (&route.RR_Network.N_NetNumber,
  220. params.Network);
  221. memset (route.RR_NextHopAddress.NHA_Mac, 0, 6);
  222. route.RR_FamilySpecificData.FSD_Flags = 0;
  223. route.RR_FamilySpecificData.FSD_TickCount = 10;
  224. route.RR_FamilySpecificData.FSD_HopCount = 1;
  225. }
  226. if (i!=0) {
  227. printf ("\n******Starting adapter # %d******\n\n", i);
  228. if (Flags & FWD_IF_TEST) {
  229. status = FwCreateInterface (
  230. (params.NdisMedium==NdisMediumWan)
  231. ? params.InterfaceIndex
  232. : i,
  233. (params.NdisMedium==NdisMediumWan)
  234. ? DEMAND_DIAL
  235. : PERMANENT,
  236. &info);
  237. ASSERTMSG ("Could not create fwif ",
  238. status==NO_ERROR);
  239. FwUpdateRouteTable (RTM_ROUTE_ADDED, &route, NULL);
  240. status = FwEnableFwInterface (
  241. (params.NdisMedium==NdisMediumWan)
  242. ? params.InterfaceIndex
  243. : i);
  244. ASSERTMSG ("Could not enable fwif ",
  245. status==NO_ERROR);
  246. status = FwBindFwInterfaceToAdapter (
  247. (params.NdisMedium==NdisMediumWan)
  248. ? params.InterfaceIndex
  249. : i,
  250. &binfo);
  251. ASSERTMSG ("Could not bind fwif ",
  252. status==NO_ERROR);
  253. status = FwGetInterface (
  254. (params.NdisMedium==NdisMediumWan)
  255. ? params.InterfaceIndex
  256. : i,
  257. &info,
  258. &stats);
  259. ASSERTMSG ("Could not get fwif ",
  260. status==NO_ERROR);
  261. }
  262. if (Flags & (SAP_SOCKET_TEST|SEND_RECV_TEST)) {
  263. if (InterlockedIncrement (&NumActiveAdapters)==0) {
  264. USHORT sockNum;
  265. printf ("\n******Creating socket port******\n\n");
  266. if (Flags & SAP_SOCKET_TEST) {
  267. PUTUSHORT2SHORT (&sockNum, SAP_SOCKET_NUM);
  268. }
  269. else {
  270. PUTUSHORT2SHORT (&sockNum, dstSocket);
  271. }
  272. sockPort = CreateSocketPort (sockNum);
  273. ASSERTERR (sockPort!=INVALID_HANDLE_VALUE);
  274. recvPacket.ovrp.hEvent = NULL;
  275. status = IpxRecvPacket (sockPort,
  276. (PUCHAR)&recvPacket.hdr,
  277. sizeof(SAP_PACKET)
  278. -FIELD_OFFSET (SAP_PACKET, hdr),
  279. &recvPacket.rsvd,
  280. &recvPacket.ovrp,
  281. &RecvCompletion);
  282. ASSERTMSG ("Failed to start receive. ",
  283. status==NO_ERROR);
  284. }
  285. sendPacket = (PSAP_PACKET)GlobalAlloc (GMEM_FIXED,
  286. sizeof(SAP_PACKET));
  287. ASSERTERR (sendPacket!=NULL);
  288. PUTUSHORT2SHORT (&sendPacket->hdr.checksum,0xFFFF);
  289. PUTUSHORT2SHORT (&sendPacket->hdr.length, 34);
  290. sendPacket->hdr.transportctl = 0;
  291. sendPacket->hdr.pkttype = 0x04;
  292. if (Flags & SAP_SOCKET_TEST) {
  293. memcpy (&sendPacket->hdr.dst.net, &params.Network, 4);
  294. if (params.NdisMedium==NdisMediumWan)
  295. memcpy (sendPacket->hdr.dst.node, params.RemoteNode, 6);
  296. else
  297. memset (sendPacket->hdr.dst.node, 0xFF, 6);
  298. PUTUSHORT2SHORT (&sendPacket->hdr.dst.socket, SAP_SOCKET_NUM);
  299. }
  300. else {
  301. PUTULONG2LONG (&sendPacket->hdr.dst.net, dstNet);
  302. memcpy (sendPacket->hdr.dst.node, dstNode, 6);
  303. PUTUSHORT2SHORT (&sendPacket->hdr.dst.socket, dstSocket);
  304. }
  305. memcpy (sendPacket->hdr.src.net, params.Network, 4);
  306. memcpy (sendPacket->hdr.src.node, params.LocalNode, 6);
  307. PUTUSHORT2SHORT (&sendPacket->hdr.src.socket, SAP_SOCKET_NUM);
  308. PUTUSHORT2SHORT (&sendPacket->sap.operation, 3);
  309. PUTUSHORT2SHORT (&sendPacket->sap.entry[0].type, 0x0003);
  310. sendPacket->ovrp.hEvent = NULL;
  311. status = IpxSendPacket (sockPort,
  312. i,
  313. (PUCHAR)&sendPacket->hdr,
  314. 34,
  315. &sendPacket->rsvd,
  316. &sendPacket->ovrp,
  317. &SendCompletion);
  318. ASSERTMSG ("Failed to start send. ",
  319. status==NO_ERROR);
  320. }
  321. }
  322. else {
  323. if (Flags & FWD_IF_TEST) {
  324. status = FwCreateInterface (
  325. 0, PERMANENT, &info);
  326. ASSERTMSG ("Could not create fwif ",
  327. status==NO_ERROR);
  328. FwUpdateRouteTable (RTM_ROUTE_ADDED, &route, NULL);
  329. status = FwEnableFwInterface (
  330. (params.NdisMedium==NdisMediumWan)
  331. ? params.InterfaceIndex
  332. : i);
  333. status = FwBindFwInterfaceToAdapter (
  334. 0, &binfo);
  335. ASSERTMSG ("Could not bind fwif ",
  336. status==NO_ERROR);
  337. }
  338. }
  339. break;
  340. default:
  341. ASSERTMSG ("Unknown adapter status reported ", FALSE);
  342. }
  343. }
  344. break;
  345. }
  346. }
  347. printf ("\n\n**** Exiting with status: %lX ****\n\n", status);
  348. NumActiveAdapters = -1;
  349. if (Flags & (SAP_SOCKET_TEST|SEND_RECV_TEST)) {
  350. if (sockPort!=INVALID_HANDLE_VALUE)
  351. DeleteSocketPort (sockPort);
  352. }
  353. IpxDeleteAdapterConfigurationPort (cfgHdl);
  354. GlobalFree (AdapterArr);
  355. CloseHandle (hdl[1]);
  356. CloseHandle (hdl[0]);
  357. if (Flags & FWD_IF_TEST) {
  358. status = FwStop ();
  359. ASSERTMSG ("Could not stop forwarder ", status==NO_ERROR);
  360. }
  361. return status;
  362. }
  363. BOOL WINAPI
  364. CtrlHandler (
  365. DWORD fdwCtrlType
  366. ) {
  367. switch (fdwCtrlType) {
  368. case CTRL_C_EVENT:
  369. Stop = TRUE;
  370. SetEvent (hdl[1]);
  371. return TRUE;
  372. /* CTRL+CLOSE: confirm that the user wants to exit. */
  373. case CTRL_CLOSE_EVENT:
  374. Stop = TRUE;
  375. SetEvent (hdl[1]);
  376. return TRUE;
  377. /* Pass other signals to the next handler. */
  378. case CTRL_BREAK_EVENT:
  379. case CTRL_LOGOFF_EVENT:
  380. case CTRL_SHUTDOWN_EVENT:
  381. default:
  382. Stop = TRUE;
  383. SetEvent (hdl[1]);
  384. return FALSE;
  385. }
  386. }
  387. VOID CALLBACK
  388. SendCompletion (
  389. DWORD status,
  390. DWORD cbBytes,
  391. LPOVERLAPPED context
  392. ) {
  393. #define sendPacket ((PSAP_PACKET)context)
  394. printf ("Status : %ld\n", status);
  395. printf ("Bytes sent : %d\n", cbBytes);
  396. printf ("Checksum : %04X\n", GETSHORT2USHORTdirect(&sendPacket->hdr.checksum));
  397. printf ("Length : %d\n", GETSHORT2USHORTdirect (&sendPacket->hdr.length));
  398. printf ("Hop count : %d\n", sendPacket->hdr.transportctl);
  399. printf ("Packet type : %02X\n", sendPacket->hdr.pkttype);
  400. printf ("Dest. net : %02X%02X%02X%02X\n",
  401. sendPacket->hdr.dst.net[0],
  402. sendPacket->hdr.dst.net[1],
  403. sendPacket->hdr.dst.net[2],
  404. sendPacket->hdr.dst.net[3]);
  405. printf ("Dest. node : %02X%02X%02X%02X%02X%02X\n",
  406. sendPacket->hdr.dst.node[0],
  407. sendPacket->hdr.dst.node[1],
  408. sendPacket->hdr.dst.node[2],
  409. sendPacket->hdr.dst.node[3],
  410. sendPacket->hdr.dst.node[4],
  411. sendPacket->hdr.dst.node[5]);
  412. printf ("Dest. socket : %04X\n", GETSHORT2USHORTdirect (&sendPacket->hdr.dst.socket));
  413. printf ("Source net : %02X%02X%02X%02X\n",
  414. sendPacket->hdr.src.net[0],
  415. sendPacket->hdr.src.net[1],
  416. sendPacket->hdr.src.net[2],
  417. sendPacket->hdr.src.net[3]);
  418. printf ("Source node : %02X%02X%02X%02X%02X%02X\n",
  419. sendPacket->hdr.src.node[0],
  420. sendPacket->hdr.src.node[1],
  421. sendPacket->hdr.src.node[2],
  422. sendPacket->hdr.src.node[3],
  423. sendPacket->hdr.src.node[4],
  424. sendPacket->hdr.src.node[5]);
  425. printf ("Source socket : %04X\n", GETSHORT2USHORTdirect (&sendPacket->hdr.src.socket));
  426. printf ("\n\n");
  427. GlobalFree (sendPacket);
  428. #undef sendPacket
  429. }
  430. VOID CALLBACK
  431. RecvCompletion (
  432. DWORD status,
  433. DWORD cbBytes,
  434. LPOVERLAPPED context
  435. ) {
  436. #define recvPacket ((PSAP_PACKET)context)
  437. CurAdapter = GetNicId(&recvPacket->rsvd);
  438. if ((CurAdapter>=0)
  439. && (CurAdapter<=gParam.AdaptersCount)
  440. && AdapterArr[CurAdapter]) {
  441. printf ("Adapter # : %d\n", CurAdapter);
  442. printf ("Status : %ld\n", status);
  443. printf ("Bytes received : %d\n", cbBytes);
  444. if (cbBytes>=(DWORD)(FIELD_OFFSET (SAP_PACKET, data)
  445. -FIELD_OFFSET(SAP_PACKET,hdr))) {
  446. printf ("Checksum : %04X\n", GETSHORT2USHORTdirect(&recvPacket->hdr.checksum));
  447. printf ("Length : %d\n", GETSHORT2USHORTdirect (&recvPacket->hdr.length));
  448. printf ("Hop count : %d\n", recvPacket->hdr.transportctl);
  449. printf ("Packet type : %02X\n", recvPacket->hdr.pkttype);
  450. printf ("Dest. net : %02X%02X%02X%02X\n",
  451. recvPacket->hdr.dst.net[0],
  452. recvPacket->hdr.dst.net[1],
  453. recvPacket->hdr.dst.net[2],
  454. recvPacket->hdr.dst.net[3]);
  455. printf ("Dest. node : %02X%02X%02X%02X%02X%02X\n",
  456. recvPacket->hdr.dst.node[0],
  457. recvPacket->hdr.dst.node[1],
  458. recvPacket->hdr.dst.node[2],
  459. recvPacket->hdr.dst.node[3],
  460. recvPacket->hdr.dst.node[4],
  461. recvPacket->hdr.dst.node[5]);
  462. printf ("Dest. socket : %04X\n", GETSHORT2USHORTdirect (&recvPacket->hdr.dst.socket));
  463. printf ("Source net : %02X%02X%02X%02X\n",
  464. recvPacket->hdr.src.net[0],
  465. recvPacket->hdr.src.net[1],
  466. recvPacket->hdr.src.net[2],
  467. recvPacket->hdr.src.net[3]);
  468. printf ("Source node : %02X%02X%02X%02X%02X%02X\n",
  469. recvPacket->hdr.src.node[0],
  470. recvPacket->hdr.src.node[1],
  471. recvPacket->hdr.src.node[2],
  472. recvPacket->hdr.src.node[3],
  473. recvPacket->hdr.src.node[4],
  474. recvPacket->hdr.src.node[5]);
  475. printf ("Source socket : %04X\n", GETSHORT2USHORTdirect (&recvPacket->hdr.src.socket));
  476. if (cbBytes>=(DWORD)(FIELD_OFFSET(SAP_PACKET,sap.entry[0])
  477. -FIELD_OFFSET(SAP_PACKET,hdr))) {
  478. INT j;
  479. ULONG nbNameCount = 0;
  480. printf ("SAP Operation : %d\n", GETSHORT2USHORTdirect (&recvPacket->sap.operation));
  481. for (j=0; (j<7) && (cbBytes>=(DWORD)FIELD_OFFSET (SAP_PACKET, sap.entry[j+1])); j++) {
  482. printf ("Server type : %04X\n", GETSHORT2USHORTdirect (&recvPacket->sap.entry[j].type));
  483. printf ("Server name : %.48s\n", recvPacket->sap.entry[j].name);
  484. printf ("Server net : %02X%02X%02X%02X\n",
  485. recvPacket->sap.entry[j].addr.net[0],
  486. recvPacket->sap.entry[j].addr.net[1],
  487. recvPacket->sap.entry[j].addr.net[2],
  488. recvPacket->sap.entry[j].addr.net[3]);
  489. printf ("Server node : %02X%02X%02X%02X%02X%02X\n",
  490. recvPacket->sap.entry[j].addr.node[0],
  491. recvPacket->sap.entry[j].addr.node[1],
  492. recvPacket->sap.entry[j].addr.node[2],
  493. recvPacket->sap.entry[j].addr.node[3],
  494. recvPacket->sap.entry[j].addr.node[4],
  495. recvPacket->sap.entry[j].addr.node[5]);
  496. printf ("Server socket : %04X\n", GETSHORT2USHORTdirect (&recvPacket->sap.entry[j].addr.socket));
  497. printf ("Server hops : %d\n", GETSHORT2USHORTdirect (&recvPacket->sap.entry[j].hops));
  498. if ((Flags & FWD_IF_TEST)
  499. && (strlen (recvPacket->sap.entry[j].name)<=16)) {
  500. nbNameCount += 1;
  501. }
  502. }
  503. if ((Flags & FWD_IF_TEST) && (nbNameCount>0)) {
  504. ULONG getNameCount = 0;
  505. PIPX_STATIC_NETBIOS_NAME_INFO nmBuffer = NULL;
  506. BOOL doNbSet = FALSE;
  507. status = FwGetStaticNetbiosNames (
  508. CurAdapter,
  509. &getNameCount,
  510. NULL);
  511. ASSERTMSG ("Could not get nb name count",
  512. (status==NO_ERROR)||(status==ERROR_INSUFFICIENT_BUFFER));
  513. nmBuffer = (PIPX_STATIC_NETBIOS_NAME_INFO)GlobalAlloc (
  514. GMEM_FIXED,
  515. sizeof (IPX_STATIC_NETBIOS_NAME_INFO)
  516. *(getNameCount+nbNameCount));
  517. ASSERTMSG ("Could not allocate nb name buffer ",
  518. nmBuffer!=NULL);
  519. if (getNameCount>0) {
  520. status = FwGetStaticNetbiosNames (
  521. CurAdapter,
  522. &getNameCount,
  523. nmBuffer);
  524. ASSERTMSG ("Could not get nb names", status==NO_ERROR);
  525. }
  526. for (j=0; j<7; j++) {
  527. UINT nmLen = strlen (recvPacket->sap.entry[j].name);
  528. if (nmLen<=16) {
  529. UINT k;
  530. ULONG i;
  531. for (k=nmLen; k<16; k++)
  532. recvPacket->sap.entry[j].name[k] = ' ';
  533. for (i=0; i<getNameCount; i++) {
  534. if (memcmp (&nmBuffer[i], recvPacket->sap.entry[j].name, 16)==0)
  535. break;
  536. }
  537. if (i==getNameCount) {
  538. memcpy (&nmBuffer[getNameCount], recvPacket->sap.entry[j].name, 16);
  539. getNameCount += 1;
  540. doNbSet = TRUE;
  541. }
  542. nbNameCount -= 1;
  543. if (nbNameCount == 0)
  544. break;
  545. }
  546. }
  547. if (doNbSet) {
  548. status = FwSetStaticNetbiosNames (
  549. CurAdapter,
  550. getNameCount,
  551. nmBuffer);
  552. ASSERTMSG ("Could not get nb names", status==NO_ERROR);
  553. }
  554. }
  555. }
  556. }
  557. else
  558. printf ("**************INVALID BYTE COUNT********");
  559. printf ("\n\n");
  560. }
  561. else
  562. printf ("Adapter # : %d - ignored \n", CurAdapter);
  563. if ((NumActiveAdapters>=0) && !Stop) {
  564. status = IpxRecvPacket (sockPort,
  565. (PUCHAR)&recvPacket->hdr,
  566. sizeof(SAP_PACKET)
  567. -FIELD_OFFSET (SAP_PACKET, hdr),
  568. &recvPacket->rsvd,
  569. &recvPacket->ovrp,
  570. &RecvCompletion);
  571. ASSERTMSG ("Failed to start receive. ", status==NO_ERROR);
  572. }
  573. #undef recvPacket
  574. }