/* ** File Name: FINGER.C ** Product: TCPware for OpenVMS ** Version: V5.6 ** Edit Level: 18 ** ** Copyright (c) 2001, 2002 by ** Process Software LLC ** Framingham, Massachusetts ** ** This software is furnished under a license for use on a ** single computer system and may be copied only 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 except for use on such ** system and to one who agrees to these license terms. Title ** to and ownership of the software shall at all times remain ** in Process Software LLC's name. ** ** The information in this document is subject to change ** without notice and should not be construed as a commitment ** by Process Software LLC. Process Software LLC assumes no ** responsibility for any errors that may appear in this document. ** ** Note: ** This module is provided "as is" for example purposes ** only. It was provided by K. Wampler and implements a ** FINGER client (see RFC-1196) that can probe REMOTE ** hosts. ** ** ** To build on a VAX with VAX C: ** $ CC FINGER.C ** $ LINK FINGER,SYS$INPUT/OPTIONS ** TCPWARE:UCX$IPC.OLB/LIBRARY ** SYS$SHARE:VAXCRTL/SHARE ** ^Z ** $ FINGER :== $FINGER ** ** ** To build on an Alpha or VAX with DEC C: ** $ CC/PREFIX=ALL FINGER.C ** $ LINK FINGER ** $ FINGER :== $FINGER ** ** ** Then type: ** FINGER username@host ** - or - ** FINGER @host */ #include #include #include #include #include #include #include /* ** For the routines declared in and , make sure they're ** prefixed with "DECC$". */ #if defined(__DECC) && defined(__DECC_VER) && (__DECC_VER > 50300000) #pragma extern_prefix save #pragma extern_prefix "DECC$" #include #include #include #pragma extern_prefix restore #else #include #include #include #endif /* ** Finger port number. */ #define PORT 79 main(long argc, char **argv) { long status, idx, buflen, host_addr; short channel; #ifdef __DECC #pragma __member_alignment save #pragma __nomember_alignment #endif struct iosb { short status; short unsigned byte_count; long devdata; } net_iosb; struct itemlist { short int param_id; long int param_val; } ecb[2]; #ifdef __DECC #pragma __member_alignment restore #endif struct descriptor { long len; char *adr; } ecb_desc; char buffer[512]; struct hostent *he; static $DESCRIPTOR (cn_desc, "_TCP0:"); if (argc != 2) { fprintf(stderr,"%s\n%s\n", "%FINGER-F-BADUSE, incorrect parameter count", "-FINGER-I-USAGE, correct usage: finger user@node"); exit(0x10000000 | SS$_BADPARAM); } /* ** Parse user@host */ idx = strlen(argv[1]); while (idx > 0) { if (argv[1][idx-1] == '@') break; idx--; } if (idx < 1) { fprintf(stderr,"%s\n%s\n","%FINGER-F-MISSING, missing \"@\"", "-FINGER-I-USAGE, correct usage: finger user@node"); exit(0x10000000 | SS$_BADPARAM); } strncpy(buffer,argv[1],idx-1); buffer[idx-1] = 0; strcat(buffer,"\015\012"); buflen = strlen(buffer); he = gethostbyname(&argv[1][idx]); if (he == 0) { /* invalid host name, try internet address */ host_addr = inet_addr(&argv[1][idx]); if (host_addr == -1) exit(SS$_NOSUCHNODE); } else memcpy((char *)&host_addr,he->h_addr,he->h_length); /* ** Assign channel to TCP0. */ status = sys$assign(&cn_desc,&channel,0,0); if (!(status & 1)) { printf("%%FINGER-F-ASSIGN, failed to assign channel to _TCP0:\n"); exit(status); } /* ** Perform "active open". */ ecb[0].param_id = 2; ecb[0].param_val = host_addr; ecb[1].param_id = 3; ecb[1].param_val = PORT; ecb_desc.len = sizeof(ecb); ecb_desc.adr = (char *) &ecb; status = sys$qiow(0,channel, (IO$_SETMODE | IO$M_CTRL | IO$M_STARTUP), &net_iosb,0,0, 0,&ecb_desc,0,0,0,0); if (status & 1) status = net_iosb.status; if (!(status & 1)) { printf("%%FINGER-F-CONFAIL, connect failed\n"); exit(status); } /* ** Send the argument. */ status = sys$qiow(0,channel,IO$_WRITEVBLK,&net_iosb,0,0, &buffer,buflen,0,0,0,0); if (status & 1) status = net_iosb.status; if (!(status & 1)) { printf("%%FINGER-F-SENDERR, error sending user name\n"); exit(status); } /* ** Receive all data returned, forward to stdout, then exit. */ do { status = sys$qiow(0,channel,IO$_READVBLK,&net_iosb,0,0, &buffer,sizeof(buffer)-1,0,0,0,0); if (status & 1) status = net_iosb.status; if (status == SS$_VCCLOSED) break; if (!(status & 1)) { printf("\n%s\n","%FINGER-F-RCVERR, error while receiving data"); exit(status); } buffer[net_iosb.byte_count] = 0; printf("%s",buffer); } while (1); /* ** Normal disconnect. */ status = sys$qiow(0,channel, (IO$_SETMODE | IO$M_CTRL | IO$M_SHUTDOWN), &net_iosb,0,0, 0,0,0,0,0,0); exit(1); }