fingerd.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 129 行
C
129 行
#ifndef lintstatic char *sccsid = "@(#)fingerd.c 4.1 (ULTRIX) 7/2/90";#endif lint/************************************************************************ * * * Copyright (c) 1988 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* * Copyright (c) 1983 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. *//*#ifndef lintchar copyright[] ="Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n";#endif not lint#ifndef lintstatic char sccsid[] = "fingerd.c 5.1 (Berkeley) 6/6/85";#endif not lint*//* * Finger server. */#include <sys/types.h>#include <netinet/in.h>#include <stdio.h>#include <ctype.h>main(argc, argv) char *argv[];{ register char *sp; char line[512]; struct sockaddr_in sin; int i, p[2], pid, status; FILE *fp; char *av[4]; i = sizeof (sin); if (getpeername(0, &sin, &i) < 0) fatal(argv[0], "getpeername"); if (fgets(line, sizeof(line), stdin) == NULL) exit(1); sp = line; av[0] = "finger"; i = 1; while (1) { while (isspace(*sp)) sp++; if (!*sp) break; if (*sp == '/' && (sp[1] == 'W' || sp[1] == 'w')) { sp += 2; av[i++] = "-l"; } if (*sp && !isspace(*sp)) { av[i++] = sp; while (*sp && !isspace(*sp)) sp++; *sp = '\0'; } } av[i] = 0; if (pipe(p) < 0) fatal(argv[0], "pipe"); if ((pid = fork()) == 0) { close(p[0]); if (p[1] != 1) { dup2(p[1], 1); close(p[1]); } execv("/usr/ucb/finger", av); _exit(1); } if (pid == -1) fatal(argv[0], "fork"); close(p[1]); if ((fp = fdopen(p[0], "r")) == NULL) fatal(argv[0], "fdopen"); while ((i = getc(fp)) != EOF) { if (i == '\n') putchar('\r'); putchar(i); } fclose(fp); while ((i = wait(&status)) != pid && i != -1) ; return(0);}fatal(prog, s) char *prog, *s;{ fprintf(stderr, "%s: ", prog); perror(s); exit(1);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?