⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netinfo.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 5 页
字号:
    return (1);

  ffi2 = ffi;


  /* Look through all the AUTOEXEC.BAT files */
  while (ffi != NULL && ffi->fpNextFileInfo != NULL)
    {
      _fstrcpy (szFilePath, ffi->fpszPathToFile);


      /* OPEN file Autoexec.bat */
      fileAuto = OpenFile (szFilePath, "rb", FALSE);

      if (fileAuto == NULL)
          continue;

      /* Get lines of Autoexec file and Find LANMAN. */
      /*   If found get version & lanroot            */

      while (ReadLine (chBuffer, 80, fileAuto, FALSE) != EOF)
        {
          pCase = strupr (chBuffer);
          pBuffer = strstr (pCase, "REM ====== LANMAN ");
          if (pBuffer != NULL)
            {
              /* Make pBuffer point to major version number */
              pBuffer += 18;

              /* Get major version of LANMAN */
              iVersion = atoi (pBuffer);
              pNetInfo->wNetworkMajor = iVersion;

              /* Point to minor version of LANMAN */
              while (*pBuffer != '.' && *pBuffer != '\0')
                ++pBuffer;

              if (*pBuffer != '\0')
                ++pBuffer;

              iVersion = atoi (pBuffer);
              pNetInfo->wNetworkMinor = iVersion;

              /* get Lan Root */
              while (ReadLine (chBuffer, 80, fileAuto, FALSE) != EOF)
                {
                  pCase = strupr (chBuffer);
                  pBuffer = strstr (pCase, "REM ====== LANMAN ");
                  if (pBuffer != NULL)
                    {
                      CloseFile (fileAuto);
                      FreeFileInfo (ffi2);
                      return 1;
                    }

                  pBuffer = strstr (pCase, "SET PATH=");
                  pRem = strstr (pCase, "REM ");
                  if ((pBuffer != NULL) && (pRem == NULL))
                    {
                      pNetInfo->wNetworkType = NET_LANMAN_BASIC;
                      pBuffer += 9;
                      for (i=0; ((i < _MAX_PATH - 2) &&
                                 (*pBuffer != ';')     &&
                                 (*pBuffer != '\0')); i++)
                        {
                          pNetInfo->szLanRoot[i] = *pBuffer;
                          pBuffer += 1;
                        }

                      i--;
                      while (pNetInfo->szLanRoot[i] != '\\' && i)
                        i--;

                      pNetInfo->szLanRoot[i] = '\0';
                      CloseFile (fileAuto);
                      FreeFileInfo (ffi2);
                      return (0);
                    }
                }
            }
        }

      fclose (fileAuto);

      /* Point to the next File info structure */
      ffi = (FILE_INFO FAR *) (ffi->fpNextFileInfo);
    }

  FreeFileInfo (ffi2);
  return 1;
}


/*******************************************************************
*
* Procedure Adapter_Status
*
*     This procedure calls a net_adapter_status ncb call and a
*     netbios_session_status ncb call to get information on the
*     user's net card. The information gather is placed into the
*     NetInfo structure.
* Local Vars:
*     NCB,
*     AdapterStatus, SessionStatus are structure filled after the
*     ncb call.  NetCardNumber maintains which card is being
*     queried.  i is for the for loop on the number of netcards.
*******************************************************************/

