home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1667 < prev    next >
Text File  |  1990-12-28  |  4KB  |  135 lines

  1. Newsgroups: alt.sources
  2. From: geoff@hinode.East.Sun.COM (Geoff Arnold @ Sun BOS - R.H. coast near the top)
  3. Subject: [nfs] Re: PC-NFS user monitor
  4. Message-ID: <1990Aug14.182511.12616@math.lsa.umich.edu>
  5. Date: Tue, 14 Aug 90 18:25:11 GMT
  6.  
  7. Archive-name: pcnfs-snoopd/10-Aug-90
  8. Original-posting-by: geoff@hinode.East.Sun.COM (Geoff Arnold @ Sun BOS - R.H. coast near the top)
  9. Original-subject: Re: PC-NFS user monitor
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.protocols.nfs.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15. Quoth perl@PacBell.COM (Richard Perlman) (in <1990Aug9.225014.27071@PacBell.COM>):
  16. #We are looking for a "monitor" program that can look at a network
  17. #and report back the I.P. address and PC-NFS serial number of all
  18. #systems running PC-NFS on a given net/sub-net.  UNIX would be 
  19. #preferred, but, MS-DOS is OK.
  20. #
  21. #We could write this ourselves, but if something already exists...
  22.  
  23. Here you are....
  24. -------------------->8----------------------------8<------------------
  25.  
  26. /*
  27.  * in.snoopd.c
  28.  *
  29.  * Hacked by Geoff Arnold from the source to in.tnamed.c
  30.  *
  31.  * This program snoops on UDP port 9 (the DISCARD port) looking for
  32.  * PC-NFS License Violation Detection broadcasts. If it sees one, it
  33.  * writes the serial number and IP address to stdout.
  34.  *
  35.  * Don't forget: make a backup copy of /etc/inetd.conf,
  36.  * then comment out the "discard" lines therein. Then send a SIGHUP
  37.  * to "inetd", so that it won't handle discards.
  38.  * Run this program with output redirected to a file. Later you can
  39.  * process the file with a simple shell script ("sort|uniq") and use
  40.  * "ping" and "arp" to identify the Ethernet addresses and hostnames.
  41.  *
  42.  * Possible enhancements: catch SIGHUP to exit cleanly; issue 
  43.  * gethostbyaddr() and "SIOCGARP" ioctl() to get the name and Ethernet
  44.  * address info in real time.
  45.  */
  46. #include <stdio.h>
  47. #include <strings.h>
  48. #include <signal.h>
  49. #include <sys/time.h>
  50. #include <sys/types.h>
  51. #include <sys/socket.h>
  52. #include <netinet/in.h>
  53. #include <netdb.h>
  54. #include <unistd.h>
  55. #include <fcntl.h>
  56.  
  57. #define BUFLEN 2000
  58.  
  59. main(argc, argv)
  60.     int argc;
  61.     char **argv;
  62. {
  63.     int s, i;
  64.     struct sockaddr_in client;
  65.     int length, clientlength;
  66.     char iobuf[BUFLEN];
  67.     register char *buffer = iobuf;
  68.  
  69.         /* the daemon is run by hand and never exits */
  70.         struct servent temp;
  71.         register struct servent *sp;
  72.         register struct protoent *pp;
  73.         struct sockaddr_in server;
  74.  
  75. /*
  76.  * Force non-blocking i/o to make sure everything is up to date
  77.  */
  78.         fcntl(stdout, F_SETFL, O_NDELAY);
  79.  
  80.         if((sp = getservbyname("discard","udp")) == NULL) {
  81.             fprintf(stderr,
  82.                "in.tnamed: UDP discard server not in /etc/services\n");
  83.             sp = &temp;
  84.             sp->s_port = htons(9);
  85.         }
  86.         if((pp = getprotobyname("udp")) == NULL) {
  87.             fprintf(stderr,
  88.                 "in.tnamed: UDP protocol not in /etc/protocols\n");
  89.             exit(1);
  90.         }
  91.         if((s = socket(AF_INET, SOCK_DGRAM, pp->p_proto)) < 0) {
  92.             perror("in.snoopd: socket error");
  93.             exit(1);
  94.         }
  95.         bzero((char *)&server, sizeof(server));
  96.         server.sin_family = AF_INET;
  97.         server.sin_port = sp->s_port;
  98.         if(bind(s, &server, sizeof(server)) != 0) {
  99.             perror("in.snoopd: bind error");
  100.             exit(1);
  101.         }
  102.         fprintf(stderr, "in.snoopd: UDP discard snooper running\n");
  103.  
  104.     for (;;) {
  105.  
  106.         clientlength = sizeof(client);
  107.         length = recvfrom(s, buffer, BUFLEN, 0, &client, &clientlength);
  108.         if(length < 0) {
  109.             perror("in.snoopd: recvfrom error. Try in.snoopd -v ?");
  110.             continue;
  111.         }
  112. #ifdef DEBUG
  113.         printf("in.snoopd: rcvd packet from %s\n",
  114.                 inet_ntoa(client.sin_addr));
  115.         for(i = 0; i < length; i++)
  116.             printf("%02x", buffer[i]);
  117.         printf("\n");
  118.         for(i = 0; i < length; i++)
  119.             printf("%c ", isprint(buffer[i]) ? buffer[i] : '.');
  120.         printf("\n");
  121. #endif
  122.         if(length == 14 && !strncmp(buffer, "PC-NFS", 6)) {
  123.             buffer[14] = '\0';
  124.             printf("%s %s\n", buffer, inet_ntoa(client.sin_addr));
  125.         }
  126.     }
  127. }
  128.  
  129.  
  130. -------------------->8----------------------------8<------------------
  131. -- Geoff Arnold, PC-NFS architect, Sun Microsystems. (geoff@East.Sun.COM)   --
  132. ** Back in the USA after a month in England. Most memorable scene: visiting **
  133. ** the "Duke Humfrey" library (part of the Bodleian in Oxford): wonderful   **
  134. ** 15th century ceiling, incanabulae and desks, the latter with PCs on...   **
  135.