[nfs] Re: PC-NFS user monitor
Geoff Arnold @ Sun BOS - R.H. coast near the top
geoff at hinode.East.Sun.COM
Wed Aug 15 04:25:11 AEST 1990
Archive-name: pcnfs-snoopd/10-Aug-90
Original-posting-by: geoff at hinode.East.Sun.COM (Geoff Arnold @ Sun BOS - R.H. coast near the top)
Original-subject: Re: PC-NFS user monitor
Reposted-by: emv at math.lsa.umich.edu (Edward Vielmetti)
[Reposted from comp.protocols.nfs.
Comments on this service to emv at math.lsa.umich.edu (Edward Vielmetti).]
Quoth perl at PacBell.COM (Richard Perlman) (in <1990Aug9.225014.27071 at PacBell.COM>):
#We are looking for a "monitor" program that can look at a network
#and report back the I.P. address and PC-NFS serial number of all
#systems running PC-NFS on a given net/sub-net. UNIX would be
#preferred, but, MS-DOS is OK.
#
#We could write this ourselves, but if something already exists...
Here you are....
-------------------->8----------------------------8<------------------
/*
* in.snoopd.c
*
* Hacked by Geoff Arnold from the source to in.tnamed.c
*
* This program snoops on UDP port 9 (the DISCARD port) looking for
* PC-NFS License Violation Detection broadcasts. If it sees one, it
* writes the serial number and IP address to stdout.
*
* Don't forget: make a backup copy of /etc/inetd.conf,
* then comment out the "discard" lines therein. Then send a SIGHUP
* to "inetd", so that it won't handle discards.
* Run this program with output redirected to a file. Later you can
* process the file with a simple shell script ("sort|uniq") and use
* "ping" and "arp" to identify the Ethernet addresses and hostnames.
*
* Possible enhancements: catch SIGHUP to exit cleanly; issue
* gethostbyaddr() and "SIOCGARP" ioctl() to get the name and Ethernet
* address info in real time.
*/
#include <stdio.h>
#include <strings.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#define BUFLEN 2000
main(argc, argv)
int argc;
char **argv;
{
int s, i;
struct sockaddr_in client;
int length, clientlength;
char iobuf[BUFLEN];
register char *buffer = iobuf;
/* the daemon is run by hand and never exits */
struct servent temp;
register struct servent *sp;
register struct protoent *pp;
struct sockaddr_in server;
/*
* Force non-blocking i/o to make sure everything is up to date
*/
fcntl(stdout, F_SETFL, O_NDELAY);
if((sp = getservbyname("discard","udp")) == NULL) {
fprintf(stderr,
"in.tnamed: UDP discard server not in /etc/services\n");
sp = &temp;
sp->s_port = htons(9);
}
if((pp = getprotobyname("udp")) == NULL) {
fprintf(stderr,
"in.tnamed: UDP protocol not in /etc/protocols\n");
exit(1);
}
if((s = socket(AF_INET, SOCK_DGRAM, pp->p_proto)) < 0) {
perror("in.snoopd: socket error");
exit(1);
}
bzero((char *)&server, sizeof(server));
server.sin_family = AF_INET;
server.sin_port = sp->s_port;
if(bind(s, &server, sizeof(server)) != 0) {
perror("in.snoopd: bind error");
exit(1);
}
fprintf(stderr, "in.snoopd: UDP discard snooper running\n");
for (;;) {
clientlength = sizeof(client);
length = recvfrom(s, buffer, BUFLEN, 0, &client, &clientlength);
if(length < 0) {
perror("in.snoopd: recvfrom error. Try in.snoopd -v ?");
continue;
}
#ifdef DEBUG
printf("in.snoopd: rcvd packet from %s\n",
inet_ntoa(client.sin_addr));
for(i = 0; i < length; i++)
printf("%02x", buffer[i]);
printf("\n");
for(i = 0; i < length; i++)
printf("%c ", isprint(buffer[i]) ? buffer[i] : '.');
printf("\n");
#endif
if(length == 14 && !strncmp(buffer, "PC-NFS", 6)) {
buffer[14] = '\0';
printf("%s %s\n", buffer, inet_ntoa(client.sin_addr));
}
}
}
-------------------->8----------------------------8<------------------
-- Geoff Arnold, PC-NFS architect, Sun Microsystems. (geoff at East.Sun.COM) --
** Back in the USA after a month in England. Most memorable scene: visiting **
** the "Duke Humfrey" library (part of the Bodleian in Oxford): wonderful **
** 15th century ceiling, incanabulae and desks, the latter with PCs on... **
More information about the Alt.sources
mailing list