void Adapter_Status (NETWORK_STRUCT * pNetInfo)
{
  struct Ncb     NCB;
  struct astat   AdapterStatus;
  struct sstat   SessionStatus;
  unsigned char  NetCardNumber=0;
  int            i, iSameNetID;

  ClearNcb (&NCB);
  /* loop until we run out of cards */
  for (NetCardNumber = 0;
       NCB.ncb_retcode == 0 && NetCardNumber < NUMBER_OF_CARDS;
       ++NetCardNumber)
    {
      /* setup the NCB for an adapter status call*/
      NCB.ncb_command      = NETBIOS_ADAPTER_STATUS;
      NCB.ncb_buffer       = (char far *) &AdapterStatus;
      NCB.ncb_length       = sizeof (struct astat);
      NCB.ncb_callname[0]  = '*';
      NCB.ncb_post         = 0;
      NCB.ncb_lana_num     = NetCardNumber;

      NetbiosRequest(&NCB);

      /* if the request was successfull, get the net card */
      /*   id & place it in the NetInfo struct            */
      if (NCB.ncb_retcode == 0)
        {
          iSameNetID = 0;
          for (i=0; i<LENGTH_OF_UNIT_ID; i++)
            {
              pNetInfo->ncsNets[NetCardNumber].bUnitID_Number[i] =
                  AdapterStatus.as_uid[i];

              if (NetCardNumber > 0)
                {
                  if (pNetInfo->ncsNets[NetCardNumber].bUnitID_Number[i] ==
                      pNetInfo->ncsNets[NetCardNumber-1].bUnitID_Number[i])
                    iSameNetID += 1;
                }
            }
          if (iSameNetID == LENGTH_OF_UNIT_ID)
              NCB.ncb_retcode = 1;

        }
      else
        break;

     if (NCB.ncb_retcode > 0)
       break;

      /* setup the NCB for an session status call*/
      NCB.ncb_command     = NETBIOS_SESSION_STATUS;
      NCB.ncb_buffer      = (char far *) &SessionStatus;
      NCB.ncb_length      = sizeof (struct sstat);
      NCB.ncb_callname[0] = '\0';
      NCB.ncb_name[0]     = '*';
      NCB.ncb_post        = 0;
      NCB.ncb_lana_num    = NetCardNumber;

      NetbiosRequest(&NCB);

      /* if the request was successful, place status info in the netinfo struct */
      if (NCB.ncb_retcode == 0)
        {
          if (SessionStatus.ss_numsess <= NUMBER_OF_SESSIONS)
            pNetInfo->ncsNets[NetCardNumber].bNumber_Of_Sessions =
                SessionStatus.ss_numsess;
          else
            {
              pNetInfo->ncsNets[NetCardNumber].bNumber_Of_Sessions = 0;
              SessionStatus.ss_numsess = 0;
            }

          for (i = 0; i < (int) SessionStatus.ss_numsess && 
                      i < NUMBER_OF_SESSIONS; i++)
            memcpy (pNetInfo->ncsNets[NetCardNumber].snRemoteSessionNames[i].szSessionName,
                    SessionStatus.ss_struct[i].ss_rname,16);
        }
      else
        break;

      ClearNcb (&NCB);
    }

  /* if the number of cards detected is over NUMBER_OF_CARDS, */
  /*   we have an error                                       */
  if (NetCardNumber >= NUMBER_OF_CARDS)
    NetCardNumber = 0;

  /* load netinfo with number of netcards */
  pNetInfo->wNumberOfNets = NetCardNumber;
}


/*******************************************************************
*
* Server_Connection procedure tries to establish a session with a server
* to validate the ability of the network to see into the LAN.
*
* LOCAL:
*    tbuff    - time of day buff from NetRemoteTOD
*    tod      - pointer to tbuf
*    sbuff    - hold the names of servers available from NetServerEnum
*    svr_name - holds server name from sbuff = \\name - \\ are appended
*    psrv     - pointer maps over sbuf
*    ser, ste, err - return values
*
**********************************************************************/

BOOL Server_Connection (VOID)
{
  char tbuff[sizeof (struct time_of_day_info)];
  struct time_of_day_info * tod = (struct time_of_day_info *) tbuff;
  char sbuff[BUFSIZ/4], svr_name[CNLEN+3];
  struct server_info_0 *psrv;
  unsigned short ser, ste, err;

  /* Get a list of severs from the browser. The browser maintains the list */
  err = NetServerEnum (NULL, 0, sbuff, sizeof(sbuff), &ser, &ste);

  /* Only check for 8 servers maximum. The browser table has a list of */
  /* servers we have connected to already. Since we have already connected */
  /* to these servers we just want to verify their existance. 8 is used in */
  /* in case a server has been brought down before the browser is updated. */
  /* 8 is also used because anything over this causes Beeping Death. */
  if (ser > (BUFSIZ/4))
      ser=BUFSIZ/4;

  /* if error other than more date, we exit because the enum failed */
  if ((err!=0) && (err!=ERROR_MORE_DATA))
      return (FALSE);

  /* loop through until we successfully connect to a server */
  for (psrv = (struct server_info_0 *)sbuff; ser--; ++psrv)
    {
      strcpy (svr_name, "\\\\");
      strcat (svr_name, psrv->sv0_name);

      /* this is a quick command which if successfull means we have an established connection */
      err = NetRemoteTOD (svr_name, tbuff, sizeof (tbuff));

      /* if we connected to someone, exit. Otherwise we loop until we do or until 8 servers have been processed */
      if (err==0)
        return (TRUE);
    }

  return (FALSE);
}


/*******************************************************************
*
* LAN_Basic_Enhanced proc finds out if the user is running DOS
* Enhanced or DOS Basic LAN Manager. This is done by finding a file
* that must be in the tree which is LAN Manager Specific. This is
* not a good way to do it, but it is the only way.
*
* LOCAL:
*    bufStat - return for stat command
*    path    - hold path of file needed for basic or enhanced
*
* Returns:  NET_LANMAN_BASIC    - If Basic LANMAN detected
*           NET_LANMAN_ENHANCED - If Enhanced LANMAN detected
*           NET_LANMAN          - If Basic or Enhanced could not
*                                 be determined.
**********************************************************************/

