forked from pool/util-linux
138 lines
3.2 KiB
Diff
138 lines
3.2 KiB
Diff
--- util-linux-2.12q/misc-utils/hostid.1
|
|
+++ util-linux-2.12q/misc-utils/hostid.1
|
|
@@ -0,0 +1,24 @@
|
|
+.TH hostid 1
|
|
+.SH NAME
|
|
+hostid \- set or print system's host id.
|
|
+.SH SYNTAX
|
|
+.B hostid
|
|
+[\-v] [\|\fIdecimal-id\fR\|]
|
|
+.SH DESCRIPTION
|
|
+.\".NXR "hostid command"
|
|
+The
|
|
+.B hostid
|
|
+command prints the current host id number in hexadecimal and both
|
|
+decimal and hexadecimal in parenthesis if the \-v option is given.
|
|
+This numeric value is expected to be unique across all hosts
|
|
+and is normally set to resemble the host's Internet address.
|
|
+
|
|
+Only the super-user can set the hostid by giving an argument. This value is
|
|
+stored in the file /etc/hostid and need only be performed once.
|
|
+
|
|
+.SH AUTHOR
|
|
+Hostid is written by Mitch DSouza \- (m.dsouza@mrc-apu.cam.ac.uk)
|
|
+
|
|
+.SH SEE ALSO
|
|
+gethostid(2), sethostid(2)
|
|
+
|
|
--- util-linux-2.12q/misc-utils/hostid.c
|
|
+++ util-linux-2.12q/misc-utils/hostid.c
|
|
@@ -0,0 +1,88 @@
|
|
+/* Program hostid. Changed on 7.10.1997 <ms@suse.de>
|
|
+ New: - Hostid 0 is not permitted.
|
|
+ - Set hostid dezimal or hexadezimal, both possible.
|
|
+ - Maximum Value for id is tested
|
|
+ - Wrong Parameters are caught
|
|
+ Nov 13 2003 - cleanup, mmj@suse.de
|
|
+ */
|
|
+
|
|
+#include <stdio.h>
|
|
+#include <stdlib.h>
|
|
+#include <string.h>
|
|
+#include <unistd.h>
|
|
+#include <errno.h>
|
|
+
|
|
+void usage(void);
|
|
+
|
|
+void usage()
|
|
+{
|
|
+ printf ("usage : hostid [-h] [-v] [<id>]\n\n"
|
|
+ "no options: print hostid as hexadecimal number\n"
|
|
+ "-h print this helptext\n"
|
|
+ "-v print hostid decimal and hexadecimal\n"
|
|
+ "<id> set the hostid to <id>\n\n"
|
|
+ "The id String can be specified as\n"
|
|
+ " - decimal number\n"
|
|
+ " - hexadecimal number preceded by 0x\n"
|
|
+ " - octal number preceded by 0 \n\n"
|
|
+ "Remarks:\n"
|
|
+ " - only root can set the hostid\n"
|
|
+ " - it's not possible to set the hostid to 0\n\n");
|
|
+}
|
|
+
|
|
+int main (int argc, char *argv[])
|
|
+{
|
|
+ long id;
|
|
+ int verbose = 0;
|
|
+
|
|
+ if (argc > 2) {
|
|
+ printf ("wrong arguments\n");
|
|
+ usage();
|
|
+ exit(1);
|
|
+ }
|
|
+
|
|
+ if (argc == 2 && strcmp(argv[1], "-h") == 0) {
|
|
+ usage();
|
|
+ exit(0);
|
|
+ }
|
|
+
|
|
+ if (argc == 2 && strcmp(argv[1], "-v") == 0) {
|
|
+ verbose = 1;
|
|
+ argc--;
|
|
+ argv++;
|
|
+ }
|
|
+
|
|
+ switch (argc) {
|
|
+ case 2:
|
|
+ id = strtol(argv[1], NULL, 0);
|
|
+ if (errno == ERANGE) {
|
|
+ printf ("Overflow: given string was out of range\n");
|
|
+ exit(1);
|
|
+ }
|
|
+
|
|
+ if (id == 0) {
|
|
+ printf ("value not possible: Abort\n");
|
|
+ usage();
|
|
+ exit(1);
|
|
+ }
|
|
+ if (sethostid(id) != 0) {
|
|
+ perror("sethostid");
|
|
+ exit(1);
|
|
+ }
|
|
+ break;
|
|
+
|
|
+ case 1:
|
|
+ id = gethostid();
|
|
+ if(id && verbose) {
|
|
+ printf("Hostid is %ld (0x%lx)\n", id, id);
|
|
+ } else if(id) {
|
|
+ printf("0x%lx\n", id);
|
|
+ } else {
|
|
+ printf ("Error while trying: gethostid\n");
|
|
+ exit(1);
|
|
+ }
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
--- util-linux-2.12q/misc-utils/Makefile
|
|
+++ util-linux-2.12q/misc-utils/Makefile
|
|
@@ -12,14 +12,14 @@
|
|
# Where to put man pages?
|
|
|
|
MAN1= cal.1 chkdupexe.1 ddate.1 logger.1 look.1 mcookie.1 \
|
|
- namei.1 rename.1 script.1 whereis.1
|
|
+ namei.1 rename.1 script.1 whereis.1 hostid.1
|
|
|
|
# Where to put binaries?
|
|
# See the "install" rule for the links. . .
|
|
|
|
BIN=
|
|
|
|
-USRBIN= cal chkdupexe ddate logger look mcookie \
|
|
+USRBIN= cal chkdupexe ddate hostid logger look mcookie \
|
|
namei rename script whereis
|
|
|
|
MAYBE= reset setterm
|