C   77

chup

Guest on 27th April 2022 01:48:41 AM

  1. #include <stdio.h>
  2. #include <hosttab.h>
  3.  
  4. main (argc, argv)
  5. char **argv;
  6. {
  7.         int     fd;
  8.         int     addr;
  9.         unsigned high, low;
  10.         long    uptime;
  11.         int     days, hours, minutes, seconds;
  12.  
  13.         if (argc == 1) {
  14.                 fprintf (stderr, "Usage: chup host [ host ] ...\n");
  15.                 exit (1);
  16.         }
  17.  
  18.         while (--argc) {
  19.                 argv++;
  20.                 addr = chaos_addr(*argv, 0);
  21.                 if ((fd = chopen(addr, "UPTIME", 0, 0, 0, 0, 0)) < 0) {
  22.                         fprintf (stderr, "Host %s (0%o) is not responding\n", *argv, addr);
  23.                         continue;
  24.                 }
  25.  
  26.                 /* 32 bits of uptime */
  27.  
  28.                 read (fd, &low, 2);
  29.                 read (fd, &high, 2);
  30.                 uptime = ((long)high << 16) + (long)low;
  31.  
  32.                 days = uptime / (60L*60L*60L*24L);
  33.                 uptime %= (60L*60L*60L*24L);
  34.                 hours = uptime / (60L*60L*60L);
  35.                 uptime %= (60L*60L*60L);
  36.                 minutes = uptime / (60L*60L);
  37.                 uptime %= (60L*60L);
  38.                 seconds = (uptime + 30L) / 60L;
  39.                 printf("%s (0%o) has been up for %d day%s, ",
  40.                         *argv, addr, days, (days != 1 ? "s" : ""));
  41.                 printf("%d hour%s, %d minute%s, %d second%s\n",
  42.                         hours, (hours != 1 ? "s" : ""),
  43.                         minutes, (minutes != 1 ? "s" : ""),
  44.                         seconds, (seconds != 1 ? "s" : ""));
  45.         }
  46. }

Raw Paste


Login or Register to edit or fork this paste. It's free.