Source code of Windows XP (NT5)
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.

231 lines
5.0 KiB

  1. // Private nt headers.
  2. //
  3. //#include <nt.h>
  4. //#include <ntrtl.h>
  5. //#include <nturtl.h>
  6. #include <stdio.h>
  7. #include <tchar.h>
  8. #include <windows.h>
  9. #include <rasapip.h>
  10. #define SZ_CMD_COUNT L"count"
  11. #define SZ_CMD_ADD L"add"
  12. #define SZ_CMD_REMOVE L"remove"
  13. #define SZ_PARAM_IPOUT L"ipout="
  14. #define SZ_PARAM_NBFIN L"nbfin="
  15. #define SZ_PARAM_NBFOUT L"nbfout="
  16. typedef enum _COMMAND
  17. {
  18. CMD_INVALID = 0,
  19. CMD_COUNT,
  20. CMD_ADD,
  21. CMD_REMOVE,
  22. } COMMAND;
  23. typedef struct _OPTIONS
  24. {
  25. COMMAND Command;
  26. UINT cIpOut;
  27. UINT cNbfIn;
  28. UINT cNbfOut;
  29. } OPTIONS;
  30. VOID
  31. ExecuteCommand (
  32. IN const OPTIONS* pOptions)
  33. {
  34. HRESULT hr;
  35. UINT cIpOut, cNbfIn, cNbfOut;
  36. switch (pOptions->Command)
  37. {
  38. case CMD_COUNT:
  39. hr = RasCountBindings (
  40. &cIpOut,
  41. &cNbfIn,
  42. &cNbfOut);
  43. printf (
  44. "TCP/IP Dial-Out: %u\n"
  45. "NetBEUI Dial-In: %u\n"
  46. "NetBEUI Dial-Out: %u\n",
  47. cIpOut, cNbfIn, cNbfOut);
  48. break;
  49. case CMD_ADD:
  50. cIpOut = pOptions->cIpOut;
  51. cNbfIn = pOptions->cNbfIn;
  52. cNbfOut = pOptions->cNbfOut;
  53. hr = RasAddBindings (
  54. &cIpOut,
  55. &cNbfIn,
  56. &cNbfOut);
  57. if (SUCCEEDED(hr))
  58. {
  59. printf (
  60. "TCP/IP Dial-Out: %u\n"
  61. "NetBEUI Dial-In: %u\n"
  62. "NetBEUI Dial-Out: %u\n",
  63. cIpOut, cNbfIn, cNbfOut);
  64. }
  65. break;
  66. case CMD_REMOVE:
  67. printf ("Net yet implemented.\n");
  68. break;
  69. default:
  70. break;
  71. }
  72. }
  73. BOOL
  74. ParseCounts (
  75. IN INT argc,
  76. IN PCWSTR argv[],
  77. OUT OPTIONS* pOptions)
  78. {
  79. BOOL fRet;
  80. INT i;
  81. // We must have an even number of parameters if we have a chance
  82. // of being correct. (We're parsing 'param= value' pairs.)
  83. //
  84. if (!argc || (argc % 2 != 0))
  85. {
  86. return FALSE;
  87. }
  88. fRet = TRUE;
  89. for (i = 0; i < argc - 1; i++)
  90. {
  91. if (0 == _wcsicmp (argv[i], SZ_PARAM_IPOUT))
  92. {
  93. pOptions->cIpOut = wcstoul (argv[++i], NULL, 10);
  94. }
  95. else if (0 == _wcsicmp (argv[i], SZ_PARAM_NBFIN))
  96. {
  97. pOptions->cNbfIn = wcstoul (argv[++i], NULL, 10);
  98. }
  99. else if (0 == _wcsicmp (argv[i], SZ_PARAM_NBFOUT))
  100. {
  101. pOptions->cNbfOut = wcstoul (argv[++i], NULL, 10);
  102. }
  103. else
  104. {
  105. fRet = FALSE;
  106. }
  107. }
  108. return fRet;
  109. }
  110. VOID
  111. Usage (
  112. IN PCWSTR pszProgramName,
  113. IN COMMAND Command)
  114. {
  115. switch (Command)
  116. {
  117. case CMD_COUNT:
  118. printf (
  119. "%S count\n",
  120. pszProgramName);
  121. break;
  122. case CMD_ADD:
  123. printf (
  124. "\n"
  125. "%S add [ipout= i] [nbfin= j] [nbfout= k]\n"
  126. "\n"
  127. " add 'i' TCP/IP Dial-Out bindings\n"
  128. " 'j' NetBEUI Dial-In bindings\n"
  129. " 'k' NetBEUI Dial-Out bindings\n"
  130. "\n"
  131. " (i, j, and k all default to zero)\n"
  132. "\n",
  133. pszProgramName);
  134. break;
  135. case CMD_REMOVE:
  136. printf (
  137. "\n"
  138. "%S remove [ipout= i] [nbfin= j] [nbfout= k]\n"
  139. "\n"
  140. " remove 'i' TCP/IP Dial-Out bindings\n"
  141. " 'j' NetBEUI Dial-In bindings\n"
  142. " 'k' NetBEUI Dial-Out bindings\n"
  143. "\n"
  144. " (i, j, and k all default to zero)\n"
  145. "\n",
  146. pszProgramName);
  147. break;
  148. default:
  149. printf (
  150. "\n"
  151. "RAS Binding Configuration (shaunco)\n"
  152. " View or change RAS bindings.\n"
  153. "\n"
  154. "%S [count | add | remove]\n",
  155. pszProgramName);
  156. break;
  157. }
  158. }
  159. VOID
  160. __cdecl
  161. wmain (
  162. IN INT argc,
  163. IN PCWSTR argv[])
  164. {
  165. HRESULT hr;
  166. OPTIONS Options;
  167. ZeroMemory (&Options, sizeof(Options));
  168. Options.Command = CMD_INVALID;
  169. if (argc < 2)
  170. {
  171. Usage (argv[0], Options.Command);
  172. return;
  173. }
  174. if (0 == _wcsicmp (argv[1], SZ_CMD_COUNT))
  175. {
  176. Options.Command = CMD_COUNT;
  177. }
  178. else if (0 == _wcsicmp (argv[1], SZ_CMD_ADD))
  179. {
  180. Options.Command = CMD_ADD;
  181. if (!ParseCounts (argc-2, &argv[2], &Options))
  182. {
  183. Usage (argv[0], CMD_ADD);
  184. return;
  185. }
  186. }
  187. else if (0 == _wcsicmp (argv[1], SZ_CMD_REMOVE))
  188. {
  189. Options.Command = CMD_REMOVE;
  190. if (!ParseCounts (argc-2, &argv[2], &Options))
  191. {
  192. Usage (argv[0], CMD_REMOVE);
  193. return;
  194. }
  195. }
  196. else
  197. {
  198. Usage (argv[0], Options.Command);
  199. return;
  200. }
  201. ExecuteCommand (&Options);
  202. }