1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)fingerd.c	5.1 (Berkeley) 6/6/85";
  15: #endif not lint
  16: 
  17: /*
  18:  * Finger server.
  19:  */
  20: #include <sys/types.h>
  21: #include <netinet/in.h>
  22: 
  23: #include <stdio.h>
  24: #include <ctype.h>
  25: 
  26: main(argc, argv)
  27:     char *argv[];
  28: {
  29:     register char *sp;
  30:     char line[512];
  31:     struct sockaddr_in sin;
  32:     int i, p[2], pid, status;
  33:     FILE *fp;
  34:     char *av[4];
  35: 
  36:     i = sizeof (sin);
  37:     if (getpeername(0, &sin, &i) < 0)
  38:         fatal(argv[0], "getpeername");
  39:     line[0] = '\0';
  40:     gets(line);
  41:     sp = line;
  42:     av[0] = "finger";
  43:     i = 1;
  44:     while (1) {
  45:         while (isspace(*sp))
  46:             sp++;
  47:         if (!*sp)
  48:             break;
  49:         if (*sp == '/' && (sp[1] == 'W' || sp[1] == 'w')) {
  50:             sp += 2;
  51:             av[i++] = "-l";
  52:         }
  53:         if (*sp && !isspace(*sp)) {
  54:             av[i++] = sp;
  55:             while (*sp && !isspace(*sp))
  56:                 sp++;
  57:             *sp = '\0';
  58:         }
  59:     }
  60:     av[i] = 0;
  61:     if (pipe(p) < 0)
  62:         fatal(argv[0], "pipe");
  63:     if ((pid = fork()) == 0) {
  64:         close(p[0]);
  65:         if (p[1] != 1) {
  66:             dup2(p[1], 1);
  67:             close(p[1]);
  68:         }
  69:         execv("/usr/ucb/finger", av);
  70:         _exit(1);
  71:     }
  72:     if (pid == -1)
  73:         fatal(argv[0], "fork");
  74:     close(p[1]);
  75:     if ((fp = fdopen(p[0], "r")) == NULL)
  76:         fatal(argv[0], "fdopen");
  77:     while ((i = getc(fp)) != EOF) {
  78:         if (i == '\n')
  79:             putchar('\r');
  80:         putchar(i);
  81:     }
  82:     fclose(fp);
  83:     while ((i = wait(&status)) != pid && i != -1)
  84:         ;
  85:     return(0);
  86: }
  87: 
  88: fatal(prog, s)
  89:     char *prog, *s;
  90: {
  91: 
  92:     fprintf(stderr, "%s: ", prog);
  93:     perror(s);
  94:     exit(1);
  95: }

Defined functions

fatal defined in line 88; used 4 times
main defined in line 26; never used

Defined variables

copyright defined in line 8; never used
sccsid defined in line 14; never used
Last modified: 1985-06-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2309
Valid CSS Valid XHTML 1.0 Strict