BOOL LAN_Basic_Enhanced (NETWORK_STRUCT * pNetInfo)
{
  struct stat bufStat;
  char path[_MAX_PATH];
  int err;

  /* copy (lanroot)\netprog\netwksta.exe into a buffer */
  /* this file must exist if the LAN Manager running is enhanced */
  strcpy (path, pNetInfo->szLanRoot);
  strcat (path, "\\netprog\\netwksta.exe");

  err = stat (path, &bufStat);

  /* if no error, then we have enhanced lan manager */
  if (err == 0)
    return (NET_LANMAN_ENHANCED);

  /* copy (lanroot)\basic\lanman.ini into a buffer */
  /* this file must exist if the LAN Manager running is basic */
  strcpy (path, pNetInfo->szLanRoot);
  strcat (path, "\\basic\\lanman.ini");

  err = stat (path, &bufStat);

  /* if no error, then we have basic lan manager */
  if (err == 0)
    return (NET_LANMAN_BASIC);

  return (NET_LANMAN);
}


/*******************************************************************
*
* Get_CSD_Info looks at the lanman.csd to get info about time and version
* of the csd. It does this by opening (LANROOT)\lanman.csd and parsing
* the file for info, then closing the file.
*
* Local Vars:
*     fileCSD = file pointer for open of lanman.csd
*     buffer  = for read line of lanman.csd
*     result, pbuffer = for file operations
*     CSD_Path = (lanroot)\lanman.csd
*
* Returns: TRUE if an error occured.
**********************************************************************/

int Get_CSD_Info (NETWORK_STRUCT * pNetInfo)
{
  FILE *fileCSD;
  char chBuffer[81], *pbuffer, CSD_Path[_MAX_PATH];
  INT  iResult;
  int  i;

  /* create (lanroot)\lanman.csd */
  strcpy (CSD_Path,pNetInfo->szLanRoot);
  strcat (CSD_Path, "\\Lanman.csd");

  /* OPEN (LANROOT)\lanman.csd */
  fileCSD = OpenFile (CSD_Path, "rb", FALSE);

  if (fileCSD == NULL)
      return (TRUE);

  /* Get first line of lanman.csd */
  iResult = ReadLine (chBuffer, 80, fileCSD, FALSE);

  if (iResult == EOF)
    {
      CloseFile (fileCSD);
      return (TRUE);
    }

  /* Get second line of lanman.csd */
  iResult = ReadLine (chBuffer, 80, fileCSD, FALSE);

  if (iResult == EOF)
    {
      CloseFile (fileCSD);
      return (TRUE);
    }

  /* search for ID in the line, if not there error out, if so get date */
  pbuffer = strstr (chBuffer, "ID");

  if (pbuffer == NULL)
    {
      CloseFile (fileCSD);
      return (TRUE);
    }

  /* skip to date field */
  pbuffer += 3;

  /* loop through extra zero's */
  while (*pbuffer == '0')
    ++pbuffer;

  /* copy date into netinfo */
  for (i = 0; i < 15              &&
              ((*pbuffer != '\n') &&
               (*pbuffer != '\r') &&
               (*pbuffer != '\0') &&
               (i < 6));              i++, pbuffer++)
    pNetInfo->szLanManager_Date[i] = *pbuffer;

  pNetInfo->szLanManager_Date[i] = '\0';

  /* Get third line of lanman.csd */
  iResult = ReadLine (chBuffer, 80, fileCSD, FALSE);

  if (iResult == EOF)
    {
      CloseFile (fileCSD);
      return (TRUE);
    }

  /* search for LM */
  pbuffer = strstr (chBuffer, "LM");

  /* skip to CSD field */
  pbuffer += 2;

  /* loop through extra zero's */
  while (*pbuffer == '0')
    ++pbuffer;

  /* copy current csd level into netinfo */
  for (i=0; i < 6 &&
            ((*pbuffer != '\n') &&
             (*pbuffer != '\r') &&
             (*pbuffer != '\0') &&
             (i < 6));              i++, pbuffer++)
    pNetInfo->szLanManager_CSD[i] = *pbuffer;

  pNetInfo->szLanManager_CSD[i] = '\0';

  CloseFile (fileCSD);
  return (FALSE);
}


/*******************************************************************
*
* GetLM_VersionInfo uses NetConfigGet to parse the lanman.ini which
* has release date, current patch levels and last patch levels.
* LAN Manager 2.1 has this format. Whether LM 3.0 will be this way is
* unclear.
*
* This is for Enhanced LM's. Basic can use api's and has different ini struct
*
* Local Vars:
*    err - return for NetConfigGet
*    len - for NetConfigGet
*    buf - return string of NetConfigGet
*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -