summaryrefslogtreecommitdiffstats
path: root/misc-utils/hostid.c
blob: 829c5b6724eba173d1065f99ac9efaac6f72b0cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Mitch DSouza - (m.dsouza@mrc-apu.cam.ac.uk) */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>

void main (int argc, char **argv)
{
    int verbose = 0;

    if(argc == 2 && strcmp(argv[1], "-v") == 0) {
	verbose = 1; 
	argc--;
	argv++;
    }

    if (argc==2) {
	if (sethostid(atoi(argv[1]))!=0) {
	    perror("sethostid");
	    exit(1);
	}
    } else if (argc==1)	{
	unsigned long id = gethostid();
	
	if(id && verbose) {
	    printf("Hostid is %lu (0x%lx)\n",id,id);
	} else if(id) {
	    printf("0x%lx\n", id);
	} else {
	    printf("Usage: %s hostid_number\n",*argv);
	}
    }
    exit(0);
}