home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume34 / netuse / part04 < prev    next >
Text File  |  1993-01-10  |  51KB  |  1,620 lines

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