home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / lanstat / lanstat.pas < prev    next >
Pascal/Delphi Source File  |  1989-09-18  |  5KB  |  203 lines

  1. {=======================================================================}
  2. { LANSTAT    Display the results of an Adapter Status NetBIOS call    }
  3. {                                    }
  4. {    lanstat            Display status of local adapter        }
  5. {    lanstat [-p] nodename    Display status of named adapter        }
  6. {    lanstat -?        Display a usage message            }
  7. {                                    }
  8. { Issue the NetBIOS Adapter Status command, and print the values of the    }
  9. { various fields.  This command can display the status of both local    }
  10. { and remote adapters.                            }
  11. {                                    }
  12. { An Artisoft Lantastic network is assumed, only to the extent that the    }
  13. { adapter status is assumed to be in the PC Network LANA format, and    }
  14. { not the Token-Ring format, and that certain of the reserved area    }
  15. { fields are assumed to hold specific information as defined in        }
  16. { Artisoft documentation.                        }
  17. {                                    }
  18. { By default, Lanstat will return the status for the local adapter.  A    }
  19. { particular node name may be used, in which case Lanstat will return    }
  20. { the status for a (possibly) remote adapter.  If the -p option is    }
  21. { given, then upper/lower case distinctions in the node name are    }
  22. { preserved, otherwise the node name is forced to upper case.        }
  23. {=======================================================================}
  24.  
  25. program LanStat;
  26.  
  27. uses DOS, NetBios;
  28.  
  29. var
  30.     ErrCode    : byte;
  31.     NodeName    : NetName;
  32.     StatusNcb    : Ncb;
  33.     Status    : LanaStatus;
  34.  
  35. function EditArgs : boolean;
  36. var
  37.     Node  : string;
  38.     OK    : boolean;
  39.     PFlag : boolean;
  40.     I     : word;
  41. begin
  42.     OK := FALSE;
  43.     PFlag := FALSE;
  44.     case ParamCount of
  45.     0 : begin
  46.         OK := TRUE;
  47.         Node := '*';
  48.         end;
  49.     1 : if (ParamStr(1) <> '-p') and (ParamStr(1) <> '-P') and
  50.                       (ParamStr(1) <> '-?') then begin
  51.         OK := TRUE;
  52.         Node := ParamStr(1);
  53.         end;
  54.     2 : if (ParamStr(1) = '-p') or (ParamStr(1) = '-P') then begin
  55.         OK := TRUE;
  56.         PFlag := TRUE;
  57.         Node := ParamStr(2);
  58.         end;
  59.     end;
  60.     if not OK then begin
  61.     writeln('Usage: "LanStat [[-p] NodeName]" or "LanStat -?"');
  62.     writeln('Display the status of a LAN adapter');
  63.     EditArgs := FALSE;
  64.     exit;
  65.     end;
  66.     if Length(Node) > 16 then begin
  67.     writeln('NodeName too long - should be 1 to 16 characters');
  68.     EditArgs := FALSE;
  69.     exit;
  70.     end;
  71.     FillChar(NodeName, 16, ' ');
  72.     for I := 1 to Length(Node) do
  73.     if PFlag then
  74.         NodeName[I] := Node[I]
  75.     else
  76.         NodeName[I] := UpCase(Node[I]);
  77.     EditArgs := TRUE;
  78. end;
  79.  
  80. function RequestStatus : byte;
  81. begin
  82.     ClearNcb(StatusNcb);
  83.     with StatusNcb do begin
  84.     Buffer  := @Status;
  85.     Command := NBAdapterStatus;
  86.     Length  := Sizeof(Status);
  87.     RemName := NodeName;
  88.     end;
  89.     CallNetBIOS(StatusNCB);
  90.     RequestStatus := StatusNCB.RetCode;
  91. end;
  92.  
  93. procedure Display1Hex(X : byte);
  94. const
  95.     HexDigits : string[16] = '0123456789ABCDEF';
  96. begin
  97.     write(HexDigits[(X and $0F)+1]);
  98. end;
  99.  
  100. procedure Display2Hex(X : byte);
  101. begin
  102.     Display1Hex(X shr 4);
  103.     Display1Hex(X);
  104. end;
  105.  
  106. procedure DisplayNetName(Name : NetName);
  107. var
  108.     I : word;
  109.     C : char;
  110.     Graphic : boolean;
  111. begin
  112.     Graphic := FALSE;
  113.     for I := 1 to 16 do begin
  114.     C := Name[I];
  115.     if (C >= chr($20)) and (C <= chr($7E)) then begin
  116.         if NOT Graphic then begin
  117.         Graphic := TRUE;
  118.         write('"');
  119.         end;
  120.         write(C);
  121.     end else begin
  122.         if Graphic then begin
  123.         Graphic := FALSE;
  124.         write('"');
  125.         end;
  126.         if I <> 1 then
  127.         write('.');
  128.         Display2Hex(ord(C));
  129.     end;
  130.     end;
  131.     if Graphic then
  132.     write('"');
  133. end;
  134.  
  135. procedure DisplayStatus;
  136. var
  137.     I : word;
  138. begin
  139.     with Status do begin
  140.     write('Adapter Status of ');
  141.     DisplayNetName(NodeName);
  142.     writeln;
  143.  
  144.     write('NetBIOS V', SoftwareVersionMajor, '.', SoftwareVersionMinor,
  145.         '    NodeName=');
  146.     for I := 1 to 6 do begin
  147.         Display2Hex(PermanentNodeName[I]);
  148.         if I <> 6 then
  149.         write('.');
  150.     end;
  151.     writeln('    Active for ',ReportingPeriodMinutes,' minutes');
  152.  
  153.     write('Misc:     Jumpers(');
  154.     Display2Hex(ExternalJumperSetting);
  155.     write('), SelfTest(');
  156.     Display2Hex(SelfTestResults);
  157.     writeln('), MaxPacketSize(',MaximumPacketSize,')');
  158.  
  159.     { The extended fields are specific to Artisoft Lantastic }
  160.     writeln('Extended: BufUsed(',ReservedArea2[0],
  161.         '), MaxBuf(',ReservedArea2[1],
  162.         '), NoBuf(',ReservedArea1[0],
  163.         '), StolenBuf(',ReservedArea1[1],')');
  164.  
  165.     writeln('Usage:    GoodXmits(',SuccessfulXmits,
  166.         '), GoodRcvs(',SuccessfulRcvs,
  167.         '), ReXmit(',RetransmitCount,
  168.         '), Depletion(',ResourceDepletionCount,')');
  169.  
  170.     writeln('Errors:   Crc(',CrcErrorCount,
  171.         '), Alignment(',AlignmentErrors,
  172.         '), Collision(',CollisionCount,
  173.         '), XmitAbort(',XmitAbortCount,')');
  174.  
  175.     writeln('NCBs:     Free(',FreeCommandBlocks,
  176.         '), Max(',CurrentMaxNcbs,
  177.         '), HardwareMax(',HwMaxCommandBlocks,')');
  178.  
  179.     writeln('Sessions: Pending(',PendingSessionCount,
  180.         '), Max(',CurrentMaxSessions,
  181.         '), HardwareMax(',HwMaxSessionCount,')');
  182.  
  183.     writeln('Names:    Entries(',NameTableEntryCount,')');
  184.     for I := 1 to NameTableEntryCount do begin
  185.         write('           #',TableEntry[I].Num,', Status(');
  186.         Display2Hex(TableEntry[I].Status);
  187.         write('), ');
  188.         DisplayNetName(TableEntry[I].Name);
  189.         writeln;
  190.     end;
  191.     end;
  192. end;
  193.  
  194. begin
  195.     if NOT EditArgs then
  196.     exit;
  197.     ErrCode := RequestStatus;
  198.     if ErrCode <> 0 then
  199.     writeln('Request status error ',ErrCode)
  200.     else
  201.     DisplayStatus;
  202. end.
  203.