/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <utmpx.h>
#include <ctype.h>
#include <netdb.h>
#include <syslog.h>
#include <fcntl.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
/*
* This version of Berkeley's rwhod has been modified to use IP multicast
* datagrams, under control of a new command-line option:
*
* rwhod -m causes rwhod to use IP multicast (instead of
* broadcast or unicast) on all interfaces that have
* the IFF_MULTICAST flag set in their "ifnet" structs
* (excluding the loopback interface). The multicast
* reports are sent with a time-to-live of 1, to prevent
* forwarding beyond the directly-connected subnet(s).
*
* rwhod -m <ttl> causes rwhod to send IP multicast datagrams with a
* time-to-live of <ttl>, via a SINGLE interface rather
* than all interfaces. <ttl> must be between 0 and
* MAX_MULTICAST_SCOPE, defined below. Note that "-m 1"
* is different than "-m", in that "-m 1" specifies
* transmission on one interface only.
*
* When "-m" is used without a <ttl> argument, the program accepts multicast
* rwhod reports from all multicast-capable interfaces. If a <ttl> argument
* is given, it accepts multicast reports from only one interface, the one
* on which reports are sent (which may be controlled via the host's routing
* table). Regardless of the "-m" option, the program accepts broadcast or
* unicast reports from all interfaces. Thus, this program will hear the
* reports of old, non-multicasting rwhods, but, if multicasting is used,
* those old rwhods won't hear the reports generated by this program.
*
* -- Steve Deering, Stanford University, February 1989
*/
static int multicast_scope;
/*
* Alarm interval. Don't forget to change the down time check in ruptime
* if this is changed.
*/
/*
* We communicate with each neighbor in
* a list constructed at the time we're
* started up. Neighbors are currently
* directly connected via a hardware interface.
*/
struct neighbor {
};
static int s;
static void onalrm(void);
static void getkmem(void);
int
{
char *cp;
if (getuid()) {
exit(1);
}
exit(1);
}
argv++;
argc--;
argv++;
argc--;
if (multicast_scope > MAX_MULTICAST_SCOPE) {
"in.rwhod: "
"ttl must not exceed %u\n",
exit(1);
}
} else {
}
} else {
goto usage;
}
argv++;
argc--;
}
if (argc > 0)
goto usage;
exit(1);
}
#ifndef DEBUG
if (fork())
exit(0);
/* CSTYLED */
{
(void) close(0);
(void) close(1);
(void) close(2);
(void) open("/", 0);
(void) dup2(0, 1);
(void) dup2(0, 2);
(void) setsid();
}
#endif
/*
* Establish host name as returned by system.
*/
exit(1);
}
*cp = '\0';
exit(1);
}
getkmem();
exit(1);
}
exit(1);
}
exit(1);
}
exit(1);
}
if (!configure(s))
exit(1);
onalrm();
for (;;) {
if (cc <= 0) {
continue;
}
continue;
}
#ifdef notdef
continue;
}
#endif
continue;
continue;
continue;
}
/*
* Rather than truncating and growing the file each time,
* use ftruncate if size is less than previous size.
*/
if (whod < 0) {
continue;
}
#if defined(_LITTLE_ENDIAN)
/* CSTYLED */
{
/* undo header byte swapping before writing to file */
for (i = 0; i < 3; i++)
for (i = 0; i < n; i++) {
we++;
}
}
#endif
}
/* NOTREACHED */
return (1);
}
/*
* Check out host name for unprintables
* and other funnies before allowing a file
* to be created. Sorry, but blanks aren't allowed.
*/
static int
{
int size = 0;
/*
* We shouldn't assume the name is NUL terminated, so bound the
* checks at the size of the whod structures wd_hostname field.
*/
(*name != '\0')) {
return (0);
}
/*
* Fail the verification if NULL name or it wasn't NUL terminated.
*/
}
static int utmpxtime;
static int utmpxent;
static int alarmcount;
static void
onalrm(void)
{
int i;
int utmpxsize = 0;
int entries;
if (alarmcount % 10 == 0)
getkmem();
alarmcount++;
utmpxsize = 0;
goto done;
}
}
utmpxbegin = utmpx;
setutxent();
cnt = 0;
endutxent();
for (i = 0; i < utmpxent; i++) {
/*
* XXX - utmpx name and line lengths should
* be here
*/
break;
we++;
}
}
}
/*
* The test on utmpxent looks silly---after all, if no one is
* logged on, why worry about efficiency?---but is useful on
* (e.g.) compute servers.
*/
exit(1);
}
for (i = 0; i < utmpxent; i++) {
we++;
}
exit(1);
}
for (i = 0; i < 3; i++)
if (multicast_mode == SCOPED_MULTICAST) {
(struct sockaddr *)&multicast_addr,
sizeof (multicast_addr));
if (multicast_mode == PER_INTERFACE_MULTICAST &&
/*
* Select the outgoing interface for the multicast.
*/
sizeof (struct in_addr)) < 0) {
"onalrm: setsockopt IP_MULTICAST_IF: %m");
exit(1);
}
(struct sockaddr *)&multicast_addr,
sizeof (multicast_addr));
} else {
}
}
exit(1);
}
done:
(void) alarm(AL_INTERVAL);
}
static void
getkmem(void)
{
endutxent();
}
/*
* Figure out device configuration and select
* networks which deserve status information.
*/
static boolean_t
configure(int s)
{
char *buf;
int n;
int numifs;
unsigned bufsize;
if (multicast_mode == SCOPED_MULTICAST) {
unsigned char ttl;
sizeof (mreq)) < 0) {
"configure: setsockopt IP_ADD_MEMBERSHIP: %m");
return (B_FALSE);
}
sizeof (ttl)) < 0) {
"configure: setsockopt IP_MULTICAST_TTL: %m");
return (B_FALSE);
}
return (B_TRUE);
}
return (B_FALSE);
}
return (B_FALSE);
}
"configure: ioctl (get interface configuration): %m");
return (B_FALSE);
}
/* Skip all logical interfaces */
continue;
break;
}
continue;
continue;
continue;
}
continue;
}
"configure: ioctl (get interface flags): %m");
continue;
}
}
if (multicast_mode == PER_INTERFACE_MULTICAST &&
/*
* Skip interfaces that have matching subnets i.e.
* (addr & netmask) are identical.
* Such interfaces are connected to the same
* physical wire.
*/
break;
}
}
continue;
sizeof (mreq)) < 0) {
"configure: "
"setsockopt IP_ADD_MEMBERSHIP: %m");
continue;
}
continue;
}
continue;
}
"configure: ioctl (get dstaddr): %m");
continue;
}
/* we assume addresses are all the same size */
}
"configure: ioctl (get broadaddr): %m");
continue;
}
/* we assume addresses are all the same size */
}
/* gag, wish we could get rid of Internet dependencies */
/*
* Avoid adding duplicate broadcast and pt-pt destinations
* to the list.
*/
break;
}
}
continue;
}
return (B_TRUE);
}
#ifdef DEBUG
/* ARGSUSED */
static ssize_t
{
int nsz;
(void) printf("load %4.2f, %4.2f, %4.2f\n",
(void) printf("%-*.*s %s:%s %.12s",
nsz,
nsz,
w->wd_hostname,
ctime(&t)+4);
else
(void) printf(" ");
}
(void) printf("\n");
}
return (0);
}
static char *
{
return (resbuf);
}
minutes %= 60;
hours %= 24;
if (days > 0) {
} else {
}
return (resbuf);
}
#endif