home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / ras / winnt / rassapi / admapi.c next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  42.0 KB  |  1,136 lines

  1. /******************************************************************************
  2. *       This is a part of the Microsoft Source Code Samples. 
  3. *       Copyright (C) 1992-1997 Microsoft Corporation.
  4. *       All rights reserved. 
  5. *       This sample source code is only intended as a supplement to 
  6. *       RasAdmin API usage and is meant to help user with
  7. *       RasAdmin API Calling convention. Use this code at your own risk. 
  8. *       Microsoft disclaims any implied warranty. This sample code can
  9. *       be copied and distributed.
  10.  
  11. ******************************************************************************/
  12.  
  13. /********************************************************************
  14. *  admapit.c -- Sample program demonstrating the use of different
  15. *                     RasAdmin API
  16. *                                                                    
  17. *  Comments:                                                 
  18. *                   RasAdmin expects \\Servername  as it's arguments.
  19. * RasAdminGetErrorString API returns error string. However 
  20. * this API may return an Error 87 (Invalid Parameter) for the Non 
  21. * RAS Error codes. This API is design for  only Ras related error codes. 
  22. * For more Info. check the documentation. I am using this API to for all the 
  23. * errors but I print the error codes before calling this API 
  24. *****************************************************************************/
  25. /***************************************************************************
  26. *  Functions:
  27. *      Init2(void);
  28. *      Init1(void);
  29. *      PrintGetStringError(DWORD dwResult);
  30. *      ServerGetInfo(WCHAR *RasSrv);
  31. *      PrintPriv(void);
  32. *      UserPrivilege(void);
  33. *      PrintClearStats(WCHAR * RasSrv, WCHAR *wszPortName);
  34. *      RasAdminClearDisc(LPVOID param);
  35. *****************************************************************************/
  36.  
  37.  
  38. #define sleeptime 60000
  39. #include <windows.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <stdlib.h>
  43. #include <lm.h>
  44. #include <stdio.h>
  45. #include <time.h>
  46. #include <ctype.h>
  47. #include <conio.h>
  48. #include <rassapi.h>
  49.  
  50. #include <memory.h>
  51. WCHAR*
  52. StrDupWFromA(
  53.     CHAR* psz );
  54.  
  55.  
  56. #define Number_Of_Flags 6
  57. HANDLE LogFile = NULL;
  58. HANDLE cLogFile = NULL;
  59. HANDLE ErrLogFile = NULL;
  60. VOID File_Print(RAS_PORT_1 *            pRasPort1,
  61.     RAS_PORT_STATISTICS *   pRasStats,
  62.     RAS_PARAMETERS *        pRasParams
  63. );
  64. VOID Debug_Print(RAS_PORT_1 *            pRasPort1,
  65.     RAS_PORT_STATISTICS *   pRasStats,
  66.     RAS_PARAMETERS *        pRasParams
  67. );
  68. VOID Init2(void);
  69. VOID Init1(void);
  70. VOID PrintGetStringError(DWORD dwResult);
  71. INT ServerGetInfo(WCHAR *RasSrv);
  72. VOID PrintPriv(void);
  73. VOID UserPrivilege(void);
  74. VOID PrintClearStats(WCHAR * RasSrv, WCHAR *wszPortName);
  75. DWORD WINAPI RasAdminClearDisc(LPVOID param);
  76.  
  77. PRAS_PORT_1             pRasPort1;
  78. PRAS_PORT_STATISTICS    pRasStats;
  79. RAS_PARAMETERS *        pRasParams;
  80. PRAS_SERVER_0           pRasServer0;
  81. PRAS_PORT_0             pRasPort0;
  82. RAS_PORT_1             RasPort1;
  83. RAS_PORT_STATISTICS    RasStats;
  84. RAS_SERVER_0           RasServer0;
  85.  
  86. BOOL First_Call = TRUE;
  87. DWORD Status =0;
  88. DWORD dwResult = 0;
  89. DWORD dwBytesWritten=0;
  90. CHAR szBuf[120];
  91. BOOL ErrLogInValid = FALSE;
  92. BOOL cErrLogInValid = FALSE;
  93. BOOL LogInValid = TRUE;
  94. WCHAR szUserAccountServer[UNLEN+1];
  95. PRAS_USER_0 ppRasUser0;
  96. RAS_USER_0 RasUser0;
  97. WCHAR lpszServerName[50];
  98. WCHAR RasSrv[64];
  99. BOOL Quit=FALSE;
  100. /*************************************************************************/
  101. /***************** Start Main ********************************************/
  102. /*************************************************************************/
  103.  
  104. WCHAR*
  105. StrDupWFromA(
  106.     CHAR* psz )
  107.  
  108.     /* Returns heap block containing a copy of 0-terminated string 'psz' or
  109.     ** NULL on error or if 'psz' is NULL.  The output string is converted to
  110.     ** UNICODE.  It is caller's responsibility to Free the returned string.
  111.     */
  112. {
  113.     WCHAR* pszNew = NULL;
  114.  
  115.     if (psz)
  116.     {
  117.     DWORD cb;
  118.  
  119.     cb = MultiByteToWideChar( CP_ACP, 0, psz, -1, NULL, 0 );
  120.  
  121.     pszNew = malloc( cb * sizeof(TCHAR) );
  122.     if (!pszNew)
  123.     {
  124.         return NULL;
  125.     }
  126.  
  127.     cb = MultiByteToWideChar( CP_ACP, 0, psz, -1, pszNew, cb );
  128.     if (cb == 0)
  129.     {
  130.         free( pszNew );
  131.         return NULL;
  132.     }
  133.     }
  134.  
  135.     return pszNew;
  136. }
  137.  
  138.  
  139.  
  140.  
  141. // Format and write debug information to OutputDebugString
  142. ULONG
  143. _cdecl
  144. DbgPrint(
  145.     PCH Format,
  146.     ...
  147.     )
  148. {   
  149.     CHAR szbuffer[255];
  150.     WCHAR buffer[255];
  151.     WCHAR *temp=NULL;
  152.     LPINT lpResult=0;
  153.     va_list marker;
  154.     va_start (marker,Format);
  155.     if (IsTextUnicode(Format, sizeof(Format),lpResult))
  156.     {
  157.     temp=StrDupWFromA(Format);
  158.          wvsprintfW (buffer,temp, marker);
  159.          OutputDebugString (buffer);
  160.           free(temp);
  161.     }
  162.     else
  163.     {
  164.          wvsprintfA (szbuffer,Format, marker);
  165.          temp=StrDupWFromA(szbuffer);
  166.          OutputDebugString (temp);
  167.          free(temp);
  168.          }
  169.     return TRUE;
  170. }
  171.  
  172.  
  173.  
  174.  
  175.  
  176. // Init Functions
  177. VOID Init1(void)
  178. {
  179. //Stores port  information in this file
  180. LogInValid = FALSE;
  181.          LogFile = CreateFile(TEXT("Admin.log"),
  182.                 GENERIC_READ|GENERIC_WRITE,
  183.                 FILE_SHARE_READ,
  184.                 (LPSECURITY_ATTRIBUTES) NULL,
  185.                 CREATE_ALWAYS,
  186.                 0,
  187.                    (HANDLE) NULL);
  188.          if (LogFile== INVALID_HANDLE_VALUE) {
  189.         LogInValid = TRUE;
  190.         }
  191.  
  192. }
  193. VOID Init2(void)
  194. {
  195. cErrLogInValid = FALSE;
  196. ErrLogInValid = FALSE;
  197. //Stores Statistics and port disconnect information in this file
  198.          cLogFile = CreateFile(TEXT("AdminStats.log"),
  199.                 GENERIC_READ|GENERIC_WRITE,
  200.                 FILE_SHARE_READ,
  201.                 (LPSECURITY_ATTRIBUTES) NULL,
  202.                 CREATE_ALWAYS,
  203.                 0,
  204.                    (HANDLE) NULL);
  205.          if (cLogFile== INVALID_HANDLE_VALUE) {
  206.         cErrLogInValid = TRUE;
  207.         }
  208. //Stores Privlege changes information of a user in this file
  209.          ErrLogFile = CreateFile(TEXT("AdminUser.log"),
  210.                 GENERIC_READ|GENERIC_WRITE,
  211.                 FILE_SHARE_READ,
  212.                 (LPSECURITY_ATTRIBUTES) NULL,
  213.                 CREATE_ALWAYS,
  214.                 0,
  215.                    (HANDLE) NULL);
  216.          if (ErrLogFile== INVALID_HANDLE_VALUE) {
  217.         ErrLogInValid = TRUE;
  218.         }
  219.         
  220. }
  221.  
  222. //Function to Print Error Strings
  223.  
  224. VOID PrintGetStringError(DWORD dwResult)
  225. {
  226. CHAR szBuf[120];
  227. DWORD dwBytesWritten=0;
  228.  
  229.      DbgPrint("ERROR  RasAdminGetErrorString      %d\n",dwResult);
  230.      sprintf(szBuf, "ERROR  RasAdminGetErrorString      %d\n",dwResult);     
  231.      WriteFile(LogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  232. }
  233.  
  234. // Function to get Server  Info.
  235. INT ServerGetInfo(WCHAR *RasSrv)
  236. {
  237. DWORD Status;
  238. DWORD dwResult;
  239. CHAR szBuf[120];
  240. DWORD dwBytesWritten=0;
  241. WCHAR Buf[512];
  242. WCHAR *lpszString;
  243. lpszString=&Buf[0];
  244.  
  245. // Calling RasAdminServerGetInfo 
  246. // Paramters:
  247. // IN   WCHAR * lpszServerName              //name of the RAS Server
  248. // OUT PRAS_SERVER_0 pRasServer0    // Pointer to server inf.
  249.  
  250.  
  251. Status=RasAdminServerGetInfo(RasSrv, pRasServer0);
  252. if (Status != ERROR_SUCCESS)
  253.    {
  254.     sprintf(szBuf, "ERROR RasAdminServerGetInfo   %d\n",Status);
  255.     dwResult = RasAdminGetErrorString((UINT) Status, lpszString, 512);
  256.     if (dwResult == ERROR_SUCCESS)
  257.         {
  258.         DbgPrint("ERROR  RasAdminServerGetInfo      %ws\n",lpszString);
  259.          sprintf(szBuf, "ERROR  RasAdminServerGetInfo      %ws\n",lpszString);     
  260.           WriteFile(LogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  261.         }
  262.      else
  263.         PrintGetStringError(dwResult);
  264.           return(1);
  265.    }
  266. else
  267.    {
  268.     sprintf(szBuf, "TotalPorts =  %d   PortsInUse = %d   RasVersion = %d  \n",
  269.        pRasServer0->TotalPorts, pRasServer0->PortsInUse, pRasServer0->RasVersion);     
  270.     WriteFile(LogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  271.    }
  272. return(0);
  273. }
  274.  
  275. // Function to print Privileges of a user
  276. VOID PrintPriv(void)
  277. {
  278. DWORD Permission;
  279. DWORD dwBytesWritten=0;
  280. CHAR szBuf[120];
  281.  
  282.      sprintf(szBuf,"\n User Privileges\n");
  283.      WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  284.      sprintf(szBuf,"Account Server Name= %ws     UserName= %ws\n",szUserAccountServer, pRasPort1->rasport0.wszUserName);
  285.      WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  286.      sprintf(szBuf," Priviledge   %d\n",ppRasUser0->bfPrivilege);
  287.      WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  288.      Permission = ppRasUser0->bfPrivilege - (ppRasUser0->bfPrivilege & RASPRIV_DialinPrivilege);
  289.      sprintf(szBuf,"CallBack Permission %d\n",Permission);
  290.      WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  291. }
  292.  
  293. //Function to get and change User Dialin Privileges. It goes through all the Dialin Privileges for a user.
  294.  
  295. VOID UserPrivilege(void)
  296. {
  297. DWORD dwResult;
  298. CHAR szBuf[120];
  299. DWORD dwBytesWritten=0;
  300. WCHAR Buf[512];
  301. WCHAR *lpszString;
  302. static DWORD LoopPriv=0;
  303. static BYTE Dialin=1;
  304. lpszString=&Buf[0];
  305.  
  306. // API Called:     RasAdminGetUserAccountServer
  307. // Parameters:
  308. //  IN WCHAR * lpszDomainName
  309. // IN WCHAR * lpszServerName
  310. // OUT WCHAR * lpszUserAccountServer
  311.  
  312.    if (pRasPort1->rasport0.fAdvancedServer > 0)
  313.      {
  314.       dwResult = RasAdminGetUserAccountServer(pRasPort1->rasport0.wszLogonDomain, 
  315.          NULL, &szUserAccountServer[0]);
  316.      }
  317.   else 
  318.       {  
  319.       wcscpy(lpszServerName, RasSrv);
  320.       dwResult = RasAdminGetUserAccountServer(NULL, &lpszServerName[0], &szUserAccountServer[0]);
  321.       }
  322.  
  323. // API Called:     RasAdmimUserGetInfo
  324. // Parameters:
  325. //  IN WCHAR * lpszUserAccountServer
  326. // IN WCHAR * lpszUserName
  327. // OUT RAS_USER_0 * ppRasUser0
  328.  
  329.   if (dwResult == ERROR_SUCCESS)
  330.      {
  331.      dwResult = RasAdminUserGetInfo(szUserAccountServer, pRasPort1->rasport0.wszUserName, ppRasUser0);
  332.      if (dwResult == ERROR_SUCCESS)
  333.      {
  334.       PrintPriv();
  335.      }
  336.      else
  337.     {
  338.     sprintf(szBuf,"RasAdminUserGetInfo     %d\n",dwResult);
  339.     WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  340.     dwResult = RasAdminGetErrorString((UINT) dwResult, lpszString, 512);
  341.     if (dwResult == ERROR_SUCCESS)
  342.         {
  343.         sprintf(szBuf, "ERROR  RasAdminUserGetInfo      %ws\n",lpszString);     
  344.         WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  345.         }
  346.     else
  347.         PrintGetStringError(dwResult);
  348.     }
  349.       if (LoopPriv > 3) 
  350.         {LoopPriv =0; Dialin = 1;}
  351.       if (LoopPriv < 4)
  352.      {
  353.       if (LoopPriv == 3) wcscpy(ppRasUser0->szPhoneNumber, TEXT("99999999"));
  354.       if (LoopPriv == 0) {ppRasUser0->bfPrivilege =  Dialin;Dialin = Dialin * 2;LoopPriv++;}
  355.       else {ppRasUser0->bfPrivilege = (RASPRIV_DialinPrivilege | Dialin  );
  356.         Dialin = Dialin * 2 ;
  357.         LoopPriv++;}
  358.      }
  359. // API Called:     RasAdmimUserSetInfo
  360. // Parameters:
  361. //  IN WCHAR * lpszUserAccountServer
  362. // IN WCHAR * lpszUserName
  363. // IN RAS_USER_0 * ppRasUser0
  364.       
  365.      dwResult = RasAdminUserSetInfo(szUserAccountServer, pRasPort1->rasport0.wszUserName,ppRasUser0);
  366.      if (dwResult != ERROR_SUCCESS)
  367.     {
  368.     sprintf(szBuf,"ERROR: RasAdminUserSetInfo     %d\n",dwResult);
  369.     WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  370.     dwResult = RasAdminGetErrorString((UINT) dwResult, lpszString, 512);
  371.     if (dwResult == ERROR_SUCCESS)
  372.         {
  373.          sprintf(szBuf, "ERROR  RasAdminUserSetInfo      %ws\n",lpszString);     
  374.          WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  375.         }
  376.      else
  377.         PrintGetStringError(dwResult);
  378.      }
  379. // API Called:     RasAdmimUserSetInfo
  380. // Parameters:
  381. //  IN WCHAR * lpszUserAccountServer
  382. // IN WCHAR * lpszUserName
  383. // IN RAS_USER_0 * ppRasUser0
  384.      if (LoopPriv == 0) 
  385.          {
  386.           ppRasUser0->bfPrivilege = (ppRasUser0->bfPrivilege | RASPRIV_DialinPrivilege);
  387.           dwResult = RasAdminUserSetInfo(szUserAccountServer, pRasPort1->rasport0.wszUserName, ppRasUser0);
  388.         if (dwResult == ERROR_SUCCESS)
  389.            {
  390.            PrintPriv();
  391.            }
  392.         else
  393.            {
  394.            sprintf(szBuf,"RasAdminUserSetInfo     %d\n",dwResult);
  395.            WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  396.            dwResult = RasAdminGetErrorString((UINT) dwResult, lpszString, 512);
  397.            if (dwResult == ERROR_SUCCESS)
  398.               {
  399.               sprintf(szBuf, "ERROR  RasAdminUserSetInfo      %ws\n",lpszString);     
  400.               WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  401.               }
  402.            else
  403.               PrintGetStringError(dwResult);
  404.            }
  405.          }
  406. // API Called:     RasAdmimUserGetInfo
  407. // Parameters:
  408. //  IN WCHAR * lpszUserAccountServer
  409. // IN WCHAR * lpszUserName
  410. // OUT RAS_USER_0 * ppRasUser0
  411.      dwResult = RasAdminUserGetInfo(szUserAccountServer, pRasPort1->rasport0.wszUserName, ppRasUser0);
  412.      if (dwResult != ERROR_SUCCESS)
  413.          {
  414.         sprintf(szBuf,"ERROR: RasAdminUserGetInfo     %d\n",dwResult);
  415.         WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  416.         dwResult = RasAdminGetErrorString((UINT) dwResult, lpszString, 512);
  417.         if (dwResult == ERROR_SUCCESS)
  418.            {
  419.            sprintf(szBuf, "ERROR  RasAdminUserGetInfo      %ws\n",lpszString);     
  420.            WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  421.            }
  422.         else
  423.           PrintGetStringError(dwResult);
  424.         }
  425.      }
  426.   else
  427.     {
  428.     DbgPrint("RasAdminGetUserAccountServer     %d\n",dwResult);
  429.     dwResult = RasAdminGetErrorString((UINT)dwResult, lpszString, 512);
  430.      if (dwResult == ERROR_SUCCESS)
  431.       {
  432.       sprintf(szBuf, "ERROR  RasAdminUserAccountServer      %ws\n",lpszString);     
  433.       WriteFile(ErrLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  434.       }
  435.       else
  436.      PrintGetStringError(dwResult);
  437.     }
  438.  
  439.  
  440. }
  441.  
  442. //To print port information, statistics and rasparams on debugger.
  443.  
  444. VOID Debug_Print(RAS_PORT_1 *            pRasPort1,
  445.     RAS_PORT_STATISTICS *   pRasStats,
  446.     RAS_PARAMETERS *        pRasParams
  447. )
  448. {
  449. TCHAR *Media_Name[] = {TEXT("MEDIA_UNKNOWN"),TEXT( "MEDIA_SERIAL"),
  450.           TEXT("MEDIA_RAS10_SERIAL"),TEXT( "MEDIA_ISDN")};
  451. TCHAR *Flag_Name[] = {TEXT("USER_AUTHENTICATED"),TEXT( "MESSENGER_PRESENT"),
  452.          TEXT("PPP_CLIENT"),TEXT("GATEWAY_ACTIVE"),TEXT("REMOTE_LISTEN"),TEXT("PORT_MULTILINKED")};
  453. TCHAR *Line_Condition[]={TEXT("RAS_PORT_NON_OPERATIONAL"),TEXT("RAS_PORT_DISCONNECTED"),
  454.           TEXT("RAS_PORT_CALLING_BACK"),TEXT("RAS_PORT_LISTENING"),TEXT("RAS_PORT_AUTHENTICATING"),
  455.           TEXT("RAS_PORT_AUTHENTICATED"),TEXT("RAS_PORT_INITIALIZING")};
  456. TCHAR *Hdw_Error[]={TEXT("RAS_MODEM_OPERATIONAL"),TEXT("RAS_MODEM_NOT_RESPONDING"),TEXT("RAS_MODEM_HARDWARE_FAILURE"),
  457.           TEXT("RAS_MODEM_INCORRECT_RESPONSE"),TEXT("RAS_MODEM_UNKNOWN")};
  458. INT  i=0;
  459. INT temp = 0;
  460. INT temp1 =0;
  461. DWORD dwsize=0;
  462. CHAR szBuf[100];
  463. DWORD dwBytesWritten=0;
  464.  
  465.     DbgPrint( "pRasPort1->rasport0.wszPortName=%ws\n",
  466.         pRasPort1->rasport0.wszPortName );
  467.     DbgPrint( "pRasPort1->rasport0.wszDeviceType=%ws\n",
  468.             pRasPort1->rasport0.wszDeviceType );
  469.     DbgPrint( "pRasPort1->rasport0.wszDeviceName=%ws\n",
  470.             pRasPort1->rasport0.wszDeviceName );
  471.     DbgPrint( "pRasPort1->rasport0.wszMediaName=%ws\n",
  472.         pRasPort1->rasport0.wszMediaName );
  473.     DbgPrint( "pRasPort1->rasport0.reserved=%d\n",
  474.             pRasPort1->rasport0.reserved );
  475.     DbgPrint("                 %s\n",Media_Name[pRasPort1->rasport0.reserved]);
  476.     DbgPrint( "pRasPort1->rasport0.Flags=%d\n",
  477.             pRasPort1->rasport0.Flags );
  478. //printing Flags
  479.     temp1 = 1;
  480.     for (i=0; i <= Number_Of_Flags; i++)
  481.      {
  482.      temp = (pRasPort1->rasport0.Flags & temp1);
  483.      if (temp)
  484.          {
  485.            DbgPrint("Flag       %s   \n",Flag_Name[i]);
  486.          }
  487.       temp1 = temp1*2;
  488.      }
  489.     DbgPrint( "pRasPort1->rasport0.wszUserName=%ws\n",
  490.             pRasPort1->rasport0.wszUserName );
  491.     DbgPrint( "pRasPort1->rasport0.wszComputer=%ws\n",
  492.             pRasPort1->rasport0.wszComputer );
  493.     DbgPrint( "pRasPort1->rasport0.dwStartSessionTime;=%d\n",
  494.             pRasPort1->rasport0.dwStartSessionTime );
  495.     sprintf(szBuf,"Formatted session start time/date :  %s\n",ctime(&pRasPort1->rasport0.dwStartSessionTime));
  496.     DbgPrint("%s",szBuf);
  497.     DbgPrint( "pRasPort1->rasport0.wszLogonDomain=%ws\n",
  498.             pRasPort1->rasport0.wszLogonDomain );
  499.     DbgPrint( "pRasPort1->rasport0.fAdvancedServer=%d\n",
  500.             pRasPort1->rasport0.fAdvancedServer );
  501.     DbgPrint( "pRasPort1->LineCondition=%d\n", pRasPort1->LineCondition );
  502.     DbgPrint("                     %s\n",Line_Condition[pRasPort1->LineCondition-1]);
  503.     DbgPrint( "pRasPort1->HardwareCondition=%d\n",pRasPort1->HardwareCondition);
  504.     DbgPrint("                     %s\n",Hdw_Error[pRasPort1->HardwareCondition-1]);
  505.     DbgPrint( "pRasPort1->LineSpeed=%d   bits/sec\n",pRasPort1->LineSpeed);
  506.     DbgPrint( "pRasPort1->NumStatistics=%d\n",pRasPort1->NumStatistics);
  507.     DbgPrint( "pRasPort1->NumMediaParms=%d\n",pRasPort1->NumMediaParms);
  508.     DbgPrint( "pRasPort1->SizeMediaParms=%d\n",pRasPort1->SizeMediaParms);
  509.     DbgPrint( "\npRasPort1->ProjResult.nbf.dwError=%d\n",
  510.                     pRasPort1->ProjResult.nbf.dwError );
  511.     if (pRasPort1->ProjResult.nbf.dwError == NO_ERROR)
  512.        {
  513.     DbgPrint( "pRasPort1->ProjResult.nbf.dwNetBiosError=%d\n",
  514.                 pRasPort1->ProjResult.nbf.dwNetBiosError );
  515.     DbgPrint( "pRasPort1->ProjResult.nbf.szName=%s\n", 
  516.                     pRasPort1->ProjResult.nbf.szName );
  517.     DbgPrint( "pRasPort1->ProjResult.nbf.wszWksta=%ws\n",
  518.                     pRasPort1->ProjResult.nbf.wszWksta );
  519.       }
  520.    DbgPrint( "pRasPort1->ProjResult.ip.dwError=%d\n", 
  521.                     pRasPort1->ProjResult.ip.dwError );
  522.    if (pRasPort1->ProjResult.ip.dwError == NO_ERROR)
  523.       { 
  524.     DbgPrint( "pRasPort1->ProjResult.ip.wszAddress=%ws\n",
  525.                 pRasPort1->ProjResult.ip.wszAddress );
  526.        }
  527.     DbgPrint( "pRasPort1->ProjResult.ipx.dwError=%d\n",
  528.                 pRasPort1->ProjResult.ipx.dwError );
  529.     if (pRasPort1->ProjResult.ipx.dwError == NO_ERROR)
  530.       {
  531.          DbgPrint( "pRasPort1->ProjResult.ipx.wszAddress=%ws\n",
  532.             pRasPort1->ProjResult.ipx.wszAddress );
  533.       }
  534.     DbgPrint( "pRasPort1->ProjResult.at.dwError=%d\n",
  535.                 pRasPort1->ProjResult.at.dwError );
  536.     if (pRasPort1->ProjResult.at.dwError == NO_ERROR)
  537.       {
  538.           DbgPrint( "pRasPort1->ProjResult.at.wszAddress=%ws\n",
  539.             pRasPort1->ProjResult.at.wszAddress );
  540.        }
  541.     DbgPrint( "\ndwBytesXmited=%d\n", pRasStats->dwBytesXmited );
  542.     DbgPrint( "dwBytesRcved=%d\n", pRasStats->dwBytesRcved );
  543.     DbgPrint( "dwFramesXmited=%d\n", pRasStats->dwFramesXmited );
  544.     DbgPrint( "dwFramesRcved=%d\n", pRasStats->dwFramesRcved);
  545.     DbgPrint( "dwCrcErr=%d\n", pRasStats->dwCrcErr);
  546.     DbgPrint( "dwTimeoutErr=%d\n", pRasStats->dwTimeoutErr);
  547.     DbgPrint( "dwAlignmentErr=%d\n", pRasStats->dwAlignmentErr);
  548.     DbgPrint( "dwHardwareOverrunErr=%d\n", pRasStats->dwHardwareOverrunErr);
  549.     DbgPrint( "dwFramingErr=%d\n", pRasStats->dwFramingErr);
  550.     DbgPrint( "dwBufferOverrunErr=%d\n", pRasStats->dwBufferOverrunErr);
  551.     DbgPrint( "dwBytesXmitedUncompressed=%d\n", 
  552.                     pRasStats->dwBytesXmitedUncompressed);
  553.     DbgPrint( "dwBytesRcvedUncompressed=%d\n", 
  554.                     pRasStats->dwBytesRcvedUncompressed);
  555.     DbgPrint( "dwBytesXmitedCompressed=%d\n", 
  556.                     pRasStats->dwBytesXmitedCompressed);
  557.     DbgPrint( "dwBytesRcvedCompressed=%d\n", 
  558.                     pRasStats->dwBytesRcvedCompressed);
  559.     for (i=0; i<pRasPort1->NumMediaParms;i++)
  560.       {
  561.       DbgPrint( "pRasParams->P_Key= %s\n",pRasParams[i].P_Key);
  562.       DbgPrint( "pRasParams->P_Type= %d\n",pRasParams[i].P_Type);
  563.       if (pRasParams[i].P_Type == 1)
  564.       {
  565.       DbgPrint("pRasParams->P_Value.Length=%d\n",pRasParams[i].P_Value.String.Length);
  566.       sprintf(szBuf,"                                                                \n");
  567.       strncpy(szBuf, pRasParams[i].P_Value.String.Data, pRasParams[i].P_Value.String.Length);
  568.       DbgPrint("pRasParams->P_Value.Data= %s\n",szBuf);
  569.       }
  570.       if (pRasParams[i].P_Type == 0)
  571.      {
  572.      DbgPrint("pRasParams->P_Value.Number=%d\n", pRasParams[i].P_Value.Number);
  573.      }
  574.       DbgPrint( "pRasParams->P_Attributes= %d\n",pRasParams[i].P_Attributes);
  575.       }
  576. }
  577.  
  578.  
  579. //Function to print Port Info, statistics and rasparam to a file
  580. VOID File_Print(RAS_PORT_1 *            pRasPort1,
  581.     RAS_PORT_STATISTICS *   pRasStats,
  582.     RAS_PARAMETERS *        pRasParams
  583. )
  584. {
  585. char *Media_Name[] = {"MEDIA_UNKNOWN", "MEDIA_SERIAL",
  586.           "MEDIA_RAS10_SERIAL", "MEDIA_ISDN"};
  587. char *Flag_Name[] = {"USER_AUTHENTICATED", "MESSENGER_PRESENT",
  588.          "PPP_CLIENT","GATEWAY_ACTIVE","REMOTE_LISTEN","PORT_MULTILINKED"};
  589. char *Line_Condition[]={"RAS_PORT_NON_OPERATIONAL","RAS_PORT_DISCONNECTED",
  590.           "RAS_PORT_CALLING_BACK","RAS_PORT_LISTENING","RAS_PORT_AUTHENTICATING",
  591.           "RAS_PORT_AUTHENTICATED","RAS_PORT_INITIALIZING"};
  592. char *Hdw_Error[]={"RAS_MODEM_OPERATIONAL","RAS_MODEM_NOT_RESPONDING","RAS_MODEM_HARDWARE_FAILURE",
  593.           "RAS_MODEM_INCORRECT_RESPONSE","RAS_MODEM_UNKNOWN"};
  594. INT  i=0;
  595. INT temp = 0;
  596. INT temp1 =0;
  597. DWORD dwsize=0;
  598. CHAR szBuf[50];
  599. CHAR buf[120];
  600. DWORD dwBytesWritten=0;
  601.     sprintf(buf, "pRasPort1->rasport0.wszPortName=%ws\n",
  602.         pRasPort1->rasport0.wszPortName );
  603.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  604.     sprintf(buf,"pRasPort1->rasport0.wszDeviceType=%ws\n",
  605.             pRasPort1->rasport0.wszDeviceType );
  606.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  607.     sprintf(buf,"pRasPort1->rasport0.wszDeviceName=%ws\n",
  608.             pRasPort1->rasport0.wszDeviceName );
  609.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  610.     sprintf(buf, "pRasPort1->rasport0.wszMediaName=%ws\n",
  611.         pRasPort1->rasport0.wszMediaName );
  612.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  613.     sprintf(buf,"pRasPort1->rasport0.reserved=%d\n",
  614.             pRasPort1->rasport0.reserved );
  615.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  616.     sprintf(buf,"                 %s\n",Media_Name[pRasPort1->rasport0.reserved]);
  617.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  618.     sprintf(buf, "pRasPort1->rasport0.Flags=%d\n",
  619.             pRasPort1->rasport0.Flags );
  620.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  621. //printing Flags
  622.     temp1 = 1;
  623.     for (i=0; i <= Number_Of_Flags; i++)
  624.      {
  625.      temp = (pRasPort1->rasport0.Flags & temp1);
  626.      if (temp)
  627.          {
  628.            sprintf(buf,"Flag       %s   \n",Flag_Name[i]);
  629.              WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  630.          }
  631.       temp1 = temp1*2;
  632.      }
  633.     sprintf(buf, "pRasPort1->rasport0.wszUserName=%ws\n",
  634.             pRasPort1->rasport0.wszUserName );
  635.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  636.     sprintf(buf, "pRasPort1->rasport0.wszComputer=%ws\n",
  637.             pRasPort1->rasport0.wszComputer );
  638.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  639.     sprintf(buf, "pRasPort1->rasport0.dwStartSessionTime;=%d\n",
  640.             pRasPort1->rasport0.dwStartSessionTime );
  641.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  642.     sprintf(buf,"Formatted session start time/date :  %s\n",ctime(&pRasPort1->rasport0.dwStartSessionTime));
  643.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  644.     sprintf(buf, "pRasPort1->rasport0.wszLogonDomain=%ws\n",
  645.             pRasPort1->rasport0.wszLogonDomain );
  646.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  647.     sprintf(buf, "pRasPort1->rasport0.fAdvancedServer=%d\n",
  648.             pRasPort1->rasport0.fAdvancedServer );
  649.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  650.     sprintf(buf, "pRasPort1->LineCondition=%d\n", pRasPort1->LineCondition );
  651.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  652.     sprintf(buf,"                     %s\n",Line_Condition[pRasPort1->LineCondition-1]);
  653.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  654.     sprintf(buf, "pRasPort1->HardwareCondition=%d\n",pRasPort1->HardwareCondition);
  655.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  656.     sprintf(buf,"                     %s\n",Hdw_Error[pRasPort1->HardwareCondition-1]);
  657.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  658.     sprintf(buf, "pRasPort1->LineSpeed=%d   bits/sec\n",pRasPort1->LineSpeed);
  659.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  660.     sprintf(buf, "pRasPort1->NumStatistics=%d\n",pRasPort1->NumStatistics);
  661.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  662.     sprintf(buf, "pRasPort1->NumMediaParms=%d\n",pRasPort1->NumMediaParms);
  663.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  664.     sprintf(buf, "pRasPort1->SizeMediaParms=%d\n",pRasPort1->SizeMediaParms);
  665.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  666.     sprintf(buf, "\npRasPort1->ProjResult.nbf.dwError=%d\n",
  667.                     pRasPort1->ProjResult.nbf.dwError );
  668.     if (pRasPort1->ProjResult.nbf.dwError == NO_ERROR)
  669.        {
  670.     sprintf(buf, "pRasPort1->ProjResult.nbf.dwNetBiosError=%d\n",
  671.                 pRasPort1->ProjResult.nbf.dwNetBiosError );
  672.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  673.     sprintf(buf, "pRasPort1->ProjResult.nbf.szName=%s\n", 
  674.                     pRasPort1->ProjResult.nbf.szName );
  675.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  676.     sprintf(buf, "pRasPort1->ProjResult.nbf.wszWksta=%ws\n",
  677.                     pRasPort1->ProjResult.nbf.wszWksta );
  678.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  679.       }
  680.    sprintf(buf, "pRasPort1->ProjResult.ip.dwError=%d\n", 
  681.                     pRasPort1->ProjResult.ip.dwError );
  682.    WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  683.    if (pRasPort1->ProjResult.ip.dwError == NO_ERROR)
  684.       { 
  685.     sprintf(buf, "pRasPort1->ProjResult.ip.wszAddress=%ws\n",
  686.                 pRasPort1->ProjResult.ip.wszAddress );
  687.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  688.        }
  689.     sprintf(buf, "pRasPort1->ProjResult.ipx.dwError=%d\n",
  690.                 pRasPort1->ProjResult.ipx.dwError );
  691.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  692.     if (pRasPort1->ProjResult.ipx.dwError == NO_ERROR)
  693.       {
  694.          sprintf(buf, "pRasPort1->ProjResult.ipx.wszAddress=%ws\n",
  695.             pRasPort1->ProjResult.ipx.wszAddress );
  696.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  697.       }
  698.     sprintf(buf, "pRasPort1->ProjResult.at.dwError=%d\n",
  699.                 pRasPort1->ProjResult.at.dwError );
  700.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  701.     if (pRasPort1->ProjResult.at.dwError == NO_ERROR)
  702.       {
  703.           sprintf(buf, "pRasPort1->ProjResult.at.wszAddress=%ws\n",
  704.             pRasPort1->ProjResult.at.wszAddress );
  705.        }
  706.     sprintf(buf, "\ndwBytesXmited=%d\n", pRasStats->dwBytesXmited );
  707.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  708.     sprintf(buf, "dwBytesRcved=%d\n", pRasStats->dwBytesRcved );
  709.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  710.     sprintf(buf, "dwFramesXmited=%d\n", pRasStats->dwFramesXmited );
  711.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  712.     sprintf(buf, "dwFramesRcved=%d\n", pRasStats->dwFramesRcved);
  713.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  714.     sprintf(buf, "dwCrcErr=%d\n", pRasStats->dwCrcErr);
  715.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  716.     sprintf(buf, "dwTimeoutErr=%d\n", pRasStats->dwTimeoutErr);
  717.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  718.     sprintf(buf, "dwAlignmentErr=%d\n", pRasStats->dwAlignmentErr);
  719.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  720.     sprintf(buf, "dwHardwareOverrunErr=%d\n", pRasStats->dwHardwareOverrunErr);
  721.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  722.     sprintf(buf, "dwFramingErr=%d\n", pRasStats->dwFramingErr);
  723.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  724.     sprintf(buf, "dwBufferOverrunErr=%d\n", pRasStats->dwBufferOverrunErr);
  725.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  726.     sprintf(buf, "dwBytesXmitedUncompressed=%d\n", 
  727.                     pRasStats->dwBytesXmitedUncompressed);
  728.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  729.     sprintf(buf, "dwBytesRcvedUncompressed=%d\n", 
  730.                     pRasStats->dwBytesRcvedUncompressed);
  731.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  732.     sprintf(buf, "dwBytesXmitedCompressed=%d\n", 
  733.                     pRasStats->dwBytesXmitedCompressed);
  734.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  735.     sprintf(buf, "dwBytesRcvedCompressed=%d\n", 
  736.                     pRasStats->dwBytesRcvedCompressed);
  737.     WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  738.     for (i=0; i<pRasPort1->NumMediaParms;i++)
  739.       {
  740.       sprintf(buf, "pRasParams->P_Key= %s\n",pRasParams[i].P_Key);
  741.       WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  742.       sprintf(buf, "pRasParams->P_Type= %d\n",pRasParams[i].P_Type);
  743.       WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  744.       if (pRasParams[i].P_Type == 1)
  745.       {
  746.       sprintf(buf,"pRasParams->P_Value.Length=%d\n",pRasParams[i].P_Value.String.Length);
  747.         WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  748.       sprintf(szBuf,"                                                                \n");
  749.       strncpy(szBuf, pRasParams[i].P_Value.String.Data, pRasParams[i].P_Value.String.Length);
  750.       sprintf(buf,"pRasParams->P_Value.Data= %s\n",szBuf);
  751.            WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  752.       }
  753.       if (pRasParams[i].P_Type == 0)
  754.      {
  755.      sprintf(buf,"pRasParams->P_Value.Number=%d\n", pRasParams[i].P_Value.Number);
  756.           WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  757.      }
  758.       sprintf(buf, "pRasParams->P_Attributes= %d\n",pRasParams[i].P_Attributes);
  759.       WriteFile(LogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  760.       }
  761. }
  762.  
  763. //Function to  clear port statistics.
  764.  
  765. VOID PrintClearStats(WCHAR * RasSrv, WCHAR *wszPortName)
  766. {
  767. RAS_PORT_1             RasPort1;
  768. RAS_PORT_STATISTICS    RasStats;
  769. RAS_PORT_STATISTICS    NewRasStats;
  770. RAS_PARAMETERS *        pRasParams=NULL;
  771. DWORD dwBytesWritten=0;
  772. CHAR szBuf[120];
  773. CHAR buf[120];
  774. WCHAR Buf[512];
  775. WCHAR *lpszString;
  776. lpszString=&Buf[0];
  777.  
  778. // API Called:     RasAdmimPortGetInfo
  779. // Parameters:
  780. //  IN WCHAR * lpszUserAccountServer
  781. // IN WCHAR * lpszPortName
  782. // OUT RAS_PORT_1 * pRasPort1
  783. // OUT RAS_PORT_STATISTICS * pRasPortStatistics
  784. // OUT RAS_PARAMETERS ** ppRasParams
  785.  
  786. // ppRasParams should be freed by calling RasAdminFreeBuffer
  787.  
  788. Status = RasAdminPortGetInfo ( RasSrv, wszPortName, &RasPort1, &RasStats, &pRasParams); 
  789.      if (Status != ERROR_SUCCESS)       
  790.       {
  791.       sprintf(szBuf, "ERROR RasAdminGetInfo   %d\n",Status);
  792.       WriteFile(cLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  793.       dwResult = RasAdminGetErrorString((UINT) Status, lpszString, 512);
  794.      if (dwResult == ERROR_SUCCESS)
  795.          {
  796.          DbgPrint("ERROR  RasAdminPortGetInfo      %ws\n",lpszString);
  797.          sprintf(szBuf, "ERROR  RasAdminPortGetInfo      %ws\n",lpszString);     
  798.          WriteFile(cLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  799.          }
  800.      else
  801.          PrintGetStringError(dwResult);
  802.     }
  803.      else
  804.     {
  805.  
  806. // API Called:     RasAdmimPortClearStatistics
  807. // Parameters:
  808. //  IN WCHAR * lpszServerName
  809. // IN WCHAR * lpszPortName
  810.  
  811.     Status = RasAdminPortClearStatistics(RasSrv, wszPortName);
  812.     if (Status != ERROR_SUCCESS)    
  813.       {
  814.       sprintf(szBuf, "ERROR RasAdminPortClearStatistics   %d\n",Status);
  815.       WriteFile(cLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  816.       dwResult = RasAdminGetErrorString((UINT) Status, lpszString, 512);
  817.      if (dwResult == ERROR_SUCCESS)
  818.          {
  819.          DbgPrint("ERROR  RasAdminPortClearStatistics      %ws\n",lpszString);
  820.          sprintf(szBuf, "ERROR  RasAdminPortClearStatistics      %ws\n",lpszString);     
  821.          WriteFile(cLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  822.          }
  823.      else
  824.          PrintGetStringError(dwResult);
  825.       }
  826.        else
  827.       {
  828.       if (pRasParams != NULL)
  829.         RasAdminFreeBuffer(pRasParams);
  830.  
  831.       Status = RasAdminPortGetInfo ( RasSrv, wszPortName, &RasPort1, &NewRasStats,&pRasParams); 
  832.       sprintf(buf,"Port name is   %ws\n",wszPortName);
  833.       printf("%s",buf);
  834.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  835.       sprintf(buf, "\ndwBytesXmited=%d                    new= %d\n", RasStats.dwBytesXmited,NewRasStats.dwBytesXmited );
  836.       printf("%s",buf);
  837.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  838.       sprintf(buf, "dwBytesRcved=%d                       new= %d\n", RasStats.dwBytesRcved,NewRasStats.dwBytesRcved );
  839.       printf("%s",buf);
  840.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  841.       sprintf(buf, "dwFramesXmited=%d                   new= %d\n", RasStats.dwFramesXmited, NewRasStats.dwFramesXmited );
  842.       printf("%s",buf);
  843.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  844.       sprintf(buf, "dwFramesRcved=%d                    new= %d\n", RasStats.dwFramesRcved, NewRasStats.dwFramesRcved);
  845.       printf("%s",buf);
  846.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  847.       sprintf(buf, "dwCrcErr=%d                              new= %d\n", RasStats.dwCrcErr, NewRasStats.dwCrcErr);
  848.       printf("%s",buf);
  849.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  850.       sprintf(buf, "dwTimeoutErr=%d                       new= %d\n", RasStats.dwTimeoutErr, NewRasStats.dwTimeoutErr);
  851.       printf("%s",buf);
  852.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  853.       sprintf(buf, "dwAlignmentErr=%d                  new= %d\n", RasStats.dwAlignmentErr, NewRasStats.dwAlignmentErr);
  854.       printf("%s",buf);
  855.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  856.       sprintf(buf, "dwHardwareOverrunErr=%d        new= %d\n", RasStats.dwHardwareOverrunErr, NewRasStats.dwHardwareOverrunErr);
  857.       printf("%s",buf);
  858.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  859.       sprintf(buf, "dwFramingErr=%d                     new= %d\n", RasStats.dwFramingErr, NewRasStats.dwFramingErr);
  860.       printf("%s",buf);
  861.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  862.       sprintf(buf, "dwBufferOverrunErr=%d             new= %d\n", RasStats.dwBufferOverrunErr, NewRasStats.dwBufferOverrunErr);
  863.       printf("%s",buf);
  864.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  865.       sprintf(buf, "dwBytesXmitedUncompressed=%d   new= %d\n", 
  866.                     RasStats.dwBytesXmitedUncompressed, NewRasStats.dwBytesXmitedUncompressed);
  867.       printf("%s",buf);
  868.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  869.       sprintf(buf, "dwBytesRcvedUncompressed=%d   new= %d\n", 
  870.                     RasStats.dwBytesRcvedUncompressed, NewRasStats.dwBytesRcvedUncompressed);
  871.       printf("%s",buf);
  872.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  873.       sprintf(buf, "dwBytesXmitedCompressed=%d     new= %d\n", 
  874.                     RasStats.dwBytesXmitedCompressed, NewRasStats.dwBytesXmitedCompressed);
  875.       printf("%s",buf);
  876.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  877.       sprintf(buf, "dwBytesRcvedCompressed=%d      new= %d\n", 
  878.                     RasStats.dwBytesRcvedCompressed, NewRasStats.dwBytesRcvedCompressed);
  879.       printf("%s",buf);
  880.       WriteFile(cLogFile, (LPSTR)buf, strlen(buf), &dwBytesWritten, NULL);
  881.     }
  882.      if (pRasParams != NULL)
  883.         RasAdminFreeBuffer(pRasParams);
  884.    }
  885. }
  886.  
  887. //Function to reset Port statistic
  888.  
  889. DWORD WINAPI RasAdminClearDisc(LPVOID param)
  890. {
  891. CHAR option= ' ';
  892. WORD i=0;
  893. DWORD Status=0;
  894. WORD Entries=0;
  895. DWORD PortOption = 0;
  896. RAS_PORT_0 *            pRasPort0=NULL;
  897. DWORD dwBytesWritten=0;
  898. CHAR szBuf[120];
  899. WCHAR Buf[512];
  900. WCHAR *lpszString;
  901. INT k=0;
  902. lpszString=&Buf[0];
  903. while (!Quit)
  904.   {
  905.     Status = RasAdminPortEnum( RasSrv, &pRasPort0, &Entries);
  906.     if (Status != ERROR_SUCCESS)
  907.     {
  908.     sprintf(szBuf, "ERROR RasAdminPortEnum   %d\n",Status);
  909.     dwResult = RasAdminGetErrorString((UINT) Status, lpszString, 512);
  910.     if (dwResult == ERROR_SUCCESS)
  911.         {
  912.         sprintf(szBuf,"ERROR  RasAdminPortEnum      %ws\n",lpszString);
  913.         WriteFile(cLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  914.         sprintf(szBuf, "ERROR  RasAdminPortEnum      %ws\n",lpszString);     
  915.         WriteFile(cLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  916.         }
  917.      else
  918.         PrintGetStringError(dwResult);
  919.     }
  920.     else
  921.     {
  922. // Print the configured ports on the screen and ask user to choose the port to reset the statistic or disconnect.
  923. // Right now, it lists all the ports  and lets the user pick up the port. A good idea is to let user only delete
  924. // connected ports.
  925.     printf("Select to C - Clear Statistic, D - Disconnect Port Q - Quit\n");
  926.     do
  927.              {option=_getch();
  928.                option =toupper(option);
  929.               printf("%c\n",option);}   while (((option) != 'C') && ((option) != 'D') && ((option) != 'Q'));
  930.     if (option == 'Q')
  931.        {
  932.           Quit = TRUE;
  933.          }              
  934.     if (option == 'C')
  935.        {
  936. // Print all the ports and then let user  choose the port to clear statistics
  937.      i = 0;         
  938.      while (i < Entries)
  939.           {
  940.           while ((i < Entries) && (k <=5))
  941.           {
  942. //Better to check if the port is connected here
  943.           printf(" %d=%ws",i,pRasPort0[i].wszPortName);
  944.           i++;
  945.           k++;
  946.           }
  947.           printf("\n");
  948.           k=1;
  949.           }
  950.       printf("Enter your option 0 - %d  ",Entries-1);
  951.       while ((scanf("%i",&PortOption) < 0) && (scanf("%i",&PortOption)> Entries-1))
  952.            {};
  953.  
  954.       PrintClearStats(RasSrv, pRasPort0[PortOption].wszPortName);          
  955.       }
  956.     if (option == 'D')
  957.        {
  958. // Print all the ports and then let user  choose the port to clear statistics
  959.      i = 0;         
  960.      while (i < Entries)
  961.           {
  962.           while ((i < Entries) && (k <=5))
  963.           {
  964. //better to check if the port is connected here
  965.           printf(" %d=%ws",i,pRasPort0[i].wszPortName);
  966.           i++;
  967.           k++;
  968.           }
  969.           printf("\n");
  970.           k=1;
  971.           }
  972.       printf("Enter your option 0 - %d ",Entries-1);
  973.       while ((scanf("%i",&PortOption) < 0) && (scanf("%i",&PortOption) > Entries-1))
  974.            {};
  975.  
  976. // API Called:     RasAdmimPortDisconnect
  977. // Parameters:
  978. //  IN WCHAR * lpszServerName
  979. // IN WCHAR * lpszPortName
  980.  
  981.       Status = RasAdminPortDisconnect(RasSrv, pRasPort0[PortOption].wszPortName);
  982.     if (Status != ERROR_SUCCESS)
  983.     {
  984.     sprintf(szBuf, "ERROR RasAdminPortDisconnect   %d\n",Status);
  985.     dwResult = RasAdminGetErrorString((UINT) Status, lpszString, 512);
  986.     if (dwResult == ERROR_SUCCESS)
  987.         {
  988.         sprintf(szBuf,"ERROR  RasAdminPortDisconnect      %ws\n",lpszString);
  989.         WriteFile(cLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  990.         sprintf(szBuf, "ERROR  RasAdminPortDisconnect      %ws\n",lpszString);     
  991.         WriteFile(cLogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  992.         }
  993.      else
  994.         PrintGetStringError(dwResult);
  995.     }
  996.     else
  997.     {
  998.     printf("Port Disconnected successfully\n");
  999.     }
  1000.      }
  1001.    }
  1002.  if (pRasPort0 != NULL)
  1003.      RasAdminFreeBuffer(pRasPort0);
  1004.   }
  1005. return(0);
  1006. }
  1007.  
  1008. void _cdecl main(int argc, char **argv)
  1009. {
  1010. INT LoopPriv=0;
  1011. INT Error = 0;
  1012. CHAR szBuf[120];
  1013. DWORD dwBytesWritten=0;
  1014. DWORD Dialin = 1;
  1015. WCHAR Buf[512];
  1016. WCHAR *lpszString;
  1017. WORD Entries;
  1018. WORD i=0;
  1019. DWORD id=0;
  1020. HANDLE ConnectDiscThread;
  1021. lpszString=&Buf[0];
  1022. pRasPort1 = &RasPort1;
  1023. pRasStats = &RasStats;
  1024. pRasServer0 = &RasServer0;
  1025. ppRasUser0 = &RasUser0;
  1026. if (argc > 1)
  1027.     {
  1028.     mbstowcs(RasSrv, argv[1], 32) ;
  1029.     }
  1030. else
  1031.     {
  1032.     printf ("to start type Admapit \\\\RasServerName\n");
  1033.     exit(0);
  1034.     }
  1035. Init1();
  1036. Init2();
  1037. Error=ServerGetInfo(RasSrv);
  1038. if (Error)
  1039.     {
  1040.     printf ("Ras Server is not started on the system");
  1041.     exit(0);
  1042.     }
  1043.     ConnectDiscThread = CreateThread (NULL,
  1044.                      0,
  1045.             &RasAdminClearDisc,
  1046.                    (LPVOID) id,
  1047.                      0,
  1048.                        &id);
  1049.  
  1050. while (!Quit)
  1051.   {
  1052. // API Called:     RasAdmimPortEnum
  1053. // Parameters:
  1054. //  IN WCHAR * lpszServerName
  1055. // OUT PRAS_PORT_0 *  ppRasPort0
  1056. // OUT WORD *  pcEntriesRead
  1057.  
  1058. // Free up ppRasPort0 by calling RasAdminFreeBuffer API
  1059.  
  1060.     Status = RasAdminPortEnum( RasSrv, &pRasPort0, &Entries);
  1061.     if (Status != ERROR_SUCCESS)
  1062.     {
  1063.     sprintf(szBuf, "ERROR RasAdminPortEnum   %d\n",Status);
  1064.           WriteFile(LogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  1065.     dwResult = RasAdminGetErrorString((UINT) Status, lpszString, 512);
  1066.     if (dwResult == ERROR_SUCCESS)
  1067.         {
  1068.         sprintf(szBuf,"ERROR  RasAdminPortEnum      %ws\n",lpszString);
  1069.         WriteFile(LogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  1070.         sprintf(szBuf, "ERROR  RasAdminPortEnum      %ws\n",lpszString);     
  1071.         WriteFile(LogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  1072.         }
  1073.      else
  1074.         PrintGetStringError(dwResult);
  1075.     }
  1076.     else
  1077.     {
  1078. //A good idea is to check for port Authentication before making this call
  1079.     for (i=0; i<Entries; i++)
  1080.          {
  1081. // API Called:     RasAdmimPortGetInfo
  1082. // Parameters:
  1083. //  IN WCHAR * lpszUserAccountServer
  1084. // IN WCHAR * lpszPortName
  1085. // OUT RAS_PORT_1 * pRasPort1
  1086. // OUT RAS_PORT_STATISTICS * pRasPortStatistics
  1087. // OUT RAS_PARAMETERS ** ppRasParams
  1088.  
  1089. // ppRasParams should be freed by calling RasAdminFreeBuffer
  1090.  
  1091.          Status = RasAdminPortGetInfo ( RasSrv, pRasPort0[i].wszPortName, pRasPort1, pRasStats, &pRasParams); 
  1092.          if (Status != ERROR_SUCCESS)       
  1093.         {
  1094.          sprintf(szBuf, "ERROR RasAdminGetInfo   %d\n",Status);
  1095.          WriteFile(LogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  1096.          dwResult = RasAdminGetErrorString((UINT) Status, lpszString, 512);
  1097.          if (dwResult == ERROR_SUCCESS)
  1098.              {
  1099.              DbgPrint("ERROR  RasAdminPortGetInfo      %ws\n",lpszString);
  1100.              sprintf(szBuf, "ERROR  RasAdminPortGetInfo      %ws\n",lpszString);     
  1101.              WriteFile(LogFile, (LPSTR)szBuf, strlen(szBuf), &dwBytesWritten, NULL);
  1102.              }
  1103.          else
  1104.             PrintGetStringError(dwResult);
  1105.         }
  1106.          else
  1107.         {
  1108.          File_Print(pRasPort1, pRasStats, pRasParams);
  1109.                  Debug_Print(pRasPort1, pRasStats, pRasParams);
  1110.         }
  1111. //Call user privilege API only if the user is connected, or you provide the user name. If you pass NULL for all the paramters to user priv API's then the API
  1112. // will hit an Assert
  1113.            if ( pRasPort1->LineCondition == RAS_PORT_AUTHENTICATED)
  1114.                  UserPrivilege();
  1115.          if (pRasParams != NULL) {
  1116.             RasAdminFreeBuffer(pRasParams);
  1117.             }
  1118.          }//End Loop
  1119.     } 
  1120.      CloseHandle(LogFile);
  1121.      if (pRasPort0 != NULL)
  1122.         RasAdminFreeBuffer(pRasPort0);
  1123.      Sleep(sleeptime);
  1124.      Init1();
  1125.      ServerGetInfo(RasSrv);
  1126.   } 
  1127.  
  1128.       WaitForSingleObject(ConnectDiscThread,INFINITE);
  1129. CloseHandle(LogFile);
  1130. CloseHandle(cLogFile);
  1131. CloseHandle(ErrLogFile);
  1132.  
  1133.   
  1134.  
  1135. } // Main End
  1136.