home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slackwar / a / util / util-lin.2 / util-lin / util-linux-2.2 / misc-utils / hostid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-22  |  651 b   |  37 lines

  1. /* Mitch DSouza - (m.dsouza@mrc-apu.cam.ac.uk) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <errno.h>
  7. #include <getopt.h>
  8.  
  9. void main (int argc, char **argv)
  10. {
  11.     int verbose = 0;
  12.  
  13.     if(argc == 2 && strcmp(argv[1], "-v") == 0) {
  14.     verbose = 1; 
  15.     argc--;
  16.     argv++;
  17.     }
  18.  
  19.     if (argc==2) {
  20.     if (sethostid(atoi(argv[1]))!=0) {
  21.         perror("sethostid");
  22.         exit(1);
  23.     }
  24.     } else if (argc==1)    {
  25.     unsigned long id = gethostid();
  26.     
  27.     if(id && verbose) {
  28.         printf("Hostid is %lu (0x%lx)\n",id,id);
  29.     } else if(id) {
  30.         printf("0x%lx\n", id);
  31.     } else {
  32.         printf("Usage: %s hostid_number\n",*argv);
  33.     }
  34.     }
  35.     exit(0);
  36. }
  37.