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.

1173 lines
36 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. stroutes.c
  5. Abstract:
  6. IPX Router Console Monitoring and Configuration tool.
  7. Static Route configuration and monitoring.
  8. Author:
  9. Vadim Eydelman 06/07/1996
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #define OPERATION_DEL_STATICROUTE (-1)
  14. #define OPERATION_SET_STATICROUTE 0
  15. #define OPERATION_ADD_STATICROUTE 1
  16. DWORD
  17. UpdateStRtInfo (
  18. LPBYTE pIfBlock,
  19. PUCHAR Network,
  20. PUCHAR pNextHop OPTIONAL,
  21. PUSHORT pTicks OPTIONAL,
  22. PUSHORT pHops OPTIONAL
  23. );
  24. DWORD
  25. AdmSetStRt (
  26. int operation,
  27. LPWSTR InterfaceNameW,
  28. PUCHAR Network,
  29. PUCHAR pNexHop OPTIONAL,
  30. PUSHORT pTicks OPTIONAL,
  31. PUSHORT pHops OPTIONAL
  32. );
  33. DWORD
  34. CfgSetStRt (
  35. int operation,
  36. LPWSTR InterfaceNameW,
  37. PUCHAR Network,
  38. PUCHAR pNexHop OPTIONAL,
  39. PUSHORT pTicks OPTIONAL,
  40. PUSHORT pHops OPTIONAL
  41. );
  42. int
  43. APIENTRY
  44. HelpStRt(
  45. IN int argc,
  46. IN WCHAR *argv[]
  47. )
  48. {
  49. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  50. return 0;
  51. }
  52. int
  53. APIENTRY
  54. ShowStRt(
  55. IN int argc,
  56. IN WCHAR *argv[],
  57. IN BOOL bDump
  58. )
  59. {
  60. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  61. DWORD rc, dwSize = sizeof(IfName);
  62. if (argc > 0)
  63. {
  64. unsigned count;
  65. #define InterfaceNameW argv[0]
  66. count = wcslen (InterfaceNameW);
  67. //======================================
  68. // Translate the Interface Name
  69. //======================================
  70. rc = IpmontrGetIfNameFromFriendlyName(
  71. InterfaceNameW, IfName, &dwSize
  72. );
  73. if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  74. {
  75. LPBYTE pIfBlock;
  76. BOOLEAN fRouter = FALSE;
  77. UCHAR Network[4];
  78. if (argc > 1)
  79. {
  80. ULONG val4;
  81. UINT n;
  82. if ((argc == 2)
  83. && ( swscanf (argv[1], L"%8lx%n", &val4, &n) == 1)
  84. && (n == wcslen (argv[1])))
  85. {
  86. Network[0] = (BYTE)(val4 >> 24);
  87. Network[1] = (BYTE)(val4 >> 16);
  88. Network[2] = (BYTE)(val4 >> 8);
  89. Network[3] = (BYTE)val4;
  90. }
  91. else
  92. {
  93. if ( !bDump )
  94. {
  95. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  96. }
  97. rc = ERROR_INVALID_PARAMETER;
  98. goto Exit;
  99. }
  100. }
  101. else
  102. {
  103. if ( !bDump )
  104. {
  105. DisplayIPXMessage (g_hModule, MSG_STATICROUTE_TABLE_HDR);
  106. }
  107. }
  108. if (g_hMprAdmin)
  109. {
  110. HANDLE hIfAdm;
  111. rc = MprAdminInterfaceGetHandle(
  112. g_hMprAdmin, IfName, &hIfAdm, FALSE
  113. );
  114. if (rc == NO_ERROR)
  115. {
  116. DWORD sz;
  117. rc = MprAdminInterfaceTransportGetInfo(
  118. g_hMprAdmin, hIfAdm, PID_IPX, &pIfBlock, &sz
  119. );
  120. }
  121. if (rc == NO_ERROR)
  122. {
  123. fRouter = TRUE;
  124. }
  125. else
  126. {
  127. if ( !bDump )
  128. {
  129. DisplayError( g_hModule, rc);
  130. }
  131. goto GetFromCfg;
  132. }
  133. }
  134. else
  135. {
  136. HANDLE hIfCfg;
  137. GetFromCfg:
  138. rc = MprConfigInterfaceGetHandle(
  139. g_hMprConfig, IfName, &hIfCfg
  140. );
  141. if (rc == NO_ERROR)
  142. {
  143. HANDLE hIfTrCfg;
  144. rc = MprConfigInterfaceTransportGetHandle(
  145. g_hMprConfig, hIfCfg, PID_IPX, &hIfTrCfg
  146. );
  147. if (rc == NO_ERROR)
  148. {
  149. DWORD sz;
  150. rc = MprConfigInterfaceTransportGetInfo(
  151. g_hMprConfig, hIfCfg, hIfTrCfg, &pIfBlock, &sz
  152. );
  153. }
  154. }
  155. }
  156. if (rc == NO_ERROR)
  157. {
  158. PIPX_TOC_ENTRY pSrToc;
  159. pSrToc = GetIPXTocEntry (
  160. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  161. IPX_STATIC_ROUTE_INFO_TYPE
  162. );
  163. if (pSrToc != NULL)
  164. {
  165. PIPX_STATIC_ROUTE_INFO pSrInfo;
  166. UINT i;
  167. pSrInfo = (PIPX_STATIC_ROUTE_INFO)
  168. (pIfBlock + pSrToc->Offset);
  169. for (i = 0; i < pSrToc->Count; i++, pSrInfo++)
  170. {
  171. if (argc > 1)
  172. {
  173. if (memcmp (Network, pSrInfo->Network, sizeof (Network))
  174. == 0)
  175. {
  176. DisplayIPXMessage(
  177. g_hModule,
  178. MSG_STATICROUTE_SCREEN_FMT,
  179. pSrInfo->Network[0], pSrInfo->Network[1],
  180. pSrInfo->Network[2], pSrInfo->Network[3],
  181. pSrInfo->NextHopMacAddress[0],
  182. pSrInfo->NextHopMacAddress[1],
  183. pSrInfo->NextHopMacAddress[2],
  184. pSrInfo->NextHopMacAddress[3],
  185. pSrInfo->NextHopMacAddress[4],
  186. pSrInfo->NextHopMacAddress[5],
  187. pSrInfo->TickCount, pSrInfo->HopCount
  188. );
  189. break;
  190. }
  191. }
  192. else
  193. {
  194. if ( bDump )
  195. {
  196. DisplayMessageT(
  197. DMP_IPX_ADD_STATIC_ROUTE, InterfaceNameW,
  198. pSrInfo->Network[0], pSrInfo->Network[1],
  199. pSrInfo->Network[2], pSrInfo->Network[3],
  200. pSrInfo->NextHopMacAddress[0],
  201. pSrInfo->NextHopMacAddress[1],
  202. pSrInfo->NextHopMacAddress[2],
  203. pSrInfo->NextHopMacAddress[3],
  204. pSrInfo->NextHopMacAddress[4],
  205. pSrInfo->NextHopMacAddress[5],
  206. pSrInfo->TickCount, pSrInfo->HopCount
  207. );
  208. }
  209. else
  210. {
  211. DisplayIPXMessage(
  212. g_hModule, MSG_STATICROUTE_TABLE_FMT,
  213. pSrInfo->Network[0], pSrInfo->Network[1],
  214. pSrInfo->Network[2], pSrInfo->Network[3],
  215. pSrInfo->NextHopMacAddress[0],
  216. pSrInfo->NextHopMacAddress[1],
  217. pSrInfo->NextHopMacAddress[2],
  218. pSrInfo->NextHopMacAddress[3],
  219. pSrInfo->NextHopMacAddress[4],
  220. pSrInfo->NextHopMacAddress[5],
  221. pSrInfo->TickCount, pSrInfo->HopCount
  222. );
  223. }
  224. }
  225. }
  226. if ((argc > 1) && (i >= pSrToc->Count))
  227. {
  228. rc = ERROR_NOT_FOUND;
  229. if ( !bDump )
  230. {
  231. DisplayError( g_hModule, rc );
  232. }
  233. }
  234. }
  235. else
  236. {
  237. rc = ERROR_NOT_FOUND;
  238. if ( !bDump )
  239. {
  240. DisplayIPXMessage (g_hModule, MSG_STATICROUTE_NONE_FOUND );
  241. }
  242. }
  243. if (fRouter)
  244. {
  245. MprAdminBufferFree (pIfBlock);
  246. }
  247. else
  248. {
  249. MprConfigBufferFree (pIfBlock);
  250. }
  251. }
  252. else
  253. {
  254. if ( !bDump )
  255. {
  256. DisplayError( g_hModule, rc);
  257. }
  258. }
  259. }
  260. else
  261. {
  262. if ( !bDump )
  263. {
  264. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  265. }
  266. rc = ERROR_INVALID_PARAMETER;
  267. }
  268. }
  269. else
  270. {
  271. if ( !bDump )
  272. {
  273. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  274. }
  275. rc = ERROR_INVALID_PARAMETER;
  276. }
  277. Exit:
  278. return rc ;
  279. #undef InterfaceNameW
  280. }
  281. int
  282. APIENTRY
  283. SetStRt (
  284. IN int argc,
  285. IN WCHAR *argv[]
  286. )
  287. {
  288. DWORD rc = NO_ERROR, rc2;
  289. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  290. DWORD dwSize = sizeof(IfName);
  291. if (argc > 1)
  292. {
  293. unsigned count;
  294. #define InterfaceNameW argv[0]
  295. count = wcslen (InterfaceNameW);
  296. //======================================
  297. // Translate the Interface Name
  298. //======================================
  299. rc2 = IpmontrGetIfNameFromFriendlyName(
  300. InterfaceNameW, IfName, &dwSize
  301. );
  302. if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  303. {
  304. ULONG val4;
  305. ULONGLONG val8;
  306. UINT n;
  307. UCHAR Network[4];
  308. if (( swscanf (argv[1], L"%8lx%n", &val4, &n) == 1)
  309. && (n == wcslen (argv[1])))
  310. {
  311. int i;
  312. UCHAR nextHop[6];
  313. USHORT ticks, hops;
  314. PUCHAR pNextHop = NULL;
  315. PUSHORT pTicks = NULL, pHops = NULL;
  316. Network[0] = (BYTE)(val4 >> 24);
  317. Network[1] = (BYTE)(val4 >> 16);
  318. Network[2] = (BYTE)(val4 >> 8);
  319. Network[3] = (BYTE)val4;
  320. for (i = 2; i < argc; i++)
  321. {
  322. if ( !_wcsicmp( argv[i], TOKEN_NEXTHOPMACADDRESS ) )
  323. {
  324. if ((pNextHop == NULL)
  325. && (i < argc - 1)
  326. && ( swscanf (argv[i+1], L"%12I64x%n", &val8, &n) == 1)
  327. && ( n == wcslen( argv[i+1] )))
  328. {
  329. i += 1;
  330. nextHop[0] = (BYTE)(val8 >> 40);
  331. nextHop[1] = (BYTE)(val8 >> 32);
  332. nextHop[2] = (BYTE)(val8 >> 24);
  333. nextHop[3] = (BYTE)(val8 >> 16);
  334. nextHop[4] = (BYTE)(val8 >> 8);
  335. nextHop[5] = (BYTE)val8;
  336. pNextHop = nextHop;
  337. }
  338. else
  339. {
  340. break;
  341. }
  342. }
  343. else if ( !_wcsicmp( argv[i], TOKEN_TICKS ) )
  344. {
  345. if ( (pTicks == NULL) && (i < argc - 1)
  346. && ( swscanf ( argv[i+1], L"%hd%n", &ticks, &n) == 1)
  347. && (n == wcslen (argv[i+1])))
  348. {
  349. i += 1;
  350. pTicks = &ticks;
  351. }
  352. else
  353. {
  354. break;
  355. }
  356. }
  357. else if ( !_wcsicmp ( argv[i], TOKEN_HOPS ) )
  358. {
  359. if ((pHops == NULL)
  360. && (i < argc - 1)
  361. && ( swscanf (argv[i+1], L"%hd%n", &hops, &n) == 1)
  362. && (n == wcslen (argv[i+1])))
  363. {
  364. i += 1;
  365. pHops = &hops;
  366. }
  367. else
  368. {
  369. break;
  370. }
  371. }
  372. else if (pNextHop == NULL)
  373. {
  374. if (( swscanf (argv[i], L"%12I64x%n", &val8, &n) == 1)
  375. && (n == wcslen (argv[i])))
  376. {
  377. nextHop[0] = (BYTE)(val8 >> 40);
  378. nextHop[1] = (BYTE)(val8 >> 32);
  379. nextHop[2] = (BYTE)(val8 >> 24);
  380. nextHop[3] = (BYTE)(val8 >> 16);
  381. nextHop[4] = (BYTE)(val8 >> 8);
  382. nextHop[5] = (BYTE)val8;
  383. pNextHop = nextHop;
  384. }
  385. else
  386. {
  387. break;
  388. }
  389. }
  390. else if (pTicks == NULL)
  391. {
  392. if (( swscanf (argv[i], L"%hd%n", &ticks, &n) == 1)
  393. && (n == wcslen (argv[i])))
  394. {
  395. pTicks = &ticks;
  396. }
  397. else
  398. {
  399. break;
  400. }
  401. }
  402. else if (pHops == NULL)
  403. {
  404. if (( swscanf (argv[i], L"%hd%n", &hops, &n) == 1)
  405. && (n == wcslen (argv[i])))
  406. {
  407. pHops = &hops;
  408. }
  409. else
  410. {
  411. break;
  412. }
  413. }
  414. else
  415. {
  416. break;
  417. }
  418. }
  419. if (i == argc)
  420. {
  421. if (g_hMprAdmin)
  422. {
  423. rc = AdmSetStRt(
  424. OPERATION_SET_STATICROUTE, IfName, Network,
  425. pNextHop, pTicks, pHops
  426. );
  427. }
  428. else
  429. {
  430. rc = NO_ERROR;
  431. }
  432. if (rc == NO_ERROR)
  433. {
  434. rc = CfgSetStRt(
  435. OPERATION_SET_STATICROUTE, IfName, Network,
  436. pNextHop, pTicks, pHops
  437. );
  438. }
  439. }
  440. else
  441. {
  442. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  443. }
  444. }
  445. else
  446. {
  447. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  448. }
  449. }
  450. else
  451. {
  452. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  453. rc = ERROR_INVALID_PARAMETER;
  454. }
  455. }
  456. else
  457. {
  458. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  459. rc = ERROR_INVALID_PARAMETER;
  460. }
  461. return rc ;
  462. #undef InterfaceNameW
  463. }
  464. int
  465. APIENTRY
  466. CreateStRt (
  467. IN int argc,
  468. IN WCHAR *argv[]
  469. )
  470. {
  471. DWORD rc = NO_ERROR, rc2;
  472. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  473. DWORD dwSize = sizeof(IfName);
  474. BOOL bArgsCount, //does the argument count match
  475. AdjNH, AdjTicks, AdjHops; //adjust for option names
  476. bArgsCount = FALSE;
  477. AdjNH = AdjTicks = AdjHops = 0;
  478. if (argc > 5)
  479. {
  480. if ( !_wcsicmp( argv[2], TOKEN_NEXTHOPMACADDRESS ) )
  481. {
  482. AdjNH = 1;
  483. }
  484. if (argc > 5 + AdjNH)
  485. {
  486. if ( !_wcsicmp( argv[3+AdjNH], TOKEN_TICKS ) )
  487. {
  488. AdjTicks = 1;
  489. }
  490. }
  491. if (argc > 5 + AdjNH + AdjTicks)
  492. {
  493. if ( !_wcsicmp( argv[4+AdjNH+AdjTicks], TOKEN_HOPS ) )
  494. {
  495. AdjHops = 1;
  496. }
  497. }
  498. bArgsCount = (argc == (5 + AdjNH + AdjTicks + AdjHops)) ? TRUE : FALSE;
  499. // make the adjustment cumulative
  500. AdjTicks += AdjNH;
  501. AdjHops += AdjTicks;
  502. }
  503. if ( (argc == 5) || (bArgsCount) )
  504. {
  505. unsigned count;
  506. #define InterfaceNameW argv[0]
  507. count = wcslen (InterfaceNameW);
  508. //======================================
  509. // Translate the Interface Name
  510. //======================================
  511. rc2 = IpmontrGetIfNameFromFriendlyName( InterfaceNameW, IfName, &dwSize );
  512. if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  513. {
  514. UINT n;
  515. ULONG val4;
  516. ULONGLONG val8;
  517. UCHAR Network[4], NextHop[6];
  518. USHORT Ticks, Hops;
  519. if (( swscanf (argv[1], L"%8lx%n", &val4, &n) == 1)
  520. && (n == wcslen (argv[1])))
  521. {
  522. Network[0] = (BYTE)(val4 >> 24);
  523. Network[1] = (BYTE)(val4 >> 16);
  524. Network[2] = (BYTE)(val4 >> 8);
  525. Network[3] = (BYTE)val4;
  526. if (( swscanf (argv[2+AdjNH], L"%12I64x%n", &val8, &n) == 1)
  527. && (n == wcslen (argv[2+AdjNH])))
  528. {
  529. NextHop[0] = (BYTE)(val8 >> 40);
  530. NextHop[1] = (BYTE)(val8 >> 32);
  531. NextHop[2] = (BYTE)(val8 >> 24);
  532. NextHop[3] = (BYTE)(val8 >> 16);
  533. NextHop[4] = (BYTE)(val8 >> 8);
  534. NextHop[5] = (BYTE)val8;
  535. if (( swscanf (argv[3+AdjTicks], L"%hd%n", &Ticks, &n) == 1)
  536. && (n == wcslen (argv[3+AdjTicks])))
  537. {
  538. if (( swscanf (argv[4+AdjHops], L"%hd%n", &Hops,&n) == 1)
  539. && (n == wcslen (argv[4+AdjHops])))
  540. {
  541. if (g_hMprAdmin)
  542. {
  543. rc = AdmSetStRt(
  544. OPERATION_ADD_STATICROUTE, IfName,
  545. Network, NextHop, &Ticks, &Hops
  546. );
  547. }
  548. else
  549. {
  550. rc = NO_ERROR;
  551. }
  552. if (rc == NO_ERROR)
  553. {
  554. rc = CfgSetStRt(
  555. OPERATION_ADD_STATICROUTE, IfName,
  556. Network, NextHop, &Ticks, &Hops
  557. );
  558. }
  559. }
  560. else
  561. {
  562. rc = ERROR_INVALID_PARAMETER;
  563. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  564. }
  565. }
  566. else
  567. {
  568. rc = ERROR_INVALID_PARAMETER;
  569. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  570. }
  571. }
  572. else
  573. {
  574. rc = ERROR_INVALID_PARAMETER;
  575. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  576. }
  577. }
  578. }
  579. else
  580. {
  581. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  582. rc = ERROR_INVALID_PARAMETER;
  583. }
  584. }
  585. else
  586. {
  587. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  588. rc = ERROR_INVALID_PARAMETER;
  589. }
  590. return rc ;
  591. #undef InterfaceNameW
  592. }
  593. int
  594. APIENTRY
  595. DeleteStRt(
  596. IN int argc,
  597. IN WCHAR *argv[]
  598. )
  599. {
  600. DWORD rc, rc2;
  601. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  602. DWORD dwSize = sizeof(IfName);
  603. if (argc == 2)
  604. {
  605. unsigned count;
  606. #define InterfaceNameW argv[0]
  607. count = wcslen (InterfaceNameW);
  608. //======================================
  609. // Translate the Interface Name
  610. //======================================
  611. rc2 = IpmontrGetIfNameFromFriendlyName( InterfaceNameW, IfName, &dwSize );
  612. if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  613. {
  614. UINT n;
  615. ULONG val4;
  616. UCHAR Network[4];
  617. if (( swscanf (argv[1], L"%8x%n", &val4, &n) == 1)
  618. && (n == wcslen (argv[1])))
  619. {
  620. Network[0] = (BYTE)(val4 >> 24);
  621. Network[1] = (BYTE)(val4 >> 16);
  622. Network[2] = (BYTE)(val4 >> 8);
  623. Network[3] = (BYTE)val4;
  624. if (g_hMprAdmin)
  625. {
  626. rc = AdmSetStRt(
  627. OPERATION_DEL_STATICROUTE, IfName, Network,
  628. NULL, NULL, NULL
  629. );
  630. }
  631. else
  632. {
  633. rc = NO_ERROR;
  634. }
  635. if (rc == NO_ERROR)
  636. {
  637. rc = CfgSetStRt(
  638. OPERATION_DEL_STATICROUTE, IfName, Network,
  639. NULL, NULL, NULL
  640. );
  641. }
  642. }
  643. else
  644. {
  645. rc = ERROR_INVALID_PARAMETER;
  646. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  647. }
  648. }
  649. else
  650. {
  651. rc = ERROR_INVALID_PARAMETER;
  652. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  653. }
  654. }
  655. else
  656. {
  657. rc = ERROR_INVALID_PARAMETER;
  658. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_STATICROUTE);
  659. }
  660. return rc ;
  661. #undef InterfaceNameW
  662. }
  663. BOOL
  664. StRtEqual (
  665. PVOID info1,
  666. PVOID info2
  667. )
  668. {
  669. #define StRt1 ((PIPX_STATIC_ROUTE_INFO)info1)
  670. #define StRt2 ((PIPX_STATIC_ROUTE_INFO)info2)
  671. return memcmp (StRt1->Network, StRt2->Network, 4) == 0;
  672. #undef StRt1
  673. #undef StRt2
  674. }
  675. DWORD
  676. AdmSetStRt (
  677. int operation,
  678. LPWSTR InterfaceNameW,
  679. PUCHAR Network,
  680. PUCHAR pNextHop OPTIONAL,
  681. PUSHORT pTicks OPTIONAL,
  682. PUSHORT pHops OPTIONAL
  683. )
  684. {
  685. DWORD rc;
  686. WCHAR IfDispName[ MAX_INTERFACE_NAME_LEN + 1 ];
  687. DWORD dwSize = sizeof(IfDispName);
  688. HANDLE hIfAdm;
  689. rc = MprAdminInterfaceGetHandle(
  690. g_hMprAdmin, InterfaceNameW, &hIfAdm, FALSE
  691. );
  692. if (rc == NO_ERROR)
  693. {
  694. LPBYTE pIfBlock;
  695. DWORD sz;
  696. rc = MprAdminInterfaceTransportGetInfo(
  697. g_hMprAdmin, hIfAdm, PID_IPX, &pIfBlock, &sz
  698. );
  699. if ( rc == NO_ERROR )
  700. {
  701. UINT msg;
  702. LPBYTE pNewBlock;
  703. switch (operation)
  704. {
  705. case OPERATION_SET_STATICROUTE:
  706. rc = UpdateStRtInfo(
  707. pIfBlock, Network, pNextHop, pTicks, pHops
  708. );
  709. pNewBlock = pIfBlock;
  710. msg = MSG_STATICROUTE_SET_ADM;
  711. break;
  712. case OPERATION_ADD_STATICROUTE:
  713. {
  714. IPX_STATIC_ROUTE_INFO SrInfo;
  715. memcpy (SrInfo.Network, Network, sizeof (SrInfo.Network));
  716. memcpy (SrInfo.NextHopMacAddress, pNextHop, sizeof (SrInfo.NextHopMacAddress));
  717. SrInfo.TickCount = *pTicks;
  718. SrInfo.HopCount = *pHops;
  719. rc = AddIPXInfoEntry (
  720. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  721. IPX_STATIC_ROUTE_INFO_TYPE,
  722. sizeof (SrInfo), &SrInfo, StRtEqual,
  723. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  724. );
  725. msg = MSG_STATICROUTE_CREATED_ADM;
  726. break;
  727. }
  728. case OPERATION_DEL_STATICROUTE:
  729. {
  730. IPX_STATIC_ROUTE_INFO SrInfo;
  731. memcpy (SrInfo.Network, Network, sizeof (SrInfo.Network));
  732. rc = DeleteIPXInfoEntry (
  733. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  734. IPX_STATIC_ROUTE_INFO_TYPE,
  735. sizeof (SrInfo), &SrInfo, StRtEqual,
  736. (PIPX_INFO_BLOCK_HEADER * ) &pNewBlock
  737. );
  738. msg = MSG_STATICROUTE_DELETED_ADM;
  739. break;
  740. }
  741. }
  742. if (rc == NO_ERROR)
  743. {
  744. rc = MprAdminInterfaceTransportSetInfo(
  745. g_hMprAdmin, hIfAdm, PID_IPX, pNewBlock,
  746. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size
  747. );
  748. if (pNewBlock != pIfBlock)
  749. {
  750. GlobalFree (pNewBlock);
  751. }
  752. if (rc == NO_ERROR)
  753. {
  754. DWORD rc2;
  755. //======================================
  756. // Translate the Interface Name
  757. //======================================
  758. rc2 = IpmontrGetFriendlyNameFromIfName(
  759. InterfaceNameW, IfDispName, &dwSize
  760. );
  761. if ( rc2 == NO_ERROR )
  762. {
  763. DisplayIPXMessage (g_hModule, msg, IfDispName );
  764. }
  765. }
  766. else
  767. {
  768. DisplayError( g_hModule, rc);
  769. }
  770. }
  771. else
  772. {
  773. DisplayError( g_hModule, rc);
  774. }
  775. MprAdminBufferFree (pIfBlock);
  776. }
  777. }
  778. else
  779. {
  780. DisplayError( g_hModule, rc);
  781. }
  782. return rc;
  783. }
  784. DWORD
  785. CfgSetStRt (
  786. int operation,
  787. LPWSTR InterfaceNameW,
  788. PUCHAR Network,
  789. PUCHAR pNextHop OPTIONAL,
  790. PUSHORT pTicks OPTIONAL,
  791. PUSHORT pHops OPTIONAL
  792. )
  793. {
  794. DWORD rc;
  795. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  796. DWORD dwSize = sizeof(IfName);
  797. HANDLE hIfCfg;
  798. rc = MprConfigInterfaceGetHandle(
  799. g_hMprConfig, InterfaceNameW, &hIfCfg
  800. );
  801. if (rc == NO_ERROR)
  802. {
  803. HANDLE hIfTrCfg;
  804. rc = MprConfigInterfaceTransportGetHandle(
  805. g_hMprConfig, hIfCfg, PID_IPX, &hIfTrCfg
  806. );
  807. if (rc == NO_ERROR)
  808. {
  809. LPBYTE pIfBlock;
  810. DWORD sz;
  811. LPBYTE pNewBlock;
  812. rc = MprConfigInterfaceTransportGetInfo(
  813. g_hMprConfig, hIfCfg, hIfTrCfg, &pIfBlock, &sz
  814. );
  815. if (rc == NO_ERROR)
  816. {
  817. UINT msg;
  818. switch (operation)
  819. {
  820. case OPERATION_SET_STATICROUTE:
  821. rc = UpdateStRtInfo(
  822. pIfBlock, Network, pNextHop, pTicks,
  823. pHops
  824. );
  825. pNewBlock = pIfBlock;
  826. msg = MSG_STATICROUTE_SET_CFG;
  827. break;
  828. case OPERATION_ADD_STATICROUTE:
  829. {
  830. IPX_STATIC_ROUTE_INFO SrInfo;
  831. memcpy (SrInfo.Network, Network, sizeof (SrInfo.Network));
  832. memcpy (SrInfo.NextHopMacAddress, pNextHop,
  833. sizeof (SrInfo.NextHopMacAddress));
  834. SrInfo.TickCount = *pTicks;
  835. SrInfo.HopCount = *pHops;
  836. rc = AddIPXInfoEntry (
  837. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  838. IPX_STATIC_ROUTE_INFO_TYPE,
  839. sizeof (SrInfo), &SrInfo,
  840. StRtEqual,
  841. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  842. );
  843. msg = MSG_STATICROUTE_CREATED_CFG;
  844. break;
  845. }
  846. case OPERATION_DEL_STATICROUTE:
  847. {
  848. IPX_STATIC_ROUTE_INFO SrInfo;
  849. memcpy (SrInfo.Network, Network, sizeof (SrInfo.Network));
  850. rc = DeleteIPXInfoEntry (
  851. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  852. IPX_STATIC_ROUTE_INFO_TYPE,
  853. sizeof (SrInfo), &SrInfo,
  854. StRtEqual, (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  855. );
  856. msg = MSG_STATICROUTE_DELETED_CFG;
  857. break;
  858. }
  859. }
  860. if (rc == NO_ERROR)
  861. {
  862. rc = MprConfigInterfaceTransportSetInfo(
  863. g_hMprConfig, hIfCfg, hIfTrCfg, pNewBlock,
  864. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size
  865. );
  866. if (pNewBlock != pIfBlock)
  867. {
  868. GlobalFree (pNewBlock);
  869. }
  870. if (rc == NO_ERROR)
  871. {
  872. DWORD rc2;
  873. rc2 = IpmontrGetFriendlyNameFromIfName(
  874. InterfaceNameW, IfName, &dwSize
  875. );
  876. if ( rc2 == NO_ERROR )
  877. {
  878. DisplayIPXMessage (g_hModule, msg, IfName );
  879. }
  880. }
  881. else
  882. {
  883. DisplayError( g_hModule, rc);
  884. }
  885. }
  886. else
  887. {
  888. DisplayError( g_hModule, rc);
  889. }
  890. MprConfigBufferFree (pIfBlock);
  891. }
  892. else
  893. {
  894. DisplayError( g_hModule, rc);
  895. }
  896. }
  897. else
  898. {
  899. DisplayError( g_hModule, rc);
  900. }
  901. }
  902. else
  903. {
  904. DisplayError( g_hModule, rc);
  905. }
  906. return rc;
  907. }
  908. DWORD
  909. UpdateStRtInfo (
  910. LPBYTE pIfBlock,
  911. PUCHAR Network,
  912. PUCHAR pNextHop OPTIONAL,
  913. PUSHORT pTicks OPTIONAL,
  914. PUSHORT pHops OPTIONAL
  915. )
  916. {
  917. DWORD rc;
  918. PIPX_TOC_ENTRY pSrToc;
  919. pSrToc = GetIPXTocEntry(
  920. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  921. IPX_STATIC_ROUTE_INFO_TYPE
  922. );
  923. if (pSrToc != NULL)
  924. {
  925. PIPX_STATIC_ROUTE_INFO pSrInfo;
  926. UINT i;
  927. pSrInfo = (PIPX_STATIC_ROUTE_INFO) (pIfBlock + pSrToc->Offset);
  928. for (i = 0; i < pSrToc->Count; i++, pSrInfo++)
  929. {
  930. if (memcmp (Network, pSrInfo->Network, sizeof (Network)) == 0)
  931. break;
  932. }
  933. if (i < pSrToc->Count)
  934. {
  935. if (ARGUMENT_PRESENT (pNextHop))
  936. {
  937. memcpy (pSrInfo->NextHopMacAddress, pNextHop,
  938. sizeof (pSrInfo->NextHopMacAddress));
  939. }
  940. if (ARGUMENT_PRESENT (pTicks))
  941. {
  942. pSrInfo->TickCount = *pTicks;
  943. }
  944. if (ARGUMENT_PRESENT (pHops))
  945. {
  946. pSrInfo->HopCount = *pHops;
  947. }
  948. rc = NO_ERROR;
  949. }
  950. else
  951. {
  952. rc = ERROR_FILE_NOT_FOUND;
  953. }
  954. }
  955. else
  956. {
  957. rc = ERROR_FILE_NOT_FOUND;
  958. }
  959. return rc;
  960. }