[BACK]Return to rusers.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rusers

Diff for /src/usr.bin/rusers/rusers.c between version 1.10 and 1.11

version 1.10, 2001/02/05 21:41:07 version 1.11, 2001/02/17 16:52:23
Line 36 
Line 36 
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/socket.h>  #include <sys/socket.h>
 #include <netdb.h>  #include <netdb.h>
   #include <err.h>
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
 #include <rpc/rpc.h>  #include <rpc/rpc.h>
Line 52 
Line 53 
 #include <rpcsvc/rnusers.h>     /* Old version */  #include <rpcsvc/rnusers.h>     /* Old version */
   
 #define MAX_INT 0x7fffffff  #define MAX_INT 0x7fffffff
   /* Preferred formatting */
 #define HOST_WIDTH 20  #define HOST_WIDTH 20
 #define LINE_WIDTH 8  #define LINE_WIDTH 8
 char *argv0;  #define NAME_WIDTH 8
   
 struct timeval timeout = { 25, 0 };  struct timeval timeout = { 25, 0 };
 int longopt;  int longopt;
Line 65 
Line 67 
         struct in_addr addr;          struct in_addr addr;
 } *hosts;  } *hosts;
   
   extern char *__progname;
   
 int  int
 search_host(struct in_addr addr)  search_host(struct in_addr addr)
 {  {
Line 85 
Line 89 
 {  {
         struct host_list *hp;          struct host_list *hp;
   
         if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) {          if (!(hp = (struct host_list *)malloc(sizeof(struct host_list))))
                 fprintf(stderr, "%s: no memory.\n", argv0);                  err(1, NULL);
                 exit(1);  
         }  
         hp->addr.s_addr = addr.s_addr;          hp->addr.s_addr = addr.s_addr;
         hp->next = hosts;          hp->next = hosts;
         hosts = hp;          hosts = hp;
Line 97 
Line 99 
 int  int
 rusers_reply(char *replyp, struct sockaddr_in *raddrp)  rusers_reply(char *replyp, struct sockaddr_in *raddrp)
 {  {
         int x, idle;          int x, idle, i;
         char date[32], idle_time[64], remote[64], local[64];          char date[32], idle_time[64], remote[UT_HOSTSIZE + 1];
           char local[HOST_WIDTH + LINE_WIDTH + 2];
           char utline[UT_LINESIZE + 1];
         struct hostent *hp;          struct hostent *hp;
         utmpidlearr *up = (utmpidlearr *)replyp;          utmpidlearr *up = (utmpidlearr *)replyp;
         char *host;          char *host, *tmp;
         int days, hours, minutes, seconds;          int days, hours, minutes, seconds;
   
         if (search_host(raddrp->sin_addr))          if (search_host(raddrp->sin_addr))
Line 121 
Line 125 
                 printf("%-*.*s ", HOST_WIDTH, HOST_WIDTH, host);                  printf("%-*.*s ", HOST_WIDTH, HOST_WIDTH, host);
   
         for (x = 0; x < up->uia_cnt; x++) {          for (x = 0; x < up->uia_cnt; x++) {
                 strncpy(date,                  strlcpy(date,
                     &(ctime((time_t *)&(up->uia_arr[x]->ui_utmp.ut_time))[4]),                      &(ctime((time_t *)&(up->uia_arr[x]->ui_utmp.ut_time))[4]),
                     sizeof(date)-1);                      sizeof(date));
                   /* ctime() adds a trailing \n.  Trimming it is only
                    * mandatory if the output formatting changes.
                    */
                   if ((tmp = strchr(date, '\n')) != NULL)
                           *tmp = '\0';
   
                 idle = up->uia_arr[x]->ui_idle;                  idle = up->uia_arr[x]->ui_idle;
                 sprintf(idle_time, "   :%02d", idle);                  sprintf(idle_time, "   :%02d", idle);
Line 152 
Line 161 
   
                 strncpy(remote, up->uia_arr[x]->ui_utmp.ut_host,                  strncpy(remote, up->uia_arr[x]->ui_utmp.ut_host,
                     sizeof(remote)-1);                      sizeof(remote)-1);
                   remote[sizeof(remote) - 1] = '\0';
                 if (strlen(remote) != 0)                  if (strlen(remote) != 0)
                         sprintf(remote, "(%.16s)",                          snprintf(remote, UT_HOSTSIZE + 1, "(%.16s)",
                             up->uia_arr[x]->ui_utmp.ut_host);                              up->uia_arr[x]->ui_utmp.ut_host);
   
                 if (longopt) {                  if (longopt) {
                         strncpy(local, host, sizeof(local));                          strncpy(local, host, sizeof(local));
                         local[HOST_WIDTH + LINE_WIDTH + 1 -                          strncpy(utline, up->uia_arr[x]->ui_utmp.ut_line,
                             strlen(up->uia_arr[x]->ui_utmp.ut_line) - 1] = 0;                              UT_LINESIZE);
                           utline[sizeof(utline) - 1] = '\0';
                           i = sizeof(local) - strlen(utline) - 2;
                           if (i < 0)
                                   i = 0;
                           local[i] = '\0';
                         strcat(local, ":");                          strcat(local, ":");
                         strncat(local, up->uia_arr[x]->ui_utmp.ut_line,                          strlcat(local, utline, sizeof(local));
                                 sizeof (local) - strlen (local) - 1);  
                         local[sizeof (local) - 1] = 0;  
   
 #define MAXNAME 8  
                         printf("%-*.*s %-*.*s %-12.12s %8s %.18s\n",                          printf("%-*.*s %-*.*s %-12.12s %8s %.18s\n",
                             MAXNAME, UT_NAMESIZE,                              NAME_WIDTH, UT_NAMESIZE,
                             up->uia_arr[x]->ui_utmp.ut_name,                              up->uia_arr[x]->ui_utmp.ut_name,
                             HOST_WIDTH+LINE_WIDTH+1, HOST_WIDTH+LINE_WIDTH+1,                              HOST_WIDTH+LINE_WIDTH+1, HOST_WIDTH+LINE_WIDTH+1,
                             local, date, idle_time, remote);                              local, date, idle_time, remote);
Line 191 
Line 203 
         struct hostent *hp;          struct hostent *hp;
   
         hp = gethostbyname(host);          hp = gethostbyname(host);
         if (hp == NULL) {          if (hp == NULL)
                 fprintf(stderr, "%s: unknown host \"%s\"\n",                  errx(1, "unknown host \"%s\"", host);
                         argv0, host);  
                 exit(1);  
         }  
   
         rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp");          rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp");
         if (rusers_clnt == NULL) {          if (rusers_clnt == NULL) {
                 clnt_pcreateerror(argv0);                  clnt_pcreateerror(__progname);
                 exit(1);                  exit(1);
         }          }
   
         bzero((char *)&up, sizeof(up));          bzero((char *)&up, sizeof(up));
         if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL,          if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL,
             xdr_utmpidlearr, &up, timeout) != RPC_SUCCESS) {              xdr_utmpidlearr, &up, timeout) != RPC_SUCCESS) {
                 clnt_perror(rusers_clnt, argv0);                  clnt_perror(rusers_clnt, __progname);
                 exit(1);                  exit(1);
         }          }
         addr.sin_addr.s_addr = *(int *)hp->h_addr;          addr.sin_addr.s_addr = *(int *)hp->h_addr;
Line 223 
Line 232 
         clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE,          clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE,
             RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr,              RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr,
             (char *)&up, rusers_reply);              (char *)&up, rusers_reply);
         if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {          if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT)
                 fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));                  errx(1, "%s", clnt_sperrno(clnt_stat));
                 exit(1);  
         }  
 }  }
   
 void  void
 usage(void)  usage(void)
 {  {
         fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0);          fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", __progname);
         exit(1);          exit(1);
 }  }
   
Line 242 
Line 249 
         int ch;          int ch;
         extern int optind;          extern int optind;
   
         if (!(argv0 = strrchr(argv[0], '/')))  
                 argv0 = argv[0];  
         else  
                 argv0++;  
   
         while ((ch = getopt(argc, argv, "al")) != -1)          while ((ch = getopt(argc, argv, "al")) != -1)
                 switch (ch) {                  switch (ch) {
                 case 'a':                  case 'a':

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11