Retire MINIX hostaddr(1)
Change-Id: I30c7b5fe4c96ea040c3eea46f1dc4d9bd135745d
This commit is contained in:
parent
407c396431
commit
035c234ade
@ -374,7 +374,7 @@
|
|||||||
./usr/bin/head minix-base
|
./usr/bin/head minix-base
|
||||||
./usr/bin/hexdump minix-base
|
./usr/bin/hexdump minix-base
|
||||||
./usr/bin/host minix-base
|
./usr/bin/host minix-base
|
||||||
./usr/bin/hostaddr minix-base
|
./usr/bin/hostaddr minix-base obsolete
|
||||||
./usr/bin/id minix-base
|
./usr/bin/id minix-base
|
||||||
./usr/bin/ifconfig minix-base obsolete
|
./usr/bin/ifconfig minix-base obsolete
|
||||||
./usr/bin/ifdef minix-base
|
./usr/bin/ifdef minix-base
|
||||||
|
@ -292,7 +292,7 @@
|
|||||||
./usr/libdata/debug/usr/bin/head.debug minix-debug debug
|
./usr/libdata/debug/usr/bin/head.debug minix-debug debug
|
||||||
./usr/libdata/debug/usr/bin/hexdump.debug minix-debug debug
|
./usr/libdata/debug/usr/bin/hexdump.debug minix-debug debug
|
||||||
./usr/libdata/debug/usr/bin/host.debug minix-debug debug
|
./usr/libdata/debug/usr/bin/host.debug minix-debug debug
|
||||||
./usr/libdata/debug/usr/bin/hostaddr.debug minix-debug debug
|
./usr/libdata/debug/usr/bin/hostaddr.debug minix-debug debug,obsolete
|
||||||
./usr/libdata/debug/usr/bin/id.debug minix-debug debug
|
./usr/libdata/debug/usr/bin/id.debug minix-debug debug
|
||||||
./usr/libdata/debug/usr/bin/ifconfig.debug minix-debug debug,obsolete
|
./usr/libdata/debug/usr/bin/ifconfig.debug minix-debug debug,obsolete
|
||||||
./usr/libdata/debug/usr/bin/ifdef.debug minix-debug debug
|
./usr/libdata/debug/usr/bin/ifdef.debug minix-debug debug
|
||||||
|
@ -140,7 +140,7 @@
|
|||||||
./usr/man/man1/hexdump.1 minix-man
|
./usr/man/man1/hexdump.1 minix-man
|
||||||
./usr/man/man1/history.1 minix-man
|
./usr/man/man1/history.1 minix-man
|
||||||
./usr/man/man1/host.1 minix-man
|
./usr/man/man1/host.1 minix-man
|
||||||
./usr/man/man1/hostaddr.1 minix-man
|
./usr/man/man1/hostaddr.1 minix-man obsolete
|
||||||
./usr/man/man1/hostname.1 minix-man
|
./usr/man/man1/hostname.1 minix-man
|
||||||
./usr/man/man1/id.1 minix-man
|
./usr/man/man1/id.1 minix-man
|
||||||
./usr/man/man1/if.1 minix-man obsolete
|
./usr/man/man1/if.1 minix-man obsolete
|
||||||
|
@ -11,7 +11,7 @@ SUBDIR= arp at backup \
|
|||||||
eject \
|
eject \
|
||||||
fix format fsck.mfs \
|
fix format fsck.mfs \
|
||||||
gcov-pull host \
|
gcov-pull host \
|
||||||
hostaddr ifdef \
|
ifdef \
|
||||||
intr irdpd isoread \
|
intr irdpd isoread \
|
||||||
loadkeys loadramdisk logger look lp \
|
loadkeys loadramdisk logger look lp \
|
||||||
lpd lspci mail MAKEDEV \
|
lpd lspci mail MAKEDEV \
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
PROG= hostaddr
|
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
|
@ -1,43 +0,0 @@
|
|||||||
.TH HOSTADDR 1
|
|
||||||
.SH NAME
|
|
||||||
hostaddr \- show ethernet address, IP address or hostname
|
|
||||||
.SH SYNOPSIS
|
|
||||||
.B hostaddr
|
|
||||||
.RB [ \-eiah ]
|
|
||||||
.RB [ \-E
|
|
||||||
.IR eth-device ]
|
|
||||||
.RB [ \-I
|
|
||||||
.IR ip-device ]
|
|
||||||
.SH DESCRIPTION
|
|
||||||
Without any of the
|
|
||||||
.B \-eia
|
|
||||||
options,
|
|
||||||
.B hostaddr
|
|
||||||
shows the ethernet address, IP address and hostname of the local host on one
|
|
||||||
line in the given order. With options only the wanted fields are shown,
|
|
||||||
still in the same order, not in option order.
|
|
||||||
.SH OPTIONS
|
|
||||||
.TP
|
|
||||||
.B \-e
|
|
||||||
Show the ethernet address.
|
|
||||||
.TP
|
|
||||||
.B \-i
|
|
||||||
Show the IP address.
|
|
||||||
.TP
|
|
||||||
.B \-a
|
|
||||||
Show the fully qualified hostname. The IP address is shown if it
|
|
||||||
can't be translated to a host name. This usually indicates that the
|
|
||||||
DNS reverse address translation tables are incomplete or that
|
|
||||||
the name daemon couldn't be contacted.
|
|
||||||
.TP
|
|
||||||
.B \-h
|
|
||||||
Set the hostname of the machine if the caller is the superuser. (Used at
|
|
||||||
boot time by the network initialization scripts.)
|
|
||||||
.SH "SEE ALSO"
|
|
||||||
.BR ifconfig (8),
|
|
||||||
.BR dhcpd (8),
|
|
||||||
.BR nonamed (8),
|
|
||||||
.BR inet (8),
|
|
||||||
.BR boot (8).
|
|
||||||
.SH AUTHOR
|
|
||||||
Kees J. Bot (kjb@cs.vu.nl)
|
|
@ -1,300 +0,0 @@
|
|||||||
/*
|
|
||||||
hostaddr.c
|
|
||||||
|
|
||||||
Fetch an ip and/or ethernet address and print it on one line.
|
|
||||||
|
|
||||||
Created: Jan 27, 1992 by Philip Homburg
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/utsname.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#include <net/netlib.h>
|
|
||||||
#include <net/hton.h>
|
|
||||||
#include <net/gen/ether.h>
|
|
||||||
#include <net/gen/eth_io.h>
|
|
||||||
#include <net/gen/if_ether.h>
|
|
||||||
#include <net/gen/in.h>
|
|
||||||
#include <net/gen/inet.h>
|
|
||||||
#include <net/gen/ip_io.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <net/gen/socket.h>
|
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <arpa/nameser.h>
|
|
||||||
#include <resolv.h>
|
|
||||||
#include <net/gen/dhcp.h>
|
|
||||||
|
|
||||||
#include <minix/paths.h>
|
|
||||||
|
|
||||||
char *prog_name;
|
|
||||||
|
|
||||||
char DHCPCACHE[]=_PATH_DHCPCACHE;
|
|
||||||
|
|
||||||
int main( int argc, char *argv[] );
|
|
||||||
void usage( void );
|
|
||||||
|
|
||||||
int main(argc, argv)
|
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{
|
|
||||||
int c;
|
|
||||||
int first_print;
|
|
||||||
int a_flag, e_flag, i_flag, h_flag;
|
|
||||||
char *E_arg, *I_arg;
|
|
||||||
int do_ether, do_ip, do_asc_ip, do_hostname;
|
|
||||||
char *eth_device, *ip_device;
|
|
||||||
int eth_fd, ip_fd;
|
|
||||||
int result;
|
|
||||||
nwio_ethstat_t nwio_ethstat;
|
|
||||||
nwio_ipconf_t nwio_ipconf;
|
|
||||||
struct hostent *hostent;
|
|
||||||
char *hostname, *domain;
|
|
||||||
char nodename[2*256];
|
|
||||||
dhcp_t dhcp;
|
|
||||||
|
|
||||||
first_print= 1;
|
|
||||||
prog_name= argv[0];
|
|
||||||
|
|
||||||
a_flag= e_flag= h_flag = i_flag= 0;
|
|
||||||
E_arg= I_arg= NULL;
|
|
||||||
|
|
||||||
while((c= getopt(argc, argv, "?aheE:iI:")) != -1)
|
|
||||||
{
|
|
||||||
switch(c)
|
|
||||||
{
|
|
||||||
case '?':
|
|
||||||
usage();
|
|
||||||
case 'a':
|
|
||||||
if (a_flag)
|
|
||||||
usage();
|
|
||||||
a_flag= 1;
|
|
||||||
break;
|
|
||||||
case 'h':
|
|
||||||
if (h_flag)
|
|
||||||
usage();
|
|
||||||
h_flag= 1;
|
|
||||||
break;
|
|
||||||
case 'e':
|
|
||||||
if (e_flag)
|
|
||||||
usage();
|
|
||||||
e_flag= 1;
|
|
||||||
break;
|
|
||||||
case 'E':
|
|
||||||
if (E_arg)
|
|
||||||
usage();
|
|
||||||
E_arg= optarg;
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
if (i_flag)
|
|
||||||
usage();
|
|
||||||
i_flag= 1;
|
|
||||||
break;
|
|
||||||
case 'I':
|
|
||||||
if (I_arg)
|
|
||||||
usage();
|
|
||||||
I_arg= optarg;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(optind != argc)
|
|
||||||
usage();
|
|
||||||
|
|
||||||
do_ether= e_flag;
|
|
||||||
if (E_arg)
|
|
||||||
eth_device= E_arg;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
eth_device= getenv("ETH_DEVICE");
|
|
||||||
if (!eth_device)
|
|
||||||
eth_device= ETH_DEVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
do_ip= i_flag;
|
|
||||||
do_asc_ip= a_flag;
|
|
||||||
do_hostname= h_flag;
|
|
||||||
if (I_arg)
|
|
||||||
ip_device= I_arg;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ip_device= getenv("IP_DEVICE");
|
|
||||||
if (!ip_device)
|
|
||||||
ip_device= IP_DEVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!do_ether && !do_ip && !do_asc_ip && !do_hostname)
|
|
||||||
do_ether= do_ip= do_asc_ip= 1;
|
|
||||||
|
|
||||||
if (do_ether)
|
|
||||||
{
|
|
||||||
eth_fd= open(eth_device, O_RDWR);
|
|
||||||
if (eth_fd == -1)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: Unable to open '%s': %s\n",
|
|
||||||
prog_name, eth_device, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
result= ioctl(eth_fd, NWIOGETHSTAT, &nwio_ethstat);
|
|
||||||
if (result == -1)
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"%s: Unable to fetch ethernet address: %s\n",
|
|
||||||
prog_name, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
printf("%s%s", first_print ? "" : " ",
|
|
||||||
ether_ntoa(&nwio_ethstat.nwes_addr));
|
|
||||||
first_print= 0;
|
|
||||||
}
|
|
||||||
if (do_ip || do_asc_ip || do_hostname)
|
|
||||||
{
|
|
||||||
ip_fd= open(ip_device, O_RDWR);
|
|
||||||
if (ip_fd == -1)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: Unable to open '%s': %s\n",
|
|
||||||
prog_name, ip_device, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
result= ioctl(ip_fd, NWIOGIPCONF, &nwio_ipconf);
|
|
||||||
if (result == -1)
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"%s: Unable to fetch IP address: %s\n",
|
|
||||||
prog_name,
|
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setuid(getuid());
|
|
||||||
|
|
||||||
if (do_ip)
|
|
||||||
{
|
|
||||||
printf("%s%s", first_print ? "" : " ",
|
|
||||||
inet_ntoa(*(struct in_addr *)&nwio_ipconf.nwic_ipaddr));
|
|
||||||
first_print= 0;
|
|
||||||
}
|
|
||||||
if (do_asc_ip || do_hostname)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
int r;
|
|
||||||
dhcp_t d;
|
|
||||||
u8_t *data;
|
|
||||||
size_t hlen, dlen;
|
|
||||||
|
|
||||||
hostname= NULL;
|
|
||||||
domain= NULL;
|
|
||||||
|
|
||||||
/* Use a reverse DNS lookup to get the host name. This is
|
|
||||||
* the preferred method, but often fails due to lazy admins.
|
|
||||||
*/
|
|
||||||
hostent= gethostbyaddr((char *)&nwio_ipconf.nwic_ipaddr,
|
|
||||||
sizeof(nwio_ipconf.nwic_ipaddr), AF_INET);
|
|
||||||
if (hostent != NULL) hostname= hostent->h_name;
|
|
||||||
|
|
||||||
if (hostname != NULL)
|
|
||||||
{
|
|
||||||
/* Reverse DNS works. */
|
|
||||||
}
|
|
||||||
else if ((fd= open(DHCPCACHE, O_RDONLY)) == -1)
|
|
||||||
{
|
|
||||||
if (errno != ENOENT)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: %s: %s\n",
|
|
||||||
prog_name, DHCPCACHE, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Try to get the hostname from the DHCP data. */
|
|
||||||
while ((r= read(fd, &d, sizeof(d))) == sizeof(d))
|
|
||||||
{
|
|
||||||
if (d.yiaddr == nwio_ipconf.nwic_ipaddr) break;
|
|
||||||
}
|
|
||||||
if (r < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: %s: %s\n",
|
|
||||||
prog_name, DHCPCACHE, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (r == sizeof(d))
|
|
||||||
{
|
|
||||||
if (dhcp_gettag(&d, DHCP_TAG_HOSTNAME,
|
|
||||||
&data, &hlen))
|
|
||||||
hostname= (char *) data;
|
|
||||||
|
|
||||||
if (dhcp_gettag(&d, DHCP_TAG_DOMAIN,
|
|
||||||
&data, &dlen))
|
|
||||||
domain= (char *) data;
|
|
||||||
|
|
||||||
if (hostname != NULL) hostname[hlen] = 0;
|
|
||||||
if (domain != NULL) domain[dlen] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hostname != NULL)
|
|
||||||
{
|
|
||||||
if (strchr(hostname, '.') != NULL)
|
|
||||||
{
|
|
||||||
domain= strchr(hostname, '.');
|
|
||||||
*domain++ = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* No host name anywhere. Use the IP address. */
|
|
||||||
hostname= inet_ntoa(*(struct in_addr *)
|
|
||||||
&nwio_ipconf.nwic_ipaddr);
|
|
||||||
domain= NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(nodename, hostname);
|
|
||||||
if (domain != NULL)
|
|
||||||
{
|
|
||||||
strcat(nodename, ".");
|
|
||||||
strcat(nodename, domain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (do_asc_ip)
|
|
||||||
{
|
|
||||||
printf("%s%s", first_print ? "" : " ", nodename);
|
|
||||||
first_print= 0;
|
|
||||||
}
|
|
||||||
if (do_hostname)
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
if ((fp= fopen("/etc/hostname.file", "w")) == NULL
|
|
||||||
|| fprintf(fp, "%s\n", nodename) == EOF
|
|
||||||
|| fclose(fp) == EOF)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: /etc/hostname.file: %s\n",
|
|
||||||
prog_name, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!first_print) printf("\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void usage()
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"Usage: %s -[eiah] [-E <eth-device>] [-I <ip-device>]\n",
|
|
||||||
prog_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user