2007-04-23 23:27:30 +02:00
|
|
|
Index: util-linux-ng-2.12r+git20070412/misc-utils/hostid.1
|
2007-04-12 18:31:42 +02:00
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2007-04-23 23:27:30 +02:00
|
|
|
+++ util-linux-ng-2.12r+git20070412/misc-utils/hostid.1
|
2006-12-19 00:18:10 +01:00
|
|
|
@@ -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)
|
|
|
|
+
|
2007-04-23 23:27:30 +02:00
|
|
|
Index: util-linux-ng-2.12r+git20070412/misc-utils/hostid.c
|
2007-04-12 18:31:42 +02:00
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2007-04-23 23:27:30 +02:00
|
|
|
+++ util-linux-ng-2.12r+git20070412/misc-utils/hostid.c
|
2006-12-19 00:18:10 +01:00
|
|
|
@@ -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;
|
|
|
|
+}
|
2007-04-23 23:27:30 +02:00
|
|
|
Index: util-linux-ng-2.12r+git20070412/misc-utils/Makefile.am
|
2007-04-12 18:31:42 +02:00
|
|
|
===================================================================
|
2007-04-23 23:27:30 +02:00
|
|
|
--- util-linux-ng-2.12r+git20070412.orig/misc-utils/Makefile.am
|
|
|
|
+++ util-linux-ng-2.12r+git20070412/misc-utils/Makefile.am
|
2007-04-12 18:31:42 +02:00
|
|
|
@@ -9,7 +9,7 @@ EXTRA_DIST = README.* \
|
|
|
|
bin_PROGRAMS =
|
2006-12-19 00:18:10 +01:00
|
|
|
|
2007-04-12 18:31:42 +02:00
|
|
|
usrbinexec_PROGRAMS = cal ddate logger look mcookie \
|
|
|
|
- namei script whereis
|
|
|
|
+ namei script whereis hostid
|
2006-12-19 00:18:10 +01:00
|
|
|
|
2007-04-12 18:31:42 +02:00
|
|
|
mcookie_LDADD = $(top_srcdir)/lib/libmd5.a
|
2006-12-19 00:18:10 +01:00
|
|
|
|
2007-04-12 18:31:42 +02:00
|
|
|
@@ -24,7 +24,7 @@ scriptreplay: scriptreplay.pl
|
|
|
|
CLEANFILES = chkdupexe scriptreplay
|
2006-12-19 00:18:10 +01:00
|
|
|
|
2007-04-12 18:31:42 +02:00
|
|
|
man_MANS = cal.1 chkdupexe.1 ddate.1 logger.1 look.1 mcookie.1 \
|
2007-04-23 23:27:30 +02:00
|
|
|
- namei.1 script.1 whereis.1 scriptreplay.1
|
|
|
|
+ namei.1 script.1 whereis.1 scriptreplay.1 hostid.1
|
2006-12-19 00:18:10 +01:00
|
|
|
|
2007-04-12 18:31:42 +02:00
|
|
|
if HAVE_NCURSES
|
|
|
|
cal_LDADD = -lncurses
|