1997-09-16 19:59:02 +00:00
|
|
|
/* print the hexadecimal identifier for the current host
|
2004-01-21 23:08:09 +00:00
|
|
|
|
2011-01-01 11:37:32 +01:00
|
|
|
Copyright (C) 1997, 1999-2004, 2007-2011 Free Software Foundation, Inc.
|
1997-09-16 19:59:02 +00:00
|
|
|
|
2007-07-23 14:35:58 +02:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
1997-09-16 19:59:02 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-23 14:35:58 +02:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
1997-09-16 19:59:02 +00:00
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2007-07-23 14:35:58 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1997-09-16 19:59:02 +00:00
|
|
|
|
|
|
|
|
/* Written by Jim Meyering. */
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2004-09-21 22:01:50 +00:00
|
|
|
#include <getopt.h>
|
1997-09-16 19:59:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
|
|
#include "system.h"
|
|
|
|
|
#include "long-options.h"
|
|
|
|
|
#include "error.h"
|
2004-06-21 15:03:35 +00:00
|
|
|
#include "quote.h"
|
1997-09-16 19:59:02 +00:00
|
|
|
|
1999-03-31 04:11:35 +00:00
|
|
|
/* The official name of this program (e.g., no `g' prefix). */
|
|
|
|
|
#define PROGRAM_NAME "hostid"
|
|
|
|
|
|
2008-05-19 16:24:27 +02:00
|
|
|
#define AUTHORS proper_name ("Jim Meyering")
|
1999-03-31 04:11:35 +00:00
|
|
|
|
1999-01-25 14:33:38 +00:00
|
|
|
void
|
1997-09-16 19:59:02 +00:00
|
|
|
usage (int status)
|
|
|
|
|
{
|
2004-01-21 23:08:09 +00:00
|
|
|
if (status != EXIT_SUCCESS)
|
1997-09-16 19:59:02 +00:00
|
|
|
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
2009-08-22 18:56:06 +02:00
|
|
|
program_name);
|
1997-09-16 19:59:02 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf (_("\
|
2009-01-08 06:33:16 -07:00
|
|
|
Usage: %s [OPTION]\n\
|
1997-09-16 20:03:02 +00:00
|
|
|
Print the numeric identifier (in hexadecimal) for the current host.\n\
|
1997-09-16 19:59:02 +00:00
|
|
|
\n\
|
2009-01-08 06:33:16 -07:00
|
|
|
"), program_name);
|
2001-12-15 20:46:30 +00:00
|
|
|
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
|
|
|
|
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
2009-09-18 23:06:21 +01:00
|
|
|
emit_ancillary_info ();
|
1997-09-16 19:59:02 +00:00
|
|
|
}
|
|
|
|
|
exit (status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
2005-06-16 23:46:27 +00:00
|
|
|
unsigned int id;
|
1997-09-16 19:59:02 +00:00
|
|
|
|
2003-06-17 18:13:23 +00:00
|
|
|
initialize_main (&argc, &argv);
|
2008-06-03 08:34:09 +02:00
|
|
|
set_program_name (argv[0]);
|
1997-09-16 19:59:02 +00:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
|
textdomain (PACKAGE);
|
|
|
|
|
|
2000-05-07 14:53:15 +00:00
|
|
|
atexit (close_stdout);
|
|
|
|
|
|
2008-08-13 22:30:14 +02:00
|
|
|
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
2009-08-22 18:56:06 +02:00
|
|
|
usage, AUTHORS, (char const *) NULL);
|
2004-11-17 00:56:25 +00:00
|
|
|
if (getopt_long (argc, argv, "", NULL, NULL) != -1)
|
2004-09-21 22:01:50 +00:00
|
|
|
usage (EXIT_FAILURE);
|
1997-09-16 19:59:02 +00:00
|
|
|
|
2004-09-21 22:01:50 +00:00
|
|
|
if (optind < argc)
|
2004-06-17 13:09:21 +00:00
|
|
|
{
|
2004-09-21 22:01:50 +00:00
|
|
|
error (0, 0, _("extra operand %s"), quote (argv[optind]));
|
2002-08-31 08:52:10 +00:00
|
|
|
usage (EXIT_FAILURE);
|
1997-09-16 19:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id = gethostid ();
|
2005-06-16 23:46:27 +00:00
|
|
|
|
|
|
|
|
/* POSIX says gethostid returns a "32-bit identifier" but is silent
|
|
|
|
|
whether it's sign-extended. Turn off any sign-extension. This
|
|
|
|
|
is a no-op unless unsigned int is wider than 32 bits. */
|
|
|
|
|
id &= 0xffffffff;
|
|
|
|
|
|
|
|
|
|
printf ("%08x\n", id);
|
1997-09-16 19:59:02 +00:00
|
|
|
|
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
|
}
|