home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sources / misc / 4244 < prev    next >
Encoding:
Text File  |  1993-01-10  |  50.3 KB  |  1,626 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: amber@engin.umich.edu (Lee Liming)
  4. Subject: v34i102:  netuse - A Network Host Usage Monitoring System, Part04/06
  5. Message-ID: <1993Jan11.023756.25510@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: e0dcd4684308d55878127b720773193e
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v34i099=netuse.203327@sparky.IMD.Sterling.COM>
  11. Date: Mon, 11 Jan 1993 02:37:56 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 1611
  14.  
  15. Submitted-by: amber@engin.umich.edu (Lee Liming)
  16. Posting-number: Volume 34, Issue 102
  17. Archive-name: netuse/part04
  18. Environment: UNIX, MS-DOS, OS/2, INET, MSC
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then feed it
  22. # into a shell via "sh file" or similar.  To overwrite existing files,
  23. # type "sh file -c".
  24. # Contents:  netuse/clients/netuseadmin.c netuse/daemons/caenlab.c
  25. #   netuse/daemons/getload.c netuse/lib/netuse.h netuse/lib/parser.c
  26. #   netuse/lib/protocol.h
  27. # Wrapped by kent@sparky on Sun Jan 10 20:28:36 1993
  28. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  29. echo If this archive is complete, you will see the following message:
  30. echo '          "shar: End of archive 4 (of 6)."'
  31. if test -f 'netuse/clients/netuseadmin.c' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'netuse/clients/netuseadmin.c'\"
  33. else
  34.   echo shar: Extracting \"'netuse/clients/netuseadmin.c'\" \(6994 characters\)
  35.   sed "s/^X//" >'netuse/clients/netuseadmin.c' <<'END_OF_FILE'
  36. X/******************************************************************************
  37. X NETUSEADMIN.C - NETUSE Network Monitoring System Administrative Client
  38. X
  39. X This program provides a user interface to the remote NETUSE server, allowing
  40. X various opertaions to be made on the host database.
  41. X
  42. X Lee Liming, The Computer Aided Engineering Network
  43. X The University of Michigan
  44. X
  45. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  46. X
  47. X User agrees to reproduce said copyright notice on all copies of the software
  48. X made by the recipient.  
  49. X
  50. X All Rights Reserved. Permission is hereby granted for the recipient to make
  51. X copies and use this software for its own internal purposes only. Recipient of
  52. X this software may re-distribute this software outside of their own
  53. X institution. Permission to market this software commercially, to include this
  54. X product as part of a commercial product, or to make a derivative work for
  55. X commercial purposes, is explicitly prohibited.  All other uses are also
  56. X prohibited unless authorized in writing by the Regents of the University of
  57. X Michigan.
  58. X
  59. X This software is offered without warranty. The Regents of the University of
  60. X Michigan disclaim all warranties, express or implied, including but not
  61. X limited to the implied warranties of merchantability and fitness for any
  62. X particular purpose. In no event shall the Regents of the University of
  63. X Michigan be liable for loss or damage of any kind, including but not limited
  64. X to incidental, indirect, consequential, or special damages. 
  65. X******************************************************************************/
  66. X
  67. X#include <stdio.h>
  68. X#include <netuse.h>
  69. X#include <parser.h>
  70. X
  71. X
  72. X#ifdef __STDC__
  73. Xint get_command(char *buf)
  74. X#else
  75. Xint get_command(buf)
  76. Xchar *buf;
  77. X#endif
  78. X{
  79. X     printf("\nnetuseadmin> ");
  80. X     gets(buf);
  81. X     return(0);
  82. X}
  83. X
  84. X
  85. X#ifdef __STDC__
  86. Xvoid display_help(void)
  87. X#else
  88. Xvoid display_help()
  89. X#endif
  90. X{
  91. X     printf("\nCommands:\n\n");
  92. X     printf("add       <vendor> <hostname> <model>  Add a new host to the database.\n");
  93. X     printf("delete    <hostname>           Delete a host from the database.\n");
  94. X     printf("list      [<vendor>]           List all hosts (or hosts from a given vendor)\n");
  95. X     printf("reload                         Load hosts from NETUSE hostfile.\n");
  96. X     printf("savestate                      Store host list in NETUSE hostfile.\n");
  97. X     printf("use       <filename>           Read additional commands from a file.\n");
  98. X     printf("\n?,help                         Display this help text.\n");
  99. X     printf("exit,quit                      Exit the program.\n");
  100. X     printf("\nVendor designations are currently 'dec', 'sun', 'apollo', 'hp', and 'ibm'.\n");
  101. X     printf("Hostnames may be either internet hostnames or IP addresses in standard format.\n");
  102. X     printf("All commands and arguments EXCEPT hostnames are case-insensitive.\n");
  103. X}
  104. X
  105. X
  106. X#ifdef __STDC__
  107. Xint execute_command(char *cstr)
  108. X#else
  109. Xint execute_command(cstr)
  110. Xchar *cstr;
  111. X#endif
  112. X{
  113. X     char command[128],buf[256];
  114. X     int mtype,modtype,mode,rv;
  115. X     FILE *inf;
  116. X
  117. X     strcpy(buf,cstr);
  118. X     stoupper(strip(strip_leading(buf)));
  119. X     if (!strlen(buf)) return(0);
  120. X     if (!strcmp(textparam(buf,0,command),"QUIT") || !strcmp(command,"EXIT"))
  121. X          return(1);
  122. X     if (!strcmp(command,"?") || !strcmp(command,"HELP")) {
  123. X          display_help();
  124. X          return(0);
  125. X     }
  126. X     if (!strcmp(command,"SAVESTATE")) {
  127. X          if (!netuseSaveState()) printf("Host database has been stored.\n");
  128. X          else printf("An error occurred while storing the database.\n");
  129. X          return(0);
  130. X     }
  131. X     if (!strcmp(command,"RELOAD")) {
  132. X          if (!netuseLoadHosts()) printf("Host database has been reloaded.\n");
  133. X          else printf("An error occurred while loading the database.\n");
  134. X          return(0);
  135. X     }
  136. X     if (!strcmp(command,"DELETE")) {
  137. X          if (!strlen(textparam(cstr,1,command))) {
  138. X               printf("Missing hostname.  Use ? to view the command list.\n");
  139. X               return(0);
  140. X          }
  141. X          if (!netuseDelName(command)) printf("Delete command successful.\n");
  142. X          else printf("An error occurred during the delete operation.\n");
  143. X          return(0);
  144. X     }
  145. X     if (!strcmp(command,"ADD")) {
  146. X          if (!strlen(textparam(cstr,1,command))) {
  147. X               printf("Missing vendor type.  Use ? to view the command list.\n");
  148. X               return(0);
  149. X          }
  150. X          if (!(mtype=netStrToMach(command))) {
  151. X               printf("Invalid vendor type.  Vendors are DEC, IBM, Apollo, HP, and Sun.\n");
  152. X               return(0);
  153. X          }
  154. X          if (!strlen(textparam(cstr,3,command))) {
  155. X               printf("Missing model type.  Use ? to view the command list.\n");
  156. X               return(0);
  157. X          }
  158. X          if (!(modtype=netStrToModel(command))) {
  159. X               printf("Invalid model type.\n");
  160. X               return(0);
  161. X          }
  162. X          if (!strlen(textparam(cstr,2,command))) {
  163. X               printf("Missing hostname.  Use ? to view the command list.\n");
  164. X               return(0);
  165. X          }
  166. X          if (!(rv=netuseAddName(command,mtype,modtype))) 
  167. X               printf("Add command successful.\n");
  168. X          else printf("Error %d occurred during the add operation.\n",rv);
  169. X          return(0);
  170. X     }
  171. X     if (!strcmp(command,"USE")) {
  172. X          if (!strlen(textparam(cstr,1,command))) {
  173. X               printf("Missing filename.  Use ? to view the command list.\n");
  174. X               return(0);
  175. X          }
  176. X          if ((inf=fopen(command,"r"))==NULL) {
  177. X               printf("Unable to open %s for input.  USE command aborted...\n");
  178. X               return(0);
  179. X          }
  180. X          printf("\n");
  181. X          mtype=0;
  182. X          while (fgets(buf,sizeof(buf),inf) && !mtype) {
  183. X               buf[strlen(buf)-1]='\0';
  184. X               if (!strlen(buf) || (buf[0]=='#')) continue;
  185. X               printf("Executing: \"%s\"...\n",buf);
  186. X               mtype=execute_command(buf);
  187. X          }
  188. X          close(inf);
  189. X          return(0);
  190. X     }
  191. X     if (!strcmp(command,"LIST")) {
  192. X          mtype=0; mode=MODE_ALL;
  193. X          if (strlen(textparam(cstr,1,command))) {
  194. X               if (!(mtype=netStrToMach(command))) {
  195. X                    printf("Valid vendor types are DEC, IBM, Apollo, HP, and Sun.\n");
  196. X                    return(0);
  197. X               }
  198. X          }
  199. X          if (netuseGetList(mtype,0,mode)) {
  200. X               printf("Unable to display host list.\n");
  201. X               return(0);
  202. X          }
  203. X          return(0);
  204. X     }
  205. X     printf("\nType \"?\" or \"help\" to receive a list of valid commands.\n");
  206. X     return(0);
  207. X}
  208. X
  209. X
  210. X#ifdef __STDC__
  211. Xmain(int argc,char *argv[])
  212. X#else
  213. Xmain(argc,argv)
  214. Xint argc;
  215. Xchar *argv[];
  216. X#endif
  217. X{
  218. X     char command[256];
  219. X     int done;
  220. X
  221. X     printf("\nNETUSE Administration Command Interpretor\n");
  222. X     netSetup();
  223. X     do {
  224. X          get_command(command);
  225. X          if (!feof(stdin)) done=execute_command(command);
  226. X     } while (!done && !feof(stdin));
  227. X     putchar('\n');
  228. X     netShutdown();
  229. X}
  230. END_OF_FILE
  231.   if test 6994 -ne `wc -c <'netuse/clients/netuseadmin.c'`; then
  232.     echo shar: \"'netuse/clients/netuseadmin.c'\" unpacked with wrong size!
  233.   fi
  234.   # end of 'netuse/clients/netuseadmin.c'
  235. fi
  236. if test -f 'netuse/daemons/caenlab.c' -a "${1}" != "-c" ; then 
  237.   echo shar: Will not clobber existing file \"'netuse/daemons/caenlab.c'\"
  238. else
  239.   echo shar: Extracting \"'netuse/daemons/caenlab.c'\" \(6849 characters\)
  240.   sed "s/^X//" >'netuse/daemons/caenlab.c' <<'END_OF_FILE'
  241. X/******************************************************************************
  242. X CAENLAB.C - CAEN-specific heuristics for telling netused whether to run or 
  243. X             to quit.
  244. X
  245. X At CAEN, we have a file called /etc/hostconfig on all non-Apollo
  246. X workstations.  If this file contains a line of the form "CLASS=LAB" in it, it
  247. X means that the machine is in a public CAEN lab.  Apollos have a config file
  248. X of a more complex format with similar information in it.
  249. X
  250. X We only run netused on lab machines, so this module contains code to tell
  251. X netused whether it's supposed to run or not on this workstation.
  252. X
  253. X To enable this code, the macro USE_CAENLAB must be defined in 
  254. X ../lib/config.h.
  255. X
  256. X Lee Liming and Michael Neil, The Computer Aided Engineering Network
  257. X The University of Michigan
  258. X
  259. X Copyright (C) 1992 by the Regents of the University of Michigan.
  260. X
  261. X User agrees to reproduce said copyright notice on all copies of the software
  262. X made by the recipient.  
  263. X
  264. X All Rights Reserved. Permission is hereby granted for the recipient to make
  265. X copies and use this software for its own internal purposes only. Recipient of
  266. X this software may re-distribute this software outside of their own
  267. X institution. Permission to market this software commercially, to include this
  268. X product as part of a commercial product, or to make a derivative work for
  269. X commercial purposes, is explicitly prohibited.  All other uses are also
  270. X prohibited unless authorized in writing by the Regents of the University of
  271. X Michigan.
  272. X
  273. X This software is offered without warranty. The Regents of the University of
  274. X Michigan disclaim all warranties, express or implied, including but not
  275. X limited to the implied warranties of merchantability and fitness for any
  276. X particular purpose. In no event shall the Regents of the University of
  277. X Michigan be liable for loss or damage of any kind, including but not limited
  278. X to incidental, indirect, consequential, or special damages. 
  279. X******************************************************************************/
  280. X
  281. X#include <stdio.h>
  282. X#include <ctype.h>
  283. X#include <sys/types.h>
  284. X#include <sys/stat.h>
  285. X#include <string.h>
  286. X#include "../lib/parser.h"
  287. X#include "caenlab.h"
  288. X
  289. X
  290. X#define CONFIGFILE     "/sys/node_data/etc/config"
  291. X#define HOSTCONFIGFILE "/etc/hostconfig"
  292. X
  293. X
  294. X#ifdef __STDC__
  295. Xchar *getfield(char *buf,int start,int stop,char *field)
  296. X#else
  297. Xchar *getfield(buf,start,stop,field)
  298. Xchar *buf;
  299. Xint start,stop;
  300. Xchar *field;
  301. X#endif
  302. X{
  303. X     --start;
  304. X     --stop;
  305. X     if (strlen(buf)<(start+1)) field[0]='\0';
  306. X     else {
  307. X          strncpy(field,buf+start,(stop-start+1));
  308. X          field[stop-start+1]='\0';
  309. X     }
  310. X     strip(field);
  311. X     return(field);
  312. X}
  313. X
  314. X
  315. X#ifdef __STDC__
  316. Xchar *pwGetField(char *pwline,int n,char *buf)
  317. X#else
  318. Xchar *pwGetField(pwline,n,buf)
  319. Xchar *pwline;
  320. Xint n;
  321. Xchar *buf;
  322. X#endif
  323. X{
  324. X     int i;
  325. X     char *p,*q;
  326. X
  327. X     p=pwline;
  328. X     for (i=0; (i<n) && (*p!='\0'); p++) 
  329. X          if (*p==':') i++;
  330. X     for (q=buf; (*p!=':') && (*p!='\0'); )
  331. X          *(q++)=(*(p++));
  332. X     *q='\0';
  333. X     return(buf);
  334. X}
  335. X
  336. X
  337. Xchar *stolower(in)
  338. Xchar *in;
  339. X{
  340. X     char *p;
  341. X
  342. X     for (p=in; *p!='\0'; p++)
  343. X          if (isupper(*p)) *p=tolower(*p);
  344. X}
  345. X
  346. X
  347. X#ifdef __STDC__
  348. Xint apolloShouldRun(void)
  349. X#else
  350. Xint apolloShouldRun()
  351. X#endif
  352. X{
  353. X     struct stat buf;
  354. X     int nameStart,nameEnd;
  355. X     int restStart,restEnd;
  356. X     int gotem,searchfield,print,theanswer;
  357. X     char name[20],rest[25];
  358. X     char inbuf[512],temp[256],*p,hostname[128];
  359. X     FILE *inf;
  360. X     
  361. X     theanswer=0;
  362. X     gethostname(hostname,sizeof(hostname));
  363. X     if ((p=strchr(hostname,'.'))!=NULL) *p='\0';
  364. X     if (stat(CONFIGFILE,&buf)) {
  365. X#ifdef TESTING
  366. X          printf("Apollo config file does not exist!\n");
  367. X#else
  368. X          logit("Apollo config file does not exist!");
  369. X#endif
  370. X          exit(1);
  371. X     }
  372. X     if ((inf=fopen(CONFIGFILE,"r"))==NULL) {
  373. X#ifdef TESTING
  374. X          printf("Unable to open the Apollo config file.\n");
  375. X#else
  376. X          logit("Unable to open the Apollo config file.");
  377. X#endif
  378. X          exit(1);
  379. X     }
  380. X     gotem=0;
  381. X     while (fgets(inbuf,sizeof(inbuf),inf)!=NULL) {
  382. X          if (!strlen(inbuf)) continue;
  383. X          inbuf[strlen(inbuf)]='\0';
  384. X          if (gotem<2) {
  385. X               if (!strncmp(inbuf,"#|<var> NODENAME",16)) {
  386. X                    nameStart=atoi(textparam(inbuf,2,temp));
  387. X                    nameEnd=atoi(textparam(inbuf,3,temp));
  388. X                    ++gotem;
  389. X               }
  390. X               if (!strncmp(inbuf,"#|<var> RESTRICTION",19)) {
  391. X                    restStart=atoi(textparam(inbuf,2,temp));
  392. X                    restEnd=atoi(textparam(inbuf,3,temp));
  393. X                    ++gotem;
  394. X               }
  395. X          }
  396. X          else {
  397. X               if ((inbuf[0]=='#') || !strlen(inbuf)) continue;
  398. X               print=0;
  399. X               getfield(inbuf,nameStart,nameEnd,name);
  400. X               for (p=name; (*p!='\0') && (*p=='/'); p++)
  401. X                    ;
  402. X               strcpy(name,p);
  403. X               stolower(name);
  404. X               getfield(inbuf,restStart,restEnd,rest);
  405. X               if (!strcmp(hostname,name) && !strcmp(rest,"L")) theanswer=1;
  406. X          }
  407. X     }
  408. X     if (gotem<2) {
  409. X#ifdef TESTING
  410. X          printf("Error in Apollo config file.\n");
  411. X#else
  412. X          logit("Error in Apollo config file.");
  413. X#endif
  414. X          exit(1);
  415. X     }
  416. X     fclose(inf);
  417. X     return(theanswer);
  418. X}
  419. X
  420. X
  421. X#ifdef __STDC__
  422. Xint hostconfigShouldRun(void)
  423. X#else
  424. Xint hostconfigShouldRun()
  425. X#endif
  426. X{
  427. X     char inbuf[132],*p,temp[132];
  428. X     FILE *inf;
  429. X     int theanswer,i;
  430. X     struct stat buf;
  431. X     
  432. X     theanswer=0;
  433. X     if (stat(HOSTCONFIGFILE,&buf)) {
  434. X#ifdef TESTING
  435. X          printf("hostconfig file does not exist!\n");
  436. X#else
  437. X          logit("hostconfig file does not exist!");
  438. X#endif
  439. X          exit(1);
  440. X     }
  441. X     if ((inf=fopen(HOSTCONFIGFILE,"r"))==NULL) {
  442. X#ifdef TESTING
  443. X          printf("Unable to open the hostconfig file.\n");
  444. X#else
  445. X          logit("Unable to open the hostconfig file.");
  446. X#endif
  447. X          exit(1);
  448. X     }
  449. X     while (fgets(inbuf,sizeof(inbuf),inf)!=NULL) {
  450. X          if (!strlen(inbuf)) continue;
  451. X          inbuf[strlen(inbuf)-1]='\0';
  452. X          if (!(p=strchr(inbuf,'='))) continue;
  453. X          *p='\0'; ++p;
  454. X          strip(strip_leading(inbuf));
  455. X          strip(strip_leading(p));
  456. X#ifdef TESTING
  457. X          printf("inbuf=\"%s\", p=\"%s\".\n",inbuf,p);
  458. X#endif
  459. X          if (!strcmp(inbuf,"CLASS")) {
  460. X               for (i=0; strlen(pwGetField(p,i,temp)) && !theanswer; i++)
  461. X                    if (!strcmp(temp,"LAB")) theanswer=1;
  462. X               break;
  463. X          }
  464. X     }
  465. X     fclose(inf);
  466. X     return(theanswer);
  467. X}
  468. X
  469. X
  470. X#ifdef __STDC__
  471. Xint netusedShouldRun(void)
  472. X#else
  473. Xint netusedShouldRun()
  474. X#endif
  475. X{
  476. X#ifdef apollo
  477. X     return(apolloShouldRun());
  478. X#else
  479. X     return(hostconfigShouldRun());
  480. X#endif
  481. X}
  482. X
  483. X
  484. X#ifdef TESTING
  485. X
  486. X/* Test program for verifying functionality */
  487. X
  488. Xmain()
  489. X{
  490. X     printf("netusedShouldRun() returns %d.\n",netusedShouldRun());
  491. X}
  492. X
  493. X
  494. X#endif
  495. END_OF_FILE
  496.   if test 6849 -ne `wc -c <'netuse/daemons/caenlab.c'`; then
  497.     echo shar: \"'netuse/daemons/caenlab.c'\" unpacked with wrong size!
  498.   fi
  499.   # end of 'netuse/daemons/caenlab.c'
  500. fi
  501. if test -f 'netuse/daemons/getload.c' -a "${1}" != "-c" ; then 
  502.   echo shar: Will not clobber existing file \"'netuse/daemons/getload.c'\"
  503. else
  504.   echo shar: Extracting \"'netuse/daemons/getload.c'\" \(8710 characters\)
  505.   sed "s/^X//" >'netuse/daemons/getload.c' <<'END_OF_FILE'
  506. X/******************************************************************************
  507. X This code gets the load average for a DEC or SUN.  (See below for extensions 
  508. X to other platforms.)
  509. X define mips for DEC
  510. X define sun for sun. (the sun needs libkvm.a linked in)
  511. X define testing for complilable program
  512. X Hacked up by: Mike Neil on Oct 11, 1990.
  513. X
  514. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  515. X
  516. X User agrees to reproduce said copyright notice on all copies of the software
  517. X made by the recipient.  
  518. X
  519. X All Rights Reserved. Permission is hereby granted for the recipient to make
  520. X copies and use this software for its own internal purposes only. Recipient of
  521. X this software may re-distribute this software outside of their own
  522. X institution. Permission to market this software commercially, to include this
  523. X product as part of a commercial product, or to make a derivative work for
  524. X commercial purposes, is explicitly prohibited.  All other uses are also
  525. X prohibited unless authorized in writing by the Regents of the University of
  526. X Michigan.
  527. X
  528. X This software is offered without warranty. The Regents of the University of
  529. X Michigan disclaim all warranties, express or implied, including but not
  530. X limited to the implied warranties of merchantability and fitness for any
  531. X particular purpose. In no event shall the Regents of the University of
  532. X Michigan be liable for loss or damage of any kind, including but not limited
  533. X to incidental, indirect, consequential, or special damages. 
  534. X******************************************************************************/
  535. X
  536. X
  537. X#if (defined(mips ) || defined(hpux))
  538. X
  539. X/*
  540. X * This code gets the load average for a DEC running Ultrix
  541. X *
  542. X * Hacked up by: Mike Neil from the xload sources.
  543. X */
  544. X
  545. X
  546. X#include <stdio.h>
  547. X#include <nlist.h>
  548. X
  549. X
  550. Xextern long lseek();
  551. Xextern void exit();
  552. X
  553. Xstatic struct nlist namelist[] = {        
  554. X#ifdef hpux
  555. X    {"avenrun"},
  556. X#else
  557. X    {"_avenrun"},
  558. X#endif
  559. X    {0}
  560. X};
  561. X
  562. Xlong loadavg_seek;
  563. X
  564. X#ifdef __STDC__
  565. Xvoid InitGetLoad(void)
  566. X#else
  567. Xvoid InitGetLoad()
  568. X#endif
  569. X{
  570. X    extern void nlist();
  571. X
  572. X#ifdef hpux
  573. X    nlist( "/hp-ux", namelist);
  574. X#else
  575. X    nlist( "/vmunix", namelist);
  576. X#endif
  577. X    if (namelist[0].n_type == 0 || namelist[0].n_value == 0) {
  578. X    /* error getting name index */
  579. X      exit(-1);
  580. X    }
  581. X    loadavg_seek = namelist[0].n_value;
  582. X
  583. X}
  584. X
  585. X#ifdef __STDC__
  586. Xdouble GetLoadPoint(double *l1,double *l2,double *l3)
  587. X#else
  588. Xdouble GetLoadPoint(l1,l2,l3)
  589. Xdouble *l1,*l2,*l3;
  590. X#endif
  591. X{
  592. X    static kmem;
  593. X
  594. X    kmem = open("/dev/kmem", 000        );
  595. X    if (kmem < 0)
  596. X    {
  597. X      /* Error opening /dev/kmem */
  598. X    }
  599. X    
  600. X    (void) lseek(kmem, loadavg_seek, 0);
  601. X    {
  602. X#ifdef hpux
  603. X        read(kmem, (char *)l1, sizeof(double));
  604. X        read(kmem, (char *)l2, sizeof(double));
  605. X        read(kmem, (char *)l3, sizeof(double));
  606. X#else
  607. X        int temp;
  608. X        (void) read(kmem, (char *)&temp, sizeof(int));
  609. X        *l1 =     (((double)(temp))/(1<<    8));
  610. X        (void) read(kmem, (char *)&temp, sizeof(int));
  611. X        *l2 =     (((double)(temp))/(1<<    8));
  612. X        (void) read(kmem, (char *)&temp, sizeof(int));
  613. X        *l3 =     (((double)(temp))/(1<<    8));
  614. X#endif
  615. X    }
  616. X  close(kmem);    
  617. X    
  618. X    return(*l1);
  619. X}
  620. X#endif
  621. X
  622. X
  623. X#ifdef sun
  624. X/*
  625. X * This code gets the load average for a SUN running 4.x.x
  626. X *
  627. X * Hacked up by: Mike Neil from the w sources.
  628. X */
  629. X
  630. X#include <stdio.h>
  631. X#include <nlist.h>
  632. X#include <sys/stat.h>
  633. X#include <sys/proc.h>
  634. X#include <kvm.h>
  635. X#include <fcntl.h>
  636. X
  637. X
  638. Xlong    avenrun[3];
  639. Xkvm_t    *kd;            /* kernel descriptor for Kernel VM calls */
  640. Xchar    *prog;            /* pointer to invocation name */
  641. X
  642. Xstruct    nlist nl[] = {
  643. X    { "_avenrun" },
  644. X#define    X_AVENRUN    0
  645. X    { "" },
  646. X};
  647. X
  648. X
  649. X/*
  650. X * readsym: get the value of a symbol from the namelist.
  651. X * exit if error.
  652. X */
  653. Xreadsym(n, b, s)
  654. Xint n;
  655. Xchar *b;
  656. Xint s;
  657. X{
  658. X    if (nl[n].n_type == 0) {
  659. X        fprintf(stderr, "%s: '%s' not in namelist\n",
  660. X            prog, nl[n].n_name);
  661. X        return(-1);
  662. X    }
  663. X    if (kvm_read(kd, nl[n].n_value, b, s) != s) {
  664. X        fprintf(stderr, "%s: kernel read error\n", prog);
  665. X        return(-1);
  666. X    }
  667. X}
  668. X
  669. X#ifdef __STDC__
  670. Xvoid InitGetLoad(void)
  671. X#else
  672. Xvoid InitGetLoad()
  673. X#endif
  674. X{
  675. X    /*Just a stub */
  676. X}
  677. X
  678. X#ifdef __STDC__
  679. Xdouble GetLoadPoint(double *l1,double *l2,double *l3)
  680. X#else
  681. Xdouble GetLoadPoint(l1,l2,l3)
  682. Xdouble *l1,*l2,*l3;
  683. X#endif
  684. X{
  685. X    double loadavg;
  686. X
  687. X            if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, prog)) == NULL) {
  688. X                return(-1);
  689. X            }
  690. X            if (kvm_nlist(kd, nl) != 0) {
  691. X                fprintf(stderr, "%s: symbols missing from namelist\n", prog);
  692. X                return(-1);
  693. X            }
  694. X    
  695. X            readsym(X_AVENRUN, avenrun, sizeof(avenrun));
  696. X            
  697. X            *l1 = (double)avenrun[0]/FSCALE;
  698. X            *l2 = (double)avenrun[1]/FSCALE;
  699. X            *l3 = (double)avenrun[2]/FSCALE;
  700. X
  701. X                        kvm_close(kd);
  702. X            return(*l1);
  703. X}
  704. X#endif
  705. X
  706. X#ifdef _AIX
  707. X
  708. X/*
  709. X * This version of this module (getload.c) is specifically for the IBM
  710. X * RS/6000 AIX 3.1 platform.
  711. X *
  712. X *  Charley Kline, University of Illinois Computing Services
  713. X *  c-kline@uiuc.edu
  714. X *
  715. X * Modified for use with 1, 5, and 15 minute averages by Michael Neil and
  716. X * Lee Liming.
  717. X */
  718. X
  719. X
  720. X#include <stdio.h>
  721. X#include <sys/sysinfo.h>
  722. X#include <sys/types.h>
  723. X#include <unistd.h>
  724. X#include <fcntl.h>
  725. X#include <math.h>
  726. X#include <nlist.h>
  727. X
  728. X
  729. Xstruct nlist kernelnames[] = {{"sysinfo", 0, 0, 0, 0, 0},{NULL, 0, 0, 0, 0, 0}};
  730. X
  731. X
  732. X#ifdef __STDC__
  733. Xvoid InitGetLoad(void)
  734. X#else
  735. Xvoid InitGetLoad()
  736. X#endif
  737. X{
  738. X    /*Just a stub */
  739. X}
  740. X
  741. X
  742. X#ifdef __STDC__
  743. Xdouble GetLoadPoint(double *l1,double *l2,double *l3)
  744. X#else
  745. Xdouble GetLoadPoint(l1,l2,l3)
  746. Xdouble *l1,*l2,*l3;
  747. X#endif
  748. X{
  749. X    static double avenrun=0.0,avenrun5=0.0,avenrun15=0.0;
  750. X    double loadav;
  751. X    struct sysinfo si;
  752. X    static int rq_old = 0, ro_old = 0;
  753. X    static initted = 0;
  754. X    static int fd;
  755. X    double multiplier;
  756. X    double t;
  757. X
  758. X    /*
  759. X    ** Do stuff we only need to do once per invocation, like opening
  760. X    ** the kmem file and fetching the parts of the symbol table.
  761. X    */
  762. X        if (!initted) {
  763. X                initted = 1;
  764. X                knlist(kernelnames, 1, sizeof (struct nlist));
  765. X                fd = open("/dev/kmem", O_RDONLY);
  766. X                if (fd < 0) {
  767. X                        perror("kmem");
  768. X                        exit(1);
  769. X                }
  770. X        }
  771. X        
  772. X        /*
  773. X    ** Get the system info structure from the running kernel.
  774. X    */
  775. X    lseek(fd, kernelnames[0].n_value, SEEK_SET);
  776. X    read(fd, &si, sizeof (struct sysinfo));
  777. X
  778. X    /*
  779. X    ** AIX doesn't keep the load average variables in the kernel; all
  780. X    ** we can get is the current number of runnable processes by
  781. X    ** observing the difference between the runque and runocc values
  782. X    ** in sysinfo, and dividing. Having done this, however, we can apply
  783. X    ** a TENEX-style exponential time-average to it by computing an
  784. X    ** averaging multiplier based on the sampling interval. This is then
  785. X    ** used to factor in the current number of runnable processes to our
  786. X    ** running load average. The result "looks right" when observed in
  787. X    ** conjunction with the process table and user activity.
  788. X    **
  789. X    ** We subtract one from the number of running processes given us by
  790. X    ** the kernel because for some reason AIX always calls one of the
  791. X    ** kprocs "runnable" even though it uses very little CPU. Subtracting
  792. X    ** this out gives a load average near zero when the machine is mostly
  793. X    ** idle, which is more familiar to those of us who are used to
  794. X    ** bsd-style load averages.                   /cvk
  795. X    */
  796. X    
  797. X    t = (double)(si.runocc - ro_old);
  798. X    loadav = (double)(si.runque - rq_old) / t - 1.0;
  799. X    rq_old = si.runque;
  800. X    ro_old = si.runocc;
  801. X    multiplier = exp(-t/60.);
  802. X    avenrun = multiplier * avenrun + (1.0 - multiplier) * loadav;
  803. X
  804. X    multiplier = exp(-t/300.);
  805. X    avenrun5 = multiplier * avenrun5 + (1.0 - multiplier) * loadav;
  806. X
  807. X    multiplier = exp(-t/900.);
  808. X    avenrun15 = multiplier * avenrun15 + (1.0 - multiplier) * loadav;
  809. X    
  810. X/*
  811. X    printf("%d %d %f %f %f %f %f\n", si.runque, si.runocc, t, loadav, avenrun,
  812. X    avenrun5, avenrun15);
  813. X*/
  814. X    *l1=avenrun; *l2=avenrun5; *l3=avenrun15;
  815. X    return(*l1);
  816. X    }
  817. X
  818. X/*
  819. Xvoid main()
  820. X{
  821. X        int    i;
  822. X        
  823. X        for (i = 0; i < 10; i++) {
  824. X                GetLoadPoint();
  825. X                sleep(10);
  826. X        }
  827. X}
  828. X*/
  829. X
  830. X#endif
  831. X
  832. X
  833. X#ifdef apollo
  834. X
  835. X/* 
  836. X  This code hacked up by Lee Liming, 10/11/91, from the Apollo uptime sources.
  837. X*/
  838. X
  839. X#include <stdio.h>
  840. X#include <sys/time.h>
  841. X
  842. X
  843. Xtypedef long proc1_$loadav_t[3];
  844. X
  845. Xvoid proc1_$get_loadav();
  846. X
  847. X
  848. X#ifdef __STDC__
  849. Xvoid InitGetLoad(void)
  850. X#else
  851. Xvoid InitGetLoad()
  852. X#endif
  853. X{
  854. X}
  855. X
  856. X
  857. X#ifdef __STDC__
  858. Xdouble GetLoadPoint(double *l1,double *l2,double *l3)
  859. X#else
  860. Xdouble GetLoadPoint(l1,l2,l3)
  861. Xdouble *l1,*l2,*l3;
  862. X#endif
  863. X{
  864. X     proc1_$loadav_t avenrun;
  865. X     int i;
  866. X
  867. X     proc1_$get_loadav(avenrun);
  868. X     *l1=avenrun[0]/65536.;
  869. X     *l2=avenrun[1]/65536.;
  870. X     *l3=avenrun[2]/65536.;
  871. X     return(*l1);
  872. X}
  873. X
  874. X#endif /* apollo */
  875. X
  876. X
  877. X#ifdef testing
  878. Xmain()
  879. X{
  880. X     double l1,l2,l3,rv;
  881. X
  882. X     printf("Starting...\n"); fflush(stdout);
  883. X     InitGetLoad();
  884. X     printf("Between...\n"); fflush(stdout);
  885. X     rv=GetLoadPoint(&l1,&l2,&l3);
  886. X     printf("rv=%0.2lf l1=%0.2lf l2=%0.2lf l3=%0.2lf\n",rv,l1,l2,l3);
  887. X}
  888. X#endif
  889. END_OF_FILE
  890.   if test 8710 -ne `wc -c <'netuse/daemons/getload.c'`; then
  891.     echo shar: \"'netuse/daemons/getload.c'\" unpacked with wrong size!
  892.   fi
  893.   # end of 'netuse/daemons/getload.c'
  894. fi
  895. if test -f 'netuse/lib/netuse.h' -a "${1}" != "-c" ; then 
  896.   echo shar: Will not clobber existing file \"'netuse/lib/netuse.h'\"
  897. else
  898.   echo shar: Extracting \"'netuse/lib/netuse.h'\" \(5782 characters\)
  899.   sed "s/^X//" >'netuse/lib/netuse.h' <<'END_OF_FILE'
  900. X/******************************************************************************
  901. X NETUSE.H - NETUSE Client Library header file
  902. X
  903. X This header file defines the functions and data types provided by the NETUSE
  904. X client library.  This is the header file which should be used when linking
  905. X with the libNetuse.a library to create a NETUSE client.
  906. X
  907. X Lee Liming and Michael Neil, The Computer Aided Engineering Network
  908. X The University of Michigan
  909. X
  910. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  911. X
  912. X User agrees to reproduce said copyright notice on all copies of the software
  913. X made by the recipient.  
  914. X
  915. X All Rights Reserved. Permission is hereby granted for the recipient to make
  916. X copies and use this software for its own internal purposes only. Recipient of
  917. X this software may re-distribute this software outside of their own
  918. X institution. Permission to market this software commercially, to include this
  919. X product as part of a commercial product, or to make a derivative work for
  920. X commercial purposes, is explicitly prohibited.  All other uses are also
  921. X prohibited unless authorized in writing by the Regents of the University of
  922. X Michigan.
  923. X
  924. X This software is offered without warranty. The Regents of the University of
  925. X Michigan disclaim all warranties, express or implied, including but not
  926. X limited to the implied warranties of merchantability and fitness for any
  927. X particular purpose. In no event shall the Regents of the University of
  928. X Michigan be liable for loss or damage of any kind, including but not limited
  929. X to incidental, indirect, consequential, or special damages. 
  930. X******************************************************************************/
  931. X
  932. X#ifndef _NETUSE_INCLUDED_
  933. X#define _NETUSE_INCLUDED_
  934. X
  935. X#include <sys/types.h>
  936. X#include "config.h"
  937. X
  938. X
  939. X#ifndef _PROTOCOL_INCLUDED_
  940. X
  941. X/* Machine/vendor types */
  942. X
  943. X#define MACH_DEC           1                                   /* DECstation */
  944. X#define MACH_SUN           2                                          /* Sun */
  945. X#define MACH_IBM_RS6000    3                                  /* IBM RS/6000 */
  946. X#define MACH_APOLLO        4                                       /* Apollo */
  947. X#define MACH_HP            5                                       /* HP9000 */
  948. X
  949. X#define MODEL_DS3100       1                          /* Machine model types */
  950. X#define MODEL_DS5000200    2
  951. X#define MODEL_DS5000120    3
  952. X#define MODEL_SUN4         4
  953. X#define MODEL_SUN4_65      5
  954. X#define MODEL_SUN4_50      6
  955. X#define MODEL_RS320        7
  956. X#define MODEL_RS520        8
  957. X#define MODEL_RS530        9
  958. X#define MODEL_RS540       10
  959. X#define MODEL_RS730       11
  960. X#define MODEL_RS930       12
  961. X#define MODEL_AP3000      13
  962. X#define MODEL_AP3500      14
  963. X#define MODEL_AP4000      15
  964. X#define MODEL_AP4500      16
  965. X#define MODEL_AP5500      17
  966. X#define MODEL_AP10010     18
  967. X#define MODEL_AP10020     19
  968. X#define MODEL_HP425E      20
  969. X#define MODEL_HP425T      21
  970. X#define MODEL_HP9000720   22
  971. X#define MODEL_SUN3        23
  972. X#define MODEL_AP2500      24
  973. X#define MODEL_DS5000133   25
  974. X#define MODEL_HP9000705   26
  975. X#define MODEL_HP9000710   27
  976. X#define MODEL_HP9000730   28
  977. X#define MODEL_HP9000750   29
  978. X#define MODEL_RS220       30
  979. X#define MODEL_RS320H      31
  980. X#define MODEL_RS340       32
  981. X#define MODEL_RS350       33
  982. X#define MODEL_RS530H      34
  983. X#define MODEL_RS550       35
  984. X#define MODEL_RS560       36
  985. X#define MODEL_RS950       37
  986. X
  987. X/* Modes for netuseGetList() */
  988. X
  989. X#define MODE_DISP       0x00        /* Normal listing (limited # of machines */
  990. X#define MODE_ALL        0x01     /* List ALL hosts (even ones that are down) */
  991. X#define MODE_DOWN       0x02                /* List only hosts that are down */
  992. X#define MODE_MASK       0x03                      /* Mask for all list modes */
  993. X#define MODE_MODELS     0x04 /* List model types instead of last report time */
  994. X#define MODE_NET        0x80                /* Network listing mode (add \r) */
  995. X
  996. X#define RV_OK              0     /* Protocol response: All's well            */
  997. X#define RV_ACK             1     /* Protocol response: Report acknowledged   */
  998. X#define RV_NACK            2     /* Protocol response: Report not ack'ed     */
  999. X#define RV_TIMEOUT         3     /* Protocol response: Timeout               */
  1000. X#define RV_NOMATCH         4     /* Protocol response: Nothing matched       */
  1001. X#define RV_NOFILE          5     /* Protocol response: Unable to access file */
  1002. X
  1003. X#define RV_nOK             0     /* Network response: All's well             */
  1004. X#define RV_nTIMEOUT       -1     /* Network response: Timeout                */
  1005. X#define RV_nBADSEND       -2     /* Network response: Unable to send packet  */
  1006. X#define RV_nBADRECV       -3     /* Network response: Unable to receive      */
  1007. X
  1008. X#endif   /* !defined(_PROTOCOL_INCLUDED_) */
  1009. X
  1010. X
  1011. X#ifdef __STDC__
  1012. X
  1013. Xint     netuseGetList(u_char machine,u_char model,int mode);
  1014. Xu_long  netGetAddress(char *buf);
  1015. Xchar   *netGetHostname(u_long ipaddr,char *buf);
  1016. Xchar   *netGetMachType(u_char mtype,char *mtname);
  1017. Xu_char  netStrToMach(char *mtname);
  1018. Xchar   *netGetModelType(u_char mtype,char *mtname);
  1019. Xu_char  netStrToModel(char *mtname);
  1020. Xchar   *netuseFind(char *name,double l1,double l2,double l3,int users,
  1021. X                   int console,int tmp,u_char machine,u_char model);
  1022. Xint     netuseAddName(char *name,u_char type,u_char model);
  1023. Xint     netuseAddIP(u_long ip_addr,u_short type);
  1024. Xint     netuseDelName(char *name);
  1025. Xint     netuseSaveState(void);
  1026. Xint     netuseLoadHosts(void);
  1027. X
  1028. X#else
  1029. X
  1030. Xint     netuseGetList();
  1031. Xu_long  netGetAddress();
  1032. Xchar   *netGetHostname();
  1033. Xchar   *netGetMachType();
  1034. Xu_char  netStrToMach();
  1035. Xchar   *netGetModelType();
  1036. Xu_char  netStrToModel();
  1037. Xchar   *netuseFind();
  1038. Xint     netuseAddName();
  1039. Xint     netuseAddIP();
  1040. Xint     netuseDelName();
  1041. Xint     netuseSaveState();
  1042. Xint     netuseLoadHosts();
  1043. X
  1044. X#endif
  1045. X
  1046. X#endif  /* _NETUSE_INCLUDED_ */
  1047. END_OF_FILE
  1048.   if test 5782 -ne `wc -c <'netuse/lib/netuse.h'`; then
  1049.     echo shar: \"'netuse/lib/netuse.h'\" unpacked with wrong size!
  1050.   fi
  1051.   # end of 'netuse/lib/netuse.h'
  1052. fi
  1053. if test -f 'netuse/lib/parser.c' -a "${1}" != "-c" ; then 
  1054.   echo shar: Will not clobber existing file \"'netuse/lib/parser.c'\"
  1055. else
  1056.   echo shar: Extracting \"'netuse/lib/parser.c'\" \(9550 characters\)
  1057.   sed "s/^X//" >'netuse/lib/parser.c' <<'END_OF_FILE'
  1058. X/******************************************************************************
  1059. X PARSER.C - String parsing functions
  1060. X
  1061. X (c) 1990, 1991, 1992, R. Lee Liming, Jr.
  1062. X USED WITH PERMISSION OF THE AUTHOR
  1063. X ALL RIGHTS RESERVED
  1064. X
  1065. X This file provides basic string manipulation functions for general-purpose
  1066. X parsing.
  1067. X
  1068. X strip() removes trailing spaces from a string.
  1069. X strip_leading() removes leading spaces from a string.
  1070. X scrunch() removes all spaces from a string.
  1071. X stoupper() converts an entire string to uppercase.
  1072. X spicture() puts a string into a fixed-size text field.
  1073. X whitespace() returns true if it's argument is a whitespace character,
  1074. X   false otherwise.
  1075. X textparam() extracts the nth token (separated by whitespace, starting at 0)
  1076. X   from its first argument.
  1077. X limits() parses a number range string and returns the start and end values.
  1078. X strstr() returns a pointer to a substring within another string.
  1079. X******************************************************************************/
  1080. X
  1081. X#include <ctype.h>
  1082. X#include <stdio.h>
  1083. X#include <string.h>
  1084. X#include <strings.h>
  1085. X
  1086. X#include "parser.h"
  1087. X
  1088. X
  1089. X/*****************************************************************************
  1090. X char *strip(str)
  1091. X
  1092. X This function removes trailing spaces from the string passed to it, and
  1093. X returns a pointer to its argument.
  1094. X*****************************************************************************/
  1095. X
  1096. X#ifdef __STDC__
  1097. Xchar *strip(char *s)
  1098. X#else
  1099. Xchar *strip(s)
  1100. Xchar *s;
  1101. X#endif
  1102. X{
  1103. X     char *p;
  1104. X
  1105. X     for (p=s+strlen(s)-1; (p>=s) && (*p==' '); p--)
  1106. X          *p='\0';
  1107. X     return(s);
  1108. X}
  1109. X
  1110. X
  1111. X/*****************************************************************************
  1112. X char *strip_leading(str)
  1113. X
  1114. X This function removes leading spaces from the string passed to it, and
  1115. X returns a pointer to its argument.
  1116. X*****************************************************************************/
  1117. X
  1118. X#ifdef __STDC__
  1119. Xchar *strip_leading(char *s)
  1120. X#else
  1121. Xchar *strip_leading(s)
  1122. Xchar *s;
  1123. X#endif
  1124. X{
  1125. X     char *p;
  1126. X
  1127. X     for (p=s; (*p!='\0') && (*p==' '); p++)
  1128. X          ;
  1129. X     strcpy(s,p);
  1130. X     return(s);
  1131. X}
  1132. X
  1133. X
  1134. X/*****************************************************************************
  1135. X char *scrunch(char *str)
  1136. X
  1137. X This function removes ALL spaces from a string, including internal spaces.
  1138. X*****************************************************************************/
  1139. X
  1140. X#ifdef __STDC__
  1141. Xchar *scrunch(char *str)
  1142. X#else
  1143. Xchar *scrunch(str)
  1144. Xchar *str;
  1145. X#endif
  1146. X{
  1147. X     char *p,*q;
  1148. X
  1149. X     for (p=str; (*p!='\0'); p++)
  1150. X          if (*p==' ') {
  1151. X               for (q=p; (*q==' '); q++)
  1152. X                    ;
  1153. X               strcpy(p,q);
  1154. X          }
  1155. X     return(str);
  1156. X}
  1157. X
  1158. X
  1159. X/*****************************************************************************
  1160. X char *stoupper(char *str)
  1161. X
  1162. X This function converts the string passed to it to uppercase, and returns a
  1163. X pointer to it.
  1164. X*****************************************************************************/
  1165. X
  1166. X#ifdef __STDC__
  1167. Xchar *stoupper(char *s)
  1168. X#else
  1169. Xchar *stoupper(s)
  1170. Xchar *s;
  1171. X#endif
  1172. X{
  1173. X     char *p;
  1174. X
  1175. X     for (p=s; *p!='\0'; p++) if (islower(*p)) *p=toupper(*p);
  1176. X     return(s);
  1177. X}
  1178. X
  1179. X
  1180. X/*****************************************************************************
  1181. X char *spicture(char *str,int n,char *temp)
  1182. X
  1183. X This function left-justifies a string in a fixed-size text field of size n.
  1184. X The string is padded or truncated as necessary.
  1185. X*****************************************************************************/
  1186. X
  1187. X#ifdef __STDC__
  1188. Xchar *spicture(char *str,int n,char *temp)
  1189. X#else
  1190. Xchar *spicture(str,n,temp)
  1191. Xchar *str;
  1192. Xint n;
  1193. Xchar *temp;
  1194. X#endif
  1195. X{
  1196. X     char *p,*q;
  1197. X     int i;
  1198. X
  1199. X     for (p=str,q=temp,i=0; i<n; i++)
  1200. X          if ((p==NULL) || (*p=='\0')) *(q++)=' ';
  1201. X          else *(q++)=(*(p++));
  1202. X     *q='\0';
  1203. X     return(temp);
  1204. X}
  1205. X
  1206. X
  1207. X/*****************************************************************************
  1208. X int whitespace(ch)
  1209. X
  1210. X This function returns true if its argument is a whitespace character (or
  1211. X comma), false otherwise.  Used for separating tokens in a string.
  1212. X*****************************************************************************/
  1213. X
  1214. X#ifdef __STDC__
  1215. Xint whitespace(char ch)
  1216. X#else
  1217. Xint whitespace(ch)
  1218. Xchar ch;
  1219. X#endif
  1220. X{
  1221. X     switch (ch) {
  1222. X          case ' ':
  1223. X          case '\t':
  1224. X          case ',':
  1225. X               return(1);
  1226. X          default:
  1227. X               return(0);
  1228. X     }
  1229. X}
  1230. X
  1231. X
  1232. X/*****************************************************************************
  1233. X char *textparam(str,n,buf)
  1234. X
  1235. X This is an interesting function, which breaks the first string up into
  1236. X tokens (separated by whitespace(), defined above), and returns the nth one
  1237. X in the third parameter.  n starts at 0 (zero) for the first token on the
  1238. X line.  The function returns a pointer to the extracted token.  Yeah, it's
  1239. X got a lot of +'s and ='s, but it seems to work...  ;-)
  1240. X*****************************************************************************/
  1241. X
  1242. X#ifdef __STDC__
  1243. Xchar *textparam(char *s,int n,char t[])
  1244. X#else
  1245. Xchar *textparam(s,n,t)
  1246. Xchar *s;
  1247. Xint n;
  1248. Xchar t[];
  1249. X#endif
  1250. X{
  1251. X     int i;
  1252. X     char *p;
  1253. X
  1254. X     for (p=s; (*p!='\0') && whitespace(*p); p++)
  1255. X          ;
  1256. X     for (i=0; (i<n) && (*p!='\0'); i++) {
  1257. X          if (*p=='"') {
  1258. X               for (p++; (*p!='\0') && (*p!='"'); p++)
  1259. X                    if ((*p=='\\') && (*(p+1)!='\0')) p++;
  1260. X               if (*p=='"') p++;
  1261. X          }
  1262. X          else for ( ; (*p!='\0') && !whitespace(*p); p++)
  1263. X                    ;
  1264. X          for ( ; (*p!='\0') && whitespace(*p); p++)
  1265. X               ;
  1266. X     }
  1267. X     if (*p=='"') {
  1268. X          for (i=0,p++; (*p!='\0') && (*p!='"'); p++,i++)
  1269. X               if ((*p=='\\') && (*(p+1)!='\0')) t[i]=(*(++p));
  1270. X               else t[i]=(*p);
  1271. X     }
  1272. X     else for (i=0; (*p!='\0') && !whitespace(*p); p++,i++)
  1273. X               t[i]=(*p);
  1274. X     t[i]='\0';
  1275. X     return(t);
  1276. X}
  1277. X
  1278. X
  1279. X/*****************************************************************************
  1280. X char *encapsulate(char *str,char *buf)
  1281. X
  1282. X The encapsulate() function encapsulates a string into a format that can be
  1283. X quoted and then successfully parsed by the textparam() function.  It escapes
  1284. X all double quotes with a backslash, and doubles all backslashes in the
  1285. X original string.  The breakout() function is used to break the string out
  1286. X of this encapsulation.
  1287. X*****************************************************************************/
  1288. X
  1289. X#ifdef __STDC__
  1290. Xchar *encapsulate(char *str,char *buf)
  1291. X#else
  1292. Xchar *encapsulate(str,buf)
  1293. Xchar *str;
  1294. Xchar *buf;
  1295. X#endif
  1296. X{
  1297. X     char *p,*q;
  1298. X
  1299. X     for (p=str,q=buf; *p!='\0'; p++) {
  1300. X          switch (*p) {
  1301. X               case '"':
  1302. X                    *(q++)='\\';
  1303. X                    *(q++)='"';
  1304. X                    break;
  1305. X               case '\\':
  1306. X                    *(q++)='\\';
  1307. X                    *(q++)='\\';
  1308. X                    break;
  1309. X               default:
  1310. X                    *(q++)=(*p);
  1311. X                    break;
  1312. X          }
  1313. X     }
  1314. X     *q='\0';
  1315. X     return(buf);
  1316. X}
  1317. X
  1318. X
  1319. X/*****************************************************************************
  1320. X char *breakout(char *str,char *buf)
  1321. X
  1322. X The breakout() function is used to break the string out of an encapsulated
  1323. X string format made using the encapsulate() function.
  1324. X*****************************************************************************/
  1325. X
  1326. X#ifdef __STDC__
  1327. Xchar *breakout(char *str,char *buf)
  1328. X#else
  1329. Xchar *breakout(str,buf)
  1330. Xchar *str;
  1331. Xchar *buf;
  1332. X#endif
  1333. X{
  1334. X     char *p,*q;
  1335. X
  1336. X     for (p=str,q=buf; *p!='\0'; p++) {
  1337. X          switch (*p) {
  1338. X               case '\\':
  1339. X                    *(q++)=(*(++p));
  1340. X                    break;
  1341. X               default:
  1342. X                    *(q++)=(*p);
  1343. X                    break;
  1344. X          }
  1345. X     }
  1346. X     *q='\0';
  1347. X     return(buf);
  1348. X}
  1349. X
  1350. X
  1351. X/*****************************************************************************
  1352. X int limits(char *rstr,int *start,int *stop)
  1353. X
  1354. X The limits function parses a range string of the form "<num> [ - <num> ]"
  1355. X into a start and stop value.  If the range syntax is legal, the return
  1356. X value is zero.
  1357. X*****************************************************************************/
  1358. X
  1359. X#ifdef __STDC__
  1360. Xint limits(char *rstr,int *start,int *stop)
  1361. X#else
  1362. Xint limits(rstr,start,stop)
  1363. Xchar *rstr;
  1364. Xint *start,*stop;
  1365. X#endif
  1366. X{
  1367. X     char *p,temp[10];
  1368. X     int i;
  1369. X
  1370. X     strip(strip_leading(rstr));
  1371. X     if (!strlen(rstr)) return(-1);
  1372. X     for (p=rstr,i=0; (*p>='0') && (*p<='9'); p++,i++)
  1373. X          temp[i]=(*p);
  1374. X     temp[i]='\0';
  1375. X     if ((*p!='\0') && (*p!='-') && (*p!=' ')) return(-1);
  1376. X     (*stop)=(*start)=atoi(temp);
  1377. X     if (*p=='\0') return(0);
  1378. X     strcpy(temp,++p);
  1379. X     strip_leading(temp);
  1380. X     if (temp[0]=='-') {
  1381. X          strcpy(temp,temp+1);
  1382. X          strip_leading(temp);
  1383. X     }
  1384. X     for (p=temp,i=0; (*p>='0') && (*p<='9'); p++,i++)
  1385. X          ;
  1386. X     if (*p!='\0') return(-2);
  1387. X     *stop=atoi(temp);
  1388. X     return(0);
  1389. X}
  1390. X
  1391. X
  1392. X/*****************************************************************************
  1393. X char *strstr(source,target)
  1394. X
  1395. X This function searches for the first occurence of the target string in the
  1396. X source string, and returns a pointer to it within the source string.  The
  1397. X function returns NULL if no match is found.
  1398. X*****************************************************************************/
  1399. X
  1400. X#ifdef __STDC__
  1401. Xchar *strstr(char *p,char s[])
  1402. X#else
  1403. Xchar *strstr(p,s)
  1404. Xchar *p,s[];
  1405. X#endif
  1406. X{
  1407. X     char *idx,*tmp;
  1408. X     int i,found=0;
  1409. X
  1410. X     if (!strlen(p)) return(NULL);
  1411. X     while (!found) {
  1412. X          if ((tmp=idx=index(p,s[0]))==0) break;
  1413. X          else {
  1414. X               for (i=0; (s[i]!='\0') && (*idx==s[i]); idx++,i++)
  1415. X                    ;
  1416. X               if (s[i]=='\0') found=1;
  1417. X               else p=(++tmp);
  1418. X          }
  1419. X     }
  1420. X     if (!found) return(NULL);
  1421. X     else return(tmp);
  1422. X}
  1423. END_OF_FILE
  1424.   if test 9550 -ne `wc -c <'netuse/lib/parser.c'`; then
  1425.     echo shar: \"'netuse/lib/parser.c'\" unpacked with wrong size!
  1426.   fi
  1427.   # end of 'netuse/lib/parser.c'
  1428. fi
  1429. if test -f 'netuse/lib/protocol.h' -a "${1}" != "-c" ; then 
  1430.   echo shar: Will not clobber existing file \"'netuse/lib/protocol.h'\"
  1431. else
  1432.   echo shar: Extracting \"'netuse/lib/protocol.h'\" \(7650 characters\)
  1433.   sed "s/^X//" >'netuse/lib/protocol.h' <<'END_OF_FILE'
  1434. X/******************************************************************************
  1435. X PROTOCOL.H - NETUSE Protocol Definition
  1436. X
  1437. X This header file defines the NETUSE protocol, used for communication with
  1438. X the NETUSE server (netuse).  All clients, including the netused daemon, use
  1439. X this protocol to send and receive information to/from the server.
  1440. X
  1441. X Lee Liming and Michael Neil, The Computer Aided Engineering Network
  1442. X The University of Michigan
  1443. X
  1444. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  1445. X
  1446. X User agrees to reproduce said copyright notice on all copies of the software
  1447. X made by the recipient.  
  1448. X
  1449. X All Rights Reserved. Permission is hereby granted for the recipient to make
  1450. X copies and use this software for its own internal purposes only. Recipient of
  1451. X this software may re-distribute this software outside of their own
  1452. X institution. Permission to market this software commercially, to include this
  1453. X product as part of a commercial product, or to make a derivative work for
  1454. X commercial purposes, is explicitly prohibited.  All other uses are also
  1455. X prohibited unless authorized in writing by the Regents of the University of
  1456. X Michigan.
  1457. X
  1458. X This software is offered without warranty. The Regents of the University of
  1459. X Michigan disclaim all warranties, express or implied, including but not
  1460. X limited to the implied warranties of merchantability and fitness for any
  1461. X particular purpose. In no event shall the Regents of the University of
  1462. X Michigan be liable for loss or damage of any kind, including but not limited
  1463. X to incidental, indirect, consequential, or special damages. 
  1464. X******************************************************************************/
  1465. X
  1466. X#ifndef _PROTOCOL_INCLUDED_
  1467. X#define _PROTOCOL_INCLUDED_
  1468. X
  1469. X#include <sys/types.h>
  1470. X#include "config.h"
  1471. X
  1472. X
  1473. X#define SEND_RETRIES       2   /* Send tries before conceding a send failure */
  1474. X#define REQ_RETRIES        2     /* Request tries before conceding a failure */
  1475. X#define TIMEOUT            5    /* Time between request and response timeout */
  1476. X
  1477. X#define OP_NOP             0                      /* NETUSE protocol opcodes */
  1478. X#define OP_STATUS          1                        /* netused status report */
  1479. X#define OP_QUERY           2               /* Request a host of a given type */
  1480. X#define OP_GETLIST         3                 /* Request the entire host list */
  1481. X#define OP_DISPLIST        4              /* Request a host list for display */
  1482. X#define OP_GETDOWN         5         /* Request list of hosts which are down */
  1483. X#define OP_ADDHOST         6                   /* Add a host to the database */
  1484. X#define OP_DELHOST         7              /* Remove a host from the database */
  1485. X#define OP_SAVESTATE       8          /* Store the database in a static file */
  1486. X#define OP_LOADHOSTS       9     /* Re-read the static file to get host list */
  1487. X#define OP_TEXTSTATUS     10              /* netused report on users & class */
  1488. X#define OP_TEXTSTATUS2    11      /* netused report (cont.) on users & class */
  1489. X#define OP_GETMLIST       12     /* Request the entire host list with models */
  1490. X#define OP_DISPMLIST      13  /* Request a host list for display with models */
  1491. X#define OP_GETMDOWN       14       /* Request models of hosts which are down */
  1492. X
  1493. X#define RV_OK              0     /* Protocol response: All's well            */
  1494. X#define RV_ACK             1     /* Protocol response: Report acknowledged   */
  1495. X#define RV_NACK            2     /* Protocol response: Report not ack'ed     */
  1496. X#define RV_TIMEOUT         3     /* Protocol response: Timeout               */
  1497. X#define RV_NOMATCH         4     /* Protocol response: Nothing matched       */
  1498. X#define RV_NOFILE          5     /* Protocol response: Unable to access file */
  1499. X
  1500. X#define RV_nOK             0     /* Network response: All's well             */
  1501. X#define RV_nTIMEOUT       -1     /* Network response: Timeout                */
  1502. X#define RV_nBADSEND       -2     /* Network response: Unable to send packet  */
  1503. X#define RV_nBADRECV       -3     /* Network response: Unable to receive      */
  1504. X
  1505. X#define MODE_DISP       0x00        /* Normal listing (limited # of machines */
  1506. X#define MODE_ALL        0x01     /* List ALL hosts (even ones that are down) */
  1507. X#define MODE_DOWN       0x02                /* List only hosts that are down */
  1508. X#define MODE_MASK       0x03                      /* Mask for all list modes */
  1509. X#define MODE_MODELS     0x04 /* List model types instead of last report time */
  1510. X#define MODE_NET        0x80                /* Network listing mode (add \r) */
  1511. X
  1512. X#define MACH_DEC           1                                /* Machine types */
  1513. X#define MACH_SUN           2
  1514. X#define MACH_IBM_RS6000    3
  1515. X#define MACH_APOLLO        4
  1516. X#define MACH_HP            5
  1517. X
  1518. X#define MODEL_DS3100       1                          /* Machine model types */
  1519. X#define MODEL_DS5000200    2
  1520. X#define MODEL_DS5000120    3
  1521. X#define MODEL_SUN4         4
  1522. X#define MODEL_SUN4_65      5
  1523. X#define MODEL_SUN4_50      6
  1524. X#define MODEL_RS320        7
  1525. X#define MODEL_RS520        8
  1526. X#define MODEL_RS530        9
  1527. X#define MODEL_RS540       10
  1528. X#define MODEL_RS730       11
  1529. X#define MODEL_RS930       12
  1530. X#define MODEL_AP3000      13
  1531. X#define MODEL_AP3500      14
  1532. X#define MODEL_AP4000      15
  1533. X#define MODEL_AP4500      16
  1534. X#define MODEL_AP5500      17
  1535. X#define MODEL_AP10010     18
  1536. X#define MODEL_AP10020     19
  1537. X#define MODEL_HP425E      20
  1538. X#define MODEL_HP425T      21
  1539. X#define MODEL_HP9000720   22
  1540. X#define MODEL_SUN3        23
  1541. X#define MODEL_AP2500      24
  1542. X#define MODEL_DS5000133   25
  1543. X#define MODEL_HP9000705   26
  1544. X#define MODEL_HP9000710   27
  1545. X#define MODEL_HP9000730   28
  1546. X#define MODEL_HP9000750   29
  1547. X#define MODEL_RS220       30
  1548. X#define MODEL_RS320H      31
  1549. X#define MODEL_RS340       32
  1550. X#define MODEL_RS350       33
  1551. X#define MODEL_RS530H      34
  1552. X#define MODEL_RS550       35
  1553. X#define MODEL_RS560       36
  1554. X#define MODEL_RS950       37
  1555. X
  1556. X#ifdef mips
  1557. X#define MACHINETYPE MACH_DEC                  /* Program is running on a DEC */
  1558. X#endif
  1559. X
  1560. X#ifdef hpux
  1561. X#define MACHINETYPE MACH_HP                   /* Program is running on an HP */
  1562. X#endif
  1563. X
  1564. X#ifdef sun
  1565. X#define MACHINETYPE MACH_SUN                  /* Program is running on a Sun */
  1566. X#endif
  1567. X
  1568. X#ifdef _IBMR2
  1569. X#define MACHINETYPE MACH_IBM_RS6000      /* Program is running on an RS/6000 */
  1570. X#endif
  1571. X
  1572. X#ifdef apollo
  1573. X#define MACHINETYPE MACH_APOLLO           /* Program is running on an Apollo */
  1574. X#endif
  1575. X
  1576. X
  1577. Xtypedef struct _userec {
  1578. X             u_char  chksum;               /* Checksum (for error detection) */
  1579. X             u_char  opcode;                                /* Packet opcode */
  1580. X             u_char  retcode;                    /* Return code from request */
  1581. X             u_char  ack;                            /* Acknowedgement field */
  1582. X             u_short load1,load2,load3;                     /* Load averages */
  1583. X             u_short users;                      /* Number of login sessions */
  1584. X             u_long  tmp;                              /* Free space in /tmp */
  1585. X             u_short console;         /* Number of login sessions on display */
  1586. X             u_short uid;                   /* User ID (for making requests) */
  1587. X             u_short filler1;
  1588. X             u_char  machine;                             /* Type of machine */
  1589. X             u_char  model;                                 /* Machine model */
  1590. X        } USEREC;                             /* A NETUSE packet as a struct */
  1591. X
  1592. X#define ipaddr tmp                                   /* Packet field aliases */
  1593. X#define portno load1
  1594. X
  1595. Xtypedef u_char PACKET[sizeof(USEREC)];  /* Used for treating packet as array */
  1596. X
  1597. X#define PACKET_SIZE     sizeof(PACKET)           /* Size (bytes) of a packet */
  1598. X
  1599. X
  1600. X#endif   /* _PROTOCOL_INCLUDED_ */
  1601. END_OF_FILE
  1602.   if test 7650 -ne `wc -c <'netuse/lib/protocol.h'`; then
  1603.     echo shar: \"'netuse/lib/protocol.h'\" unpacked with wrong size!
  1604.   fi
  1605.   # end of 'netuse/lib/protocol.h'
  1606. fi
  1607. echo shar: End of archive 4 \(of 6\).
  1608. cp /dev/null ark4isdone
  1609. MISSING=""
  1610. for I in 1 2 3 4 5 6 ; do
  1611.     if test ! -f ark${I}isdone ; then
  1612.     MISSING="${MISSING} ${I}"
  1613.     fi
  1614. done
  1615. if test "${MISSING}" = "" ; then
  1616.     echo You have unpacked all 6 archives.
  1617.     rm -f ark[1-9]isdone
  1618. else
  1619.     echo You still must unpack the following archives:
  1620.     echo "        " ${MISSING}
  1621. fi
  1622. exit 0
  1623. exit 0 # Just in case...
  1624.