* The Remote User Information Daemon
*
* (c) 1997--2010 Martin Mares <mj@ucw.cz>
- *
- * This software may be freely distributed and used according to the terms
- * of the GNU General Public License. See file COPYING in any of the GNU packages.
*/
#include <stdio.h>
#include <utmp.h>
#include <signal.h>
#include <dirent.h>
-#include <asm/types.h>
#include <errno.h>
#include "net.h"
if (name)
{
if (! (h = gethostbyname(name)))
- die("%s: %m", name);
+ die("Failed to resolve %s", name);
}
else
h = NULL;
}
static void
-scan_utmp(struct rywho_pkt *p, time_t now)
+scan_utmp(struct nwho_pkt *p, time_t now)
{
struct utmp *u;
int cnt = 0;
}
static void
-scan_load(struct rywho_pkt *p)
+scan_load(struct nwho_pkt *p)
{
int n, i, j[6];
char buf[256];
}
static void
-make_pkt(struct rywho_pkt *pkt)
+make_pkt(struct nwho_pkt *pkt)
{
bzero(pkt, sizeof(pkt));
pkt->magic = htonl(NWHO_MAGIC);
}
static void
-save_pkt(char *name, struct rywho_pkt *pkt, int len)
+save_pkt(char *name, struct nwho_pkt *pkt, int len)
{
int fd = open(name, O_WRONLY | O_CREAT, 0666);
if (fd < 0)
static void
receive(void)
{
- int r, al;
- struct rywho_pkt pkt;
+ int r;
+ struct nwho_pkt pkt;
struct sockaddr_in sa;
- int n = sizeof(struct rywho_pkt) - MAX_USERS * sizeof(struct userinfo);
+ socklen_t al = sizeof(sa);
+ int n = sizeof(struct nwho_pkt) - MAX_USERS * sizeof(struct userinfo);
struct hostrec *e;
struct hostent *h;
char *c;
alarm(DEFAULT_PRUNE_TIME);
- al = sizeof(sa);
r = recvfrom(sock, &pkt, sizeof(pkt), 0, (struct sockaddr *) &sa, &al);
alarm(0);
now = time(NULL);
static void
local_scan(void)
{
- struct rywho_pkt pkt;
+ struct nwho_pkt pkt;
static char hostname[64];
make_pkt(&pkt);
static void
daemonize(void)
{
+ pid_t pid = fork();
+ if (pid < 0)
+ die("Fork failed: %m");
+ if (pid)
+ exit(0);
+
close(0);
close(1);
close(2);
static void
client(char *serv)
{
- struct rywho_pkt pkt;
+ struct nwho_pkt pkt;
net_init(serv);
utmpname(UTMP_FILE);
int
main(int argc, char **argv)
{
- int pid;
-
- if (argc != 1 && argc != 2)
- {
- fprintf(stderr, "Usage: nwhod [<server>]\n");
- return 1;
- }
- pid = fork();
- if (pid < 0)
- {
- perror("fork");
- return 1;
- }
- if (pid)
- return 0;
if (argc == 2)
client(argv[1]);
else if (argc == 1)
server();
- return 1;
+ else
+ {
+ fprintf(stderr, "Usage: nwhod [<server>]\n");
+ return 1;
+ }
+ return 0;
}