home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2328 < prev    next >
Encoding:
Text File  |  1990-12-28  |  8.4 KB  |  330 lines

  1. Newsgroups: alt.sources
  2. From: christos@theory.tn.cornell.edu (Christos S. Zoulas)
  3. Subject: ywho, patch 1
  4. Message-ID: <1990Dec16.021125.19214@batcomputer.tn.cornell.edu>
  5. Date: Sun, 16 Dec 90 02:11:25 GMT
  6.  
  7. Hello again,
  8.  
  9. This is a patch to the ywho program I posted before, that takes care
  10. of the non null terminated hostname printing bug.
  11.  
  12. Thanks to:
  13.  
  14. Mark Nagel         <nagel@buckaroo.ics.uci.edu>
  15. Jan van der Steen     <jansteen@cwi.nl>
  16. Tom Christiansen     <tchrist@pixel.convex.com>
  17.  
  18. for their suggestions, bug report, and fixes.
  19.  
  20. christos
  21.  
  22. *** ywho.1v.orig    Wed Jun 20 00:05:08 1990
  23. --- ywho.1v    Sat Dec 15 20:56:52 1990
  24. ***************
  25. *** 1,8 ****
  26. ! .TH YWHO 1V "28 February 1988"
  27.   .SH NAME
  28. ! ywho/yusers/yuptime \- who, users, uptime on clients in a sun-RPC network.
  29.   .SH SYNOPSIS
  30. ! .B ywho/yusers/yuptime 
  31.   [<host>]|[-g <netgroup>]
  32.   .SH DESCRIPTION
  33.   .I ywho
  34. --- 1,8 ----
  35. ! .TH YWHO 1V "15 December 1990"
  36.   .SH NAME
  37. ! ywho, yusers, yuptime \- who, users, uptime on clients in a sun-RPC network.
  38.   .SH SYNOPSIS
  39. ! .B ywho, yusers, yuptime 
  40.   [<host>]|[-g <netgroup>]
  41.   .SH DESCRIPTION
  42.   .I ywho
  43. ***************
  44. *** 81,87 ****
  45.   .SH AUTHORS 
  46.   James P. Lewis, York University, 1988
  47.   .br
  48. ! Christos S. Zoulas, Cornell University, 1989
  49.   .SH SEE ALSO
  50.   netgroup(5), yp(5)
  51.   .SH NOTE
  52. --- 81,87 ----
  53.   .SH AUTHORS 
  54.   James P. Lewis, York University, 1988
  55.   .br
  56. ! Christos S. Zoulas, Cornell University, 1990
  57.   .SH SEE ALSO
  58.   netgroup(5), yp(5)
  59.   .SH NOTE
  60. *** ywho.c.orig    Thu Oct  4 19:28:46 1990
  61. --- ywho.c    Sat Dec 15 20:56:40 1990
  62. ***************
  63. *** 1,4 ****
  64. ! /* $Header: /usr/share/src/local/common/bin/ywho/RCS/ywho.c,v 1.10 90/10/04 19:28:14 christos Exp $ */
  65.   /* 
  66.    * ywho.c: Use rpc to obtain information about remote users
  67.    *       if it is invoked as yusers, present info in short format
  68. --- 1,4 ----
  69. ! /* $Header: /tmp_mnt/usr/share/src/local/common/bin/ywho/RCS/ywho.c,v 1.11 90/12/15 20:59:44 christos Exp $ */
  70.   /* 
  71.    * ywho.c: Use rpc to obtain information about remote users
  72.    *       if it is invoked as yusers, present info in short format
  73. ***************
  74. *** 19,24 ****
  75. --- 19,28 ----
  76.    *
  77.    *
  78.    * $Log:    ywho.c,v $
  79. +  * Revision 1.11  90/12/15  20:59:44  christos
  80. +  * Fixed remote host printing (again)
  81. +  * and lint cosmetic fixes.
  82. +  * 
  83.    * Revision 1.10  90/10/04  19:28:14  christos
  84.    * Eliminated duplicate hosts from the list.
  85.    * Fixed printing for remote host.
  86. ***************
  87. *** 60,66 ****
  88.    *
  89.    */
  90.   #ifndef lint
  91. ! static char rcsid[] = "$Id: ywho.c,v 1.10 90/10/04 19:28:14 christos Exp $";
  92.   #endif /* lint */
  93.   
  94.   #include <sys/types.h>
  95. --- 64,70 ----
  96.    *
  97.    */
  98.   #ifndef lint
  99. ! static char rcsid[] = "$Id: ywho.c,v 1.11 90/12/15 20:59:44 christos Exp $";
  100.   #endif /* lint */
  101.   
  102.   #include <sys/types.h>
  103. ***************
  104. *** 84,93 ****
  105.   # define HST_LEN 64
  106.   #endif
  107.   
  108.   #define NIL(a) ((a *) 0)
  109. ! #define NEW(a) ((a *) Malloc(sizeof(a)))
  110. ! #define NEWN(a, n) ((a *) Malloc(sizeof(a) * (n)))
  111. ! #define strdup(a) ((char *) strcpy(Malloc(strlen(a) + 1), a))
  112.   #define SEP "\t \n,="
  113.   #ifndef FSCALE
  114.   #define FSCALE (1 << 8)
  115. --- 88,109 ----
  116.   # define HST_LEN 64
  117.   #endif
  118.   
  119. + #ifdef lint
  120. + /*
  121. +  * Make lint think Malloc's value is well aligned.
  122. +  */
  123. + typedef union {
  124. +     double a; long b; int c; short d; char e;
  125. + } *align_t;
  126. + #else
  127. + typedef char *align_t;
  128. + #endif
  129.   #define NIL(a) ((a *) 0)
  130. ! #define NEW(a) ((a *) Malloc((unsigned) sizeof(a)))
  131. ! #define NEWN(a, n) ((a *) Malloc((unsigned) (sizeof(a) * (n))))
  132. ! #define strdup(a) ((char *) strcpy((char *) Malloc((unsigned) (strlen(a) + 1)),\
  133. !                    a))
  134.   #define SEP "\t \n,="
  135.   #ifndef FSCALE
  136.   #define FSCALE (1 << 8)
  137. ***************
  138. *** 113,119 ****
  139.   extern char *getenv();
  140.   extern char *sys_errlist[];
  141.   extern int  errno;
  142. ! static char *Malloc();
  143.   static void do_host();
  144.   static void do_timeout();
  145.   static char *pname;
  146. --- 129,135 ----
  147.   extern char *getenv();
  148.   extern char *sys_errlist[];
  149.   extern int  errno;
  150. ! static align_t Malloc();
  151.   static void do_host();
  152.   static void do_timeout();
  153.   static char *pname;
  154. ***************
  155. *** 193,199 ****
  156.   
  157.       if ( argc == 1 ) {
  158.       home = getenv("HOME");
  159. !     sprintf(buffer, "%s%s.yhosts", home ? home : "", home ? "/" : "");
  160.       fp = fopen(buffer, "r");
  161.   
  162.       if ( fp == NIL(FILE) ) {
  163. --- 209,216 ----
  164.   
  165.       if ( argc == 1 ) {
  166.       home = getenv("HOME");
  167. !     (void) sprintf(buffer, "%s%s.yhosts", 
  168. !                home ? home : "", home ? "/" : "");
  169.       fp = fopen(buffer, "r");
  170.   
  171.       if ( fp == NIL(FILE) ) {
  172. ***************
  173. *** 301,307 ****
  174.       }
  175.       alarm(0);
  176.       }
  177. !     exit(0);
  178.   }
  179.   
  180.   static struct utmpidlearr      cutmpidlearr;
  181. --- 318,324 ----
  182.       }
  183.       alarm(0);
  184.       }
  185. !     return(0);
  186.   }
  187.   
  188.   static struct utmpidlearr      cutmpidlearr;
  189. ***************
  190. *** 319,325 ****
  191.   {
  192.       char                nick_name[HST_LEN], tmp[BUFSIZ];
  193.       int                 ss, dd, hh, mm, printed;
  194. !     int                 addrlen, i, j, sock;
  195.       register CLIENT     *client, *client_st;
  196.       struct hostent      *hp;
  197.       struct timeval      pertry_timeout, total_timeout;
  198. --- 336,342 ----
  199.   {
  200.       char                nick_name[HST_LEN], tmp[BUFSIZ];
  201.       int                 ss, dd, hh, mm, printed;
  202. !     int                 i, sock;
  203.       register CLIENT     *client, *client_st;
  204.       struct hostent      *hp;
  205.       struct timeval      pertry_timeout, total_timeout;
  206. ***************
  207. *** 326,331 ****
  208. --- 343,349 ----
  209.       struct sockaddr_in  server_addr;
  210.       enum clnt_stat      clnt_stat, clnt_stat_st;
  211.       char                *ptr, *host;
  212. +     long        j;
  213.       
  214.   
  215.       (void) strncpy(nick_name, hst->hp.h_name, HST_LEN);
  216. ***************
  217. *** 347,353 ****
  218.       pertry_timeout.tv_usec = 0;
  219.       total_timeout.tv_sec = timeout;
  220.       total_timeout.tv_usec = 0;
  221. -     addrlen = sizeof(struct sockaddr_in);
  222.       bcopy(hp->h_addr, (caddr_t) &server_addr.sin_addr, hp->h_length);
  223.       server_addr.sin_family = AF_INET;
  224.       server_addr.sin_port = 0;
  225. --- 365,370 ----
  226. ***************
  227. *** 377,383 ****
  228.       pertry_timeout.tv_usec = 0;
  229.       total_timeout.tv_sec = timeout;
  230.       total_timeout.tv_usec = 0;
  231. -     addrlen = sizeof(struct sockaddr_in);
  232.       bcopy(hp->h_addr, (caddr_t) &server_addr.sin_addr, hp->h_length);
  233.       server_addr.sin_family = AF_INET;
  234.       server_addr.sin_port = 0;
  235. --- 394,399 ----
  236. ***************
  237. *** 446,465 ****
  238.              ctime(&j)+4, tmp);
  239.   
  240.   #if !defined(hpux) || defined(__hpux) 
  241.           if (*(host = cutmpidlearr.uia_arr[i]->ui_utmp.ut_host)) {
  242. !         char *ptr, flg;
  243. !         for (ptr = tmp, flg = isdigit(*host) ? '\0' : '.'; 
  244. !              *host != '\0' && ptr < 
  245. !              &tmp[sizeof(cutmpidlearr.uia_arr[i]->ui_utmp.ut_host)] &&
  246. !              (*host != flg || ((host = strchr(host, ':')) != 0));
  247. !              host++) {
  248. !             if (*host == ':') flg = '\0';
  249. !             *ptr++ = isupper(*host) ? tolower(*host) : *host;
  250. !             *ptr = '\0';
  251.           }
  252.           (void) fprintf(stdout, " %-16.16s\n", tmp);
  253.           }
  254.           else 
  255.   #endif
  256.           (void) fprintf(stdout, "\n");
  257.           if ( i < cutmpidlearr.uia_cnt - 1 ) 
  258. --- 462,490 ----
  259.              ctime(&j)+4, tmp);
  260.   
  261.   #if !defined(hpux) || defined(__hpux) 
  262. + #define SIZ_UT_HOST sizeof(cutmpidlearr.uia_arr[i]->ui_utmp.ut_host)
  263.           if (*(host = cutmpidlearr.uia_arr[i]->ui_utmp.ut_host)) {
  264. !             char *dot, *col;
  265. !             (void) strncpy(tmp, host, SIZ_UT_HOST);
  266. !         tmp[SIZ_UT_HOST] = '\0';
  267. !         if (!isdigit(*tmp) && (dot = strchr(tmp, '.')) != NIL(char)) {
  268. !             if ((col = strchr(tmp, ':')) != NIL(char)) {
  269. !             if (col > dot)
  270. !                 (void) strcpy(dot, col);
  271. !             }
  272. !             else
  273. !             *dot = '\0';
  274.           }
  275. +         for (ptr = tmp; *ptr;)
  276. +              *ptr++ = isupper(*ptr) ? tolower(*ptr) : *ptr;
  277.           (void) fprintf(stdout, " %-16.16s\n", tmp);
  278.           }
  279.           else 
  280. + #undef SIZ_UT_HOST
  281.   #endif
  282.           (void) fprintf(stdout, "\n");
  283.           if ( i < cutmpidlearr.uia_cnt - 1 ) 
  284. ***************
  285. *** 526,535 ****
  286.   /* Malloc(): 
  287.    *    Memory checked malloc
  288.    */
  289. ! static char *
  290.   Malloc(nth)
  291.   unsigned nth;
  292.   {
  293.       char *ptr;
  294.       extern char *malloc();
  295.   
  296. --- 551,561 ----
  297.   /* Malloc(): 
  298.    *    Memory checked malloc
  299.    */
  300. ! static align_t
  301.   Malloc(nth)
  302.   unsigned nth;
  303.   {
  304. + #ifndef lint
  305.       char *ptr;
  306.       extern char *malloc();
  307.   
  308. ***************
  309. *** 538,543 ****
  310. --- 564,572 ----
  311.       exit(1);
  312.       }
  313.       return(ptr);
  314. + #else
  315. +     return(nth ? (align_t) 0 : (align_t) 0);
  316. + #endif
  317.   } /* end Malloc */
  318.   
  319.   /* do_timeout():
  320. -- 
  321. +------------------------------------------------------------------------+
  322. | Christos Zoulas         | 389 Theory Center, Electrical Engineering,   |
  323. | christos@ee.cornell.edu | Cornell University, Ithaca NY 14853.         |
  324. | christos@crnlee.bitnet  | Phone: Disconnected  |   Fax: (607) 254 4565 |
  325.