#! /bin/sh # Strip off top stuff and run this through /bin/sh to produce: # README # mudwho.c # Produced by Chris's stupid and simple sh shar. echo 'README' if [ -f README ] then echo README already exists; exit 1 fi sed 's/^//' >'README' <<'ENDIT' About mudwho: ------------- 'mudwho' is a small client program that connects to an RWHO server and grabs WHO lists of every mud that the RWHO server knows about. To compile, all you need to do is: cc mudwho.c -o mudwho You may define -DNO_HUGE_RESOLVER_CODE if you don't want to link in the resolver libraries; note that this means you'll have to specify hosts by number. Usage: ------ mudwho [-S server] [-P servport] [-u user] [-m mud] The server can be specified also by setting the environment variable MUDWHOSERVER. The port defaults to 6889, but can be also specified by setting the environment variable MUDWHOPORT. The options -u and -m will limit the output to whatever matches either the user (player) name given or the mud name given. (There is a timeout value of about a second, so if you're using a RWHO server that's far enough away that you have some net lag, you may get the entire WHO list output instead of just what you specified with -u or -m.) Ask around for the nearest (net-wise) RWHO server to you. For starters, try using moebius.math.okstate.edu (139.78.10.3). Any bug reports should go to the author, Marcus J. Ranum (mjr@decuac.dec.com). ENDIT echo 'mudwho.c' if [ -f mudwho.c ] then echo mudwho.c already exists; exit 1 fi sed 's/^//' >'mudwho.c' <<'ENDIT' /* Copyright (C) 1991, Marcus J. Ranum. All rights reserved. */ #ifndef lint static char RCSid[] = "$Header: /usr/users/mjr/hacks/umud/RWHO/RCS/mudwho.c,v 1.6 91/06/16 18:33:51 mjr Exp $"; #endif #include #include #include extern int errno; #include #include #include #include #include #include #include #define STREAMPORT 6889 #define ENVHOST "MUDWHOSERVER" #define ENVPORT "MUDWHOPORT" #ifndef NO_HUGE_RESOLVER_CODE extern struct hostent *gethostbyname(); #endif extern char *getenv(); extern char *optarg; main(ac,av) int ac; char *av[]; { struct sockaddr_in addr; struct hostent *hp; int fd; char *p; int red; char rbuf[1024]; char *srv = (char *)0; int portnum = STREAMPORT; char *checkwho = (char *)0; char *checkmud = (char *)0; srv = getenv(ENVHOST); if((p = getenv(ENVPORT)) != (char *)0) portnum = atoi(p); while((red = getopt(ac,av,"S:P:u:m:")) != EOF) { switch(red) { case 'S': srv = optarg; break; case 'P': portnum = atoi(optarg); break; case 'u': checkwho = optarg; break; case 'm': checkmud = optarg; break; default: exit(usage()); } } if(srv == (char *)0) { fprintf(stderr,"rwho server host must be provided [-S host]\n"); exit(1); } if(checkmud != (char *)0 && checkwho != (char *)0) { fprintf(stderr,"You can only search for one user or MUD entry\n"); exit(1); } p = srv; while(*p != '\0' && (*p == '.' || isdigit(*p))) p++; /* not all digits or dots */ if(*p != '\0') { #ifndef NO_HUGE_RESOLVER_CODE if((hp = gethostbyname(srv)) == (struct hostent *)0) { fprintf(stderr,"unknown host %s\n",srv); exit(1); } (void)bcopy(hp->h_addr,(char *)&addr.sin_addr,hp->h_length); #else fprintf(stderr,"must use numerical notation for host name\n"); exit(1); #endif } else { unsigned long f; if((f = inet_addr(srv)) == -1L) { fprintf(stderr,"unknown host %s\n",srv); exit(1); } (void)bcopy((char *)&f,(char *)&addr.sin_addr,sizeof(f)); } addr.sin_port = htons(portnum); addr.sin_family = AF_INET; if((fd = socket(AF_INET,SOCK_STREAM,0)) < 0) { perror("socket"); exit(1); } if(connect(fd,&addr,sizeof(addr)) < 0) { perror("connect"); exit(1); } /* send request if one */ if(checkmud != (char *)0 || checkwho != (char *)0) { char xuf[512]; int xlen; sprintf(xuf,"%s=%.30s", checkmud == (char *)0 ? "who" : "mud", checkmud == (char *)0 ? checkwho : checkmud); xlen = strlen(xuf) + 1; if(write(fd,xuf,xlen) != xlen) { perror("write to rwho server failed"); exit(1); } } while((red = read(fd,rbuf,sizeof(rbuf))) > 0) write(1,rbuf,red); exit(0); } usage() { fprintf(stderr,"usage: mudwho [-S server] [-P servport] [-u user] [-m mud]\n"); fprintf(stderr,"\twhere user is someone to scan for\n"); fprintf(stderr,"\tmud is a specific MUD to scan for\n"); fprintf(stderr,"\t%s and %s can be set in the environment\n",ENVPORT,ENVHOST); return(1); } ENDIT exit 0