#!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # README # Makefile # test.sh # vxRsh.c # This archive created: Tue Aug 27 11:13:22 1991 echo shar: extracting README '(1631 characters)' cat << \SHAR_EOF > README 8/25/91 vxRsh INSTALL: 1. Make sure that you have all the files: README test.sh Makefile vxRsh.h vxRsh.c vxRshd.c vxRsh.man 2. Check the Makefile, especially make sure that you cross-compile correctly. vxRshd.o - Should run on the target only. vxRsh.c generates two object files: vxRsh.o - Runs on UNIX. vxRsh_vw.o - Runs on VxWorks. 3. Check vxRsh.h make sure that the port number (VXRSH_PORT_NUM) is OK. check the defined flags. 4. Run the make. 5. To start the deamon: - Load it to the target. - call vxRshdInit(0). - sp vxRshdTest 6. run the test.sh script: - sh test.sh 7. To install man pages (vwman style): - make install BIND To add vxRsh to your kernel. - Update your makefile in $(VW)/config/all to include vxRshd (and vxRsh_vw if you need). - Add the following to your usrConfig.c /* * Spawn vxRshd. */ #ifdef INCLUDE_VXRSH if (vxRshdInit(0) == ERROR) printErr("can not spawn vxRshd - error = 0x%x.\n", errnoGet()); #endif /* INCLUDE_VXRSH */ - add to configAll.h #define INCLUDE_VXRSH /* vxRsh deamon */ BUGS Under vxWorks.4.0.X There is a possible problem when a log session is in progress and some one tries to login. In this case the rlogin succeed but the STDOUT is still own by the log session. A simple solution is to restart the shell and reinitialized STDOUT by heating control/c. This problem does not occur in vxWork.5.X. Probably rlogin automatically rediercts STDOUT... COMMENTS Any comments, BUG report, BUG fixes, spelling fixes are welcomed. Benny benny@vlss.amdahl.com SHAR_EOF if test 1631 -ne "`wc -c README`" then echo shar: error transmitting README '(should have been 1631 characters)' fi echo shar: extracting Makefile '(2643 characters)' cat << \SHAR_EOF > Makefile # vxRsh # Makefile # # HISTORY: # 09/01/89 bxs20: Created. # # Benny Schanider benny@vlss.amdahl.com # ## top-level VxWorks directory #VW = ../../ VW = /usr/vw/ #VW = /home/dimona/vw/ ## sub-directories VWH = $(VW)h/ H1 = $(VWH) H2 = $(VWH)net/ H3 = $(VWH)rpc/ H4 = $(VWH)68k/ H5 = $(VWH)sparc/ H6 = $(VWH)drv/ ## tools SH = /bin/sh CP = cp MANGEN = $(VW)unsupported/tools/mangen/mangen.sh MANGEN_FLAGS = -d -l -n LPR = more #LPR = lpr #LPR = cat ## COMPILE FLAGS TARGET = sun3 I = /usr/include INCLUDES = -I. -I$(H1) -I$(H2) CFLAGS = -g -target $(TARGET) $(INCLUDES) -DVXWORKS LINTFLAGS = -bun $(INCLUDES) ######################## vxRsh programs ####################################### SRC = vxRsh.c vxRshd.c HDR = vxRsh.h MORE_FILES = README test.sh VXRSH_PROG = vxRsh vxRshd.o vxRsh_vw.o default : $(VXRSH_PROG) all : clean default docs hardcopy shar install rel clean: /bin/rm -f *.o core vxRsh vxRsh.man *.nr vxRsh.p1 vxRsh.p2 vxRsh.p3 vxRshd.o : vxRshd.c $(H1)vxWorks.h $(H1)stdioLib.h $(H1)strLib.h \ $(H1)in.h $(H1)socket.h vxRsh.h vxRsh_vw.o : vxRsh.c $(H1)excLib.h $(H1)sysLib.h \ $(H1)in.h $(H1)stdioLib.h $(H1)symLib.h $(H1)ioLib.h \ $(H1)sysSymTbl.h $(H1)a_out.h vxRsh.h $(H1)taskLib.h \ $(H1)vxWorks.h cc -c $(CFLAGS) -o vxRsh_vw.o vxRsh.c vxRsh: vxRsh.c $I/sys/types.h $I/sys/socket.h \ $I/netinet/in.h $I/stdio.h \ $I/sys/time.h $I/sys/timeb.h $I/arpa/inet.h $I/string.h \ $I/sys/ioctl.h $I/sys/termio.h $I/math.h $I/signal.h \ $I/sys/signal.h $I/netdb.h vxRsh.h cc -g -I. -I/usr/include/ -o vxRsh vxRsh.c ${HOST_LIB_HOST} docs: vxRsh.nr vxRshd.nr vxRsh.nr : vxRsh.c $(MANGEN) /bin/rm -f mgr.out mg.out $(SH) $(MANGEN) -d -n 4 vxRsh.c mv mg.out vxRsh4.nr nroff -mangen vxRsh4.nr > vxRsh.man $(SH) $(MANGEN) $(MANGEN_FLAGS) 2 vxRsh.c mv mgr.out vxRsh_rtn.nr vxRshd.nr : vxRshd.c $(MANGEN) /bin/rm -f mgr.out mg.out $(SH) $(MANGEN) $(MANGEN_FLAGS) 2 vxRshd.c mv mg.out vxRshd.nr hardcopy : docs /usr/lib/tmac/tmac.angen printdoc printdoc : ls *.nr >file.names nroff -mangen `sort file.names` | $(LPR) $(LPR) $(MORE_FILES) /bin/rm -f file.names shar : Makefile docs /bin/rm -f vxRsh.shar shar -v -c README Makefile test.sh vxRsh.c > vxRsh.p1 shar -v -c vxRshd.c > vxRsh.p2 shar -v -c vxRsh.man vxRsh.h > vxRsh.p3 install : docs /usr/lib/tmac/tmac.angen $(CP) vxRsh4.nr $(VW)mansrc/man4/vxRsh.nr $(CP) vxRshd.nr $(VW)mansrc/man1/vxRshdLib.nr rel : shar /bin/rm /usr/sun7/benny/vwarc/vx/vxRsh/* cp vxRsh.p1 vxRsh.p2 vxRsh.p3 /usr/sun7/benny/vwarc/vx/vxRsh SHAR_EOF if test 2643 -ne "`wc -c Makefile`" then echo shar: error transmitting Makefile '(should have been 2643 characters)' fi echo shar: extracting test.sh '(428 characters)' cat << \SHAR_EOF > test.sh #!/bin/sh # # Test the module case $# in 1) ;; *) echo 'Usage: sh test.sh ' 1>&2; exit 2 esac vxRsh -w $1 echo $? vxRsh $1 printf \"Hello world\\n\" vxRsh -b $1 printf \"Hello world\\n\" vxRsh $1 printf \"%s\", \"Hello world\\n\" vxRsh -b $1 printf \"%s\", \"Hello world\\n\" /bin/rm -f stam* echo "Collecting log information please wait about 10 sec..." vxRsh -l "stam" $1 & sleep 10 vxRsh -e $1 cat stam* SHAR_EOF if test 428 -ne "`wc -c test.sh`" then echo shar: error transmitting test.sh '(should have been 428 characters)' fi echo shar: extracting vxRsh.c '(24001 characters)' cat << \SHAR_EOF > vxRsh.c /* vxRsh.c - vxRsh client source */ /* modification history * vxRsh.c * Implementation for rsh for vxWorks. This module implements * the client side * * Routines: * E main() - Runs under UNIX system * E vxRsh() - Client side. * S createClient() - Open the connection. * S vxRshIntr() - SIGINT & SIGQUIT ISR * S vxRshSigAlarm() - Time out ISR. * S vxRshTargetName() - Translate internet number to host name. * S vxRshUsage() - Prints the usage message. * * AUTHORS * Benny Schnaider benny@vlss.amdahl.com (408) 746-3440 * * HISTORY: * 10/07/91 bxs20: Support shell bypass. * 07/16/90 bxs20: Return codes were updated. * 09/01/89 bxs20: Created. */ /* SYNOPSIS vxRsh [-t] [-b] vxRsh [-t] [-l ] [-e] [-r] [-s] vxRsh [-h] DESCRIPTION vxRsh is a client server model based on text protocol. It is designed to enable remote execution of vxWorks commands from UNIX host. vxRsh typically uses the vxWorks shell for the remote execution however, by using the [-b] option the shell is bypassed. Bypassing the shell is essential to overcome the fact that the shell is not reentrant. In both cases (using or bypassing the shell) the STDOUT of the target is redirected to the connecting socket. vxRsh can also be used to log and filter the STDOUT of vxWorks to a UNIX file. Other features include hard and soft reset to a vxWorks target and a report of the peer name connected to the target locking the shell (e.g. rlogin, telnet). It requires a vxRshd server to run on the a vxWorks target. A subset of vxRsh can run on vxWorks. OPTIONS .RS 1 .IP [-b] Bypass target shell. The default of the server is to execute by passing to execute(2). Due to the fact that the shell is not reentrant, it implies that only one shell session can be active at the same time. The [-b] option is an alternative: the vxRshd receives the command, parses it and then activates a routine which corresponds to the first string in . By no means is this parsing as powerful as the vxWorks shell. For example you can not defined a new variable. The only format which is supported is: .CS [ [[,] ...]] .CE Where can be either a symbol or a number or a string (surrounded by quotes). Up to ten parameters are supported. Still, it should cover many cases. Note that vxWorks has a global STDOUT for all tasks. Using the [-b] option can be confusing to other tasks (e.g. active rlogin). Thus, it is recommended to use this option only for commands which take short execution time (you can always spawn a new task). .IP [-e] Stop log file. This option stops any active log session started with [-l] option. It can be useful when there is a confusion about where STDOUT is at a particular time. .IP [-h] Prints the usage message .IP [-l] Start log file. is used as a generic file name. The generic name is augmented with a string consisting of the month and day: (e.g. foo_Aug_22). vxRsh keeps writing all the shell standard output to this file. Each line is prefixed with the time stamp (client's local time). Once the server detects that the day has changed, the current log file is closed and a new file is opened. The code for this function is hidden in vxRshSetLine(2) and should be easy to customize. Note that if is "" the server dumps the output to it's STDOUT. The vxWorks shell must be unlocked when the logging is triggered. Thereafter, it can be locked or unlocked. Note that whenever the STDOUT is redirected (e.g rlogind) the logging stops. It resumes automatically after the redirection is restored (i.e. logout). Any new activation of [-l] option closes the previous log session (if it exists) and starts a new log session. One possible usage of this option is to start the client in the boot script of the target. This will ensure constant monitoring of the shell into a file (except for STDOUT redirection). In case of confusion about STDOUT you can always restart the shell and reinitialized STDOUT by heating control/c. .IP [-r] Target reset - hardware reset. Typically, the server calls a special BSP routine (HW reset) which rests the board. If your board does not support HW reset set the DEFINE flags in vxRsh.h to call reboot(BOOT_COLD). Note that the shell is not needed for this option and no questions are asked... .IP [-s] Target reset - software reset. Typically, the server calls reboot(BOOT_WARM_QUICK_AUTOBOOT). The shell is not required for this option. (i.e. It can be called even if the shell is locked e.g. rlogin). .IP [-t] Enables timeout for read/write socket operations when communicating with the server. This option can be useful when the target must response within a predefined time. The default for this option is OFF. [-t] Enables timeout. .IP [-w] Find the peer name that is locking shell (typically via rlogin or telnet). The server checks all the open file descriptors for a valid connected socket. The first socket found, is assume to be the one which is "engaged". The server decodes it's peer IP address. The client uses it's local data base to translate the IP address into a host name. This approach is neither "clean" nor suitable. However, it is less embracing than having a target connected from unknown location... It is possible to control the search in the FD table by modifying VXRSH_SEARCH_PEER_[LOW|HIGH] in vxRsh.h. .RE COMPATIBILITY This tool is based on the execute(2) routine. In vxWorks 4.0.1 this routine was defined as static. It is extern in 5.X. If your version does not allow linking to execute(2), you can either disable the "session" option by bypassing the shell or decode the address from the disassembler... The vxRsh client runs on UNIX host and on vxWorks target. However, the vxWorks version of the client is only a subset of the UNIX version. Currently, the server runs on vxWorks target only. RETURN The client returns one of the following values (These values are defined in vxRsh.h): [VXRSH_ERR_OK] No errors - Normal termination. [VXRSH_ERR_SYNTAX] Illegal syntax. [VXRSH_ERR_OPEN] Can not establish connection. [VXRSH_ERR_IO] Can not read or write. [VXRSH_ERR_INUSE] Target is already in use. [VXRSH_ERR_EXEC] Remote execution error. [VXRSH_ERR_ABORT] Operation aborted (e.g. ^C). [VXRSH_ERR_DECODE] Unable to decode return value. [VXRSH_ERR_TO] Time out error. [VXRSH_ERR_CLIENT_CMD] Illegal client protocol command. [VXRSH_ERR_CLIENT_EXEC] Client execution error. [VXRSH_ERR_TARGET] Target returns ERROR (-1). When called from a UNIX shell this value is assigned to a UNIX shell variable (e.g. $?). A special case is when the target returns: .CS "Sorry, this system is engaged". .CE For this case the server returns the IP address of the peer which is locking the shell (see above [-w]). EXAMPLES To execute the command "i" on beethoven (target name): vxRsh beethoven i Find who is logged to beethoven vxRsh -w beethoven To send a string (note that \\" escaping might depend on your (UNIX) shell): vxRsh beethoven "printf \\"Hello world\\"" To start logging the target STDOUT into a file stam_MMM_DD: vxRsh -l stam beethoven To stop logging the target STDOUT: vxRsh -e beethoven Bypass the target: vxRsh -b beethoven ls And finally to hardware reset the target: vxRsh -r beethoven BUS vxRsh is not compatible with the standard UNIX rsh. The search for the peer which is locking the vxWorks shell should be part of shellLib(1). AUTHORS Benny Schnaider: benny@vlss.amdahl.com (408) 746-3440 SEE ALSO vxRshd(2) vxRsh.h */ #ifdef VXWORKS #include #include #include #include #include #else /* VXWORKS */ #include #include #include #include #include #include #include #include #include #include #include #include #endif /* VXWORKS */ #include /* * Static data */ static int sock = -1; static struct sockaddr_in serverAddr; static struct sockaddr_in clientAddr; static int timeOutFlag = 0; /* 1: Use time out for I/O */ static int recordTimeFlag = 0; /* 1: Record time stamp */ static char vxLogFileName[FILE_NAME_LENGTH]; /* Holds the log file name */ /* * External routines */ extern void bcopy(); /* * Forward declarations */ static void vxRshIntr(); static void vxRshSigAlarm(); static int targetName(); static void vxRshUsage(); #ifdef VXWORKS static int alarm(); #endif /* VXWORKS */ #ifdef VXWORKS #define exit return #else /* VXWORKS */ /******************************************************************* * vxRshUsage * Print a usage message to stderr * * RETURN * VOID - The program exists with VXRSH_ERR_SYNTAX */ LOCAL void vxRshUsage(s) char *s; /* Program name */ { (void)fprintf(stderr, "%s Usage:\n", s); (void)fprintf(stderr, " [-t] [-l ] [-e] [-r] [-s] [-w] \n"); (void)fprintf(stderr, " [-t] [-b] \n"); (void)fprintf(stderr, " [-h]\n"); (void)fprintf(stderr, " [-b] - Bypass target shell\n"); (void)fprintf(stderr, " [-e] - Stop log file\n"); (void)fprintf(stderr, " [-h] - This message\n"); (void)fprintf(stderr, " [-l] - Start log file\n"); (void)fprintf(stderr, " [-r] - Target reset - hardware reset\n"); (void)fprintf(stderr, " [-s] - Target reset - software reset\n"); (void)fprintf(stderr, " [-t] - Enable time out\n"); (void)fprintf(stderr, " [-w] - Find who is locking the shell\n"); exit(1); } /* vxRshUsage() */ /*************************************************************************** * main * (UNIX only) * This is the main routine for UNIX: * - Parses the command line. * - Set static variable: e.g.: timeOutFlag, recordTimeFlag... * - Build the activation parameters for vxRsh. * * RETURNS: * OK/ERROR based on the return value from vxRsh. See vxRsh(4). * In case of parsing error vxRshUsage() will be called to exit. * */ main(argc, argv) int argc; /* */ char *argv[]; /* */ { char *protocolCommand = VXRSH_CMD_SESSION; char *target = NULL; char command[BUFF_LEN]; extern char *optarg; extern int optind; int st = 0; int c, i; int minParam = 2; /* * Parse command parameters */ while ((c = getopt(argc, argv, VXRSH_CMD_OPTIONS)) != -1) { switch(c) { case 'b': protocolCommand = VXRSH_CMD_BYPASS; break; case 'e': protocolCommand = VXRSH_CMD_END_LOG; /* recordTimeFlag++; */ minParam = 1; break; case 'l': protocolCommand = VXRSH_CMD_START_LOG; recordTimeFlag++; minParam = 1; (void)strcpy(vxLogFileName, optarg); break; case 'r': protocolCommand = VXRSH_CMD_HW_RESET; minParam = 1; break; case 's': protocolCommand = VXRSH_CMD_SW_RESET; minParam = 1; break; case 't': timeOutFlag++; break; case 'w': protocolCommand = VXRSH_CMD_WHO; minParam = 1; break; case '?': default: st++; break; } /* switch(c) */ } /* while(getopt()) */ if ((st != 0) || ((argc - optind) < minParam)) { vxRshUsage(argv[0]); } target = argv[optind]; command[0] = NULL; for (i = optind + 1; i < argc; i++) { (void)strcat(command, argv[i]); (void)strcat(command, " "); } /* * Init signals */ if ((signal(SIGINT, vxRshIntr) == SIG_ERR) || (signal(SIGQUIT, vxRshIntr) == SIG_ERR) || (signal(SIGALRM, vxRshSigAlarm) == SIG_ERR)) { perror("Can not install siganl()"); st = VXRSH_ERR_CLIENT_EXEC; } /* Signal installation */ if (st == OK) { st = vxRsh(target, command, protocolCommand); } return(st); } /* main() */ #endif /* VXWORKS */ /***************************************************************************** * vxRsh * * This is the main entry routine for the vxRsh client when running under * vxWorks. This routine implements the client side. Initially, a string * identifying the protocol is send to the server: * "SLS": Start log file. * "ELG": End log file. * "HRS": Hardware reset. * "SRS": Software reset. * "SES": DEFAULT. vxRsh session requires the vxWorks shell. * "BPS": Remote shell, bypasses vxWorks shell. * "WHO": Find who is locking the shell. * * The above strings are defined in vxRsh.h. Note that if no protocol is * selected (i.e. protocolCommand == NULL) the default - "SES" is used. * After the protocol string, the client sends the (activation * parameters) to the server and waits for an answer. The client continues * reading the server socket till EOF. Upon termination, the client decodes * the returned string and sets the return value. There are two types of * return values. They have different interpretation depending on the * environment (UNIX/vxWorks): *.RS 1 *.IP rtnVal: 4 *This is the value which was returned from the server. If *something goes wrong this value will be ERROR (-1). *.IP exitVal: *This value should be normally VXRSH_ERR_OK. In case of problems *exit value will be set according to one of the values as *specified in vxRsh.h *.RE * * Return value are decoded from a string which has the following format: *.CS * value = = <0xvalue> [(server - ) [client - ]] * * Example: * value = -1 = 0xffffffff (server - 4) client - 130.0.0.9 *.CE * where: *.RS 2 *.IP 4 *Is the return value from the remote executed command. In case of *server error is -1. *.IP *Error detected by the server: *.RS 1 *.IP [VXRSH_ERR_EXEC] 4 *The shell (i.e., execute()) returns ERROR. *.IP [VXRSH_ERR_INUSE] *The shell is in use. *.IP [VXRSH_ERR_CLIENT_CMD] *Protocol error (illegal command). *.RE *.IP *The suspicious peer which locks the shell. *.RE * * A special case of return value is when the server returns VXRSH_ERROR_INUSE. * In this case (shell in use) the server returns an IP address of the peer * which is presumably holding the shell. The client decodes this address * and translate it into host name string. * * RETURN: * For UNIX: exitVal. * For vxWorks: rtnVal. * */ vxRsh(targetName, command, protocolCommand) char *targetName; /* Target name */ char *command; /* VxWorks shell command */ char *protocolCommand; /* e.g. VXRSH_CMD_SESSION */ { char buff[BUFF_LEN]; char clientAddrBuff[BUFF_LEN]; register int buffInd; static int rtnVal, exitVal; int st, scanVal; int deamonVal, rtnValHex; /* * Initialization */ sock = -1; buff[0] = NULL; if (protocolCommand == NULL) { protocolCommand = VXRSH_CMD_SESSION; } /* * Establish connection. */ if ((sock = createClient(targetName)) == ERROR) { #ifdef VXWORKS return(ERROR); #else /* VXWORKS */ exit(VXRSH_ERR_OPEN); #endif /* VXWORKS */ } /* Can not establish the connection */ /* * Send input to the server */ (void)sprintf(buff, "%s %s\0", protocolCommand, command); if (write(sock, buff, strlen(buff) + 1) != (strlen(buff) + 1)) { (void)fprintf(stderr, "%s: Can not write to server\n", "vxRsh"); #ifdef VXWORKS return(ERROR); #else /* VXWORKS */ exit(VXRSH_ERR_IO); #endif /* VXWORKS */ } /* * Read results */ buffInd = 0; if (recordTimeFlag) { sprintf(buff, "Target name = %s\n", targetName); vxRshFilterLine(buff); } /* Use line filter */ if (timeOutFlag) { (void)alarm(VXRSH_TO); } /* timeOutFlag() */ while ((st = recv(sock, &buff[buffInd], 1, NULL)) != 0) { (void)alarm(0); /* Turn off the alarm */ if (st == -1) { (void)fprintf(stderr, "%s: Can not read from server\n", "vxRsh"); #ifdef VXWORKS return(ERROR); #else /* VXWORKS */ exit(VXRSH_ERR_IO); #endif /* VXWORKS */ } /* can not read from socket */ /* * Check for end of line */ if ((buffInd >= BUFF_LEN) || (buff[buffInd] == '\n')) { buff[buffInd + 1] = NULL; if (recordTimeFlag) { vxRshFilterLine(buff); } /* Use line filter */ else { (void)printf("%s", buff); } if (buffInd >= BUFF_LEN) { (void)fprintf(stderr, "Input buffer overflow\n"); } buffInd = 0; } else { buffInd = (buffInd + 1) % BUFF_LEN; } if (timeOutFlag) { (void)alarm(VXRSH_TO); } /* timeOutFlag() */ } /* Continue reading */ (void)alarm(0); /* * The return value from the deamon overrides the return value from * the target. */ clientAddrBuff[0] = NULL; scanVal = sscanf(buff, "value = %d = 0x%x (server - %d) client - %s", &rtnVal, &rtnValHex, &deamonVal, clientAddrBuff); switch (scanVal) { case 0: case 1: if (recordTimeFlag) { exitVal = VXRSH_ERR_OK; } else { exitVal = ERROR; } break; case 2: exitVal = VXRSH_ERR_OK; break; case 3: case 4: rtnVal = ERROR; exitVal = deamonVal; break; default: rtnVal = ERROR; exitVal = VXRSH_ERR_DECODE; } /* switch(scanVal) */ /* * If the machine is used find out who is using it. Translate internet * address to host name. */ if ((deamonVal == VXRSH_ERR_INUSE) && (clientAddrBuff[0] != NULL)) { if (vxRshTargetName(buff, clientAddrBuff) == OK) { (void)fprintf(stderr, "Target is used, apparently from: %s\n", buff); } /* vxRshTargetName() */ } /* Target in use */ (void)close(sock); if (recordTimeFlag) { sprintf(buff, ">> File closed\n"); vxRshFilterLine(buff); } /* Use line filter */ #ifdef VXWORKS return rtnVal; #else /* VXWORKS */ return(exitVal); #endif /* VXWORKS */ } /* vxRsh() */ /************************************************************************* * createClient * * Creates a TCP client socket. * Make sure that you like VXRSH_PORT_NUM. * * RETURN: * ERROR for error or - the socket created. */ LOCAL createClient(s) char *s; /* Target name */ { struct hostent *hp; #ifdef VXWORKS int intAdrs; #endif /* VXWORKS */ /* * zero out the socket structures */ (void)bzero((char *)&serverAddr, sizeof(serverAddr)); (void)bzero((char *)&clientAddr, sizeof(clientAddr)); /* Open the socket */ if ( (sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("can't open the socket"); #ifdef VXWORKS printErrno(errnoGet()); #endif /* VXWORKS */ return(ERROR); } /* * Fill serverAddr */ serverAddr.sin_family = AF_INET; serverAddr.sin_port = VXRSH_PORT_NUM; #ifdef VXWORKS if ( (intAdrs = hostGetByName(s)) == ERROR) { (void)fprintf(stderr, "%s: unknown host\n", s); (void)close(sock); return(ERROR); } (void)bcopy(&intAdrs, (char *)&serverAddr.sin_addr, sizeof(int)); #else /* VXWORKS */ if ( (hp = gethostbyname(s)) == NULL) { (void)fprintf(stderr, "%s: unknown host\n", s); (void)close(sock); return(ERROR); } (void)bcopy(hp->h_addr, (char *)&serverAddr.sin_addr, hp->h_length); #endif /* VXWORKS */ /* * Connect */ if (connect (sock, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) == ERROR) { perror("connect failed"); #ifdef VXWORKS printErrno(errnoGet()); #endif /* VXWORKS */ (void)close(sock); return(ERROR); } #ifdef VXWORKS /* setbuf(sock, NULL); */ #endif /* VXWORKS */ return(sock); } /* createClient */ /************************************************************************* * vxRshTargetName * * Translate the host addr to host name. * * RETURN: * OK/ERROR - Error if can not find the IP address in the data base. */ LOCAL vxRshTargetName(buff, hostAddr) char *buff; /* A buffer for return address */ char *hostAddr; /* IP address */ { #ifndef VXWORKS struct hostent *hp; struct sockaddr_in sin; #endif /* VXWORKS */ #ifdef VXWORKS if (hostGetByAddr(hostAddr, buff) == ERROR) { (void)fprintf(stderr, "%s: unknown host address\n", hostAddr); (void)close(sock); return(ERROR); } #else /* VXWORKS */ (void)bzero((char *)&sin, sizeof (sin)); sin.sin_addr.s_addr = inet_addr(hostAddr); if ((hp = gethostbyaddr((char *)&sin.sin_addr, sizeof (struct in_addr), AF_INET)) == NULL) { (void)fprintf(stderr, "%s: unknown host address\n", hostAddr); (void)close(sock); return(ERROR); } (void)strcpy(buff, (char *)hp -> h_name); #endif /* VXWORKS */ return(OK); } /* vxRshTargetName */ #ifdef VXWORKS /*************************************************************************** * alarm * NULL routine for vxWorks. * RETURN */ LOCAL alarm() { } /* alarm() */ /*************************************************************************** * vxRshFilterLine - vxWorks * * Note that for vxWorks this routine just prints the line to STDOUT. * * RETURN: * VOID * */ void vxRshFilterLine(inBuff) char *inBuff; /* Input buffer */ { (void)printf("%s", inBuff); } /* vxRshSetLine() */ #else /* VXWORKS */ /************************************************************************** * vxRshIntr * * Interrupt service routine. * - Close the socket (if open) * - exit. * * RETURN VOID. * */ LOCAL void vxRshIntr() { if (sock != -1) (void)close(sock); exit (VXRSH_ERR_ABORT); } /* vxRshIntr() */ /*************************************************************************** * vxRshSigAlarm * * Interrupt service routine. * - Close the socket (if open) * - exit. * * RETURN * VOID. */ LOCAL void vxRshSigAlarm() { if (sock != -1) (void)close(sock); (void)fprintf(stderr, "%s: time out error\n", "vxRsh"); exit (VXRSH_ERR_TO); } /* vxRshSigAlarm() */ /*************************************************************************** * vxRshFilterLine - UNIX * * This routine is used to alter the input string coming from the target. * Typically, it will just add a time stamp prefix to the line. * It is also used to determine the output file name. * The main idea is to keep one file per day. The file name consists of the * generic file name, as provided in the activation line [-l ], plus * a postfix which describes the date (month and day). If the time stamp * is changed, the old file (if exists) is closed and a new file is opened. * This routine should be farther customized per installation need. * * RETURN VOID * */ void vxRshFilterLine(inBuff) char *inBuff; /* Input buffer */ { char buff[100]; char buff1[10]; char logFile[FILE_NAME_LENGTH]; time_t tloc; static char fileNamePostfix[10] = NULL; /* * get and parse the current time of day */ (void)time(&tloc); (void)strcpy(buff, ctime(&tloc)); buff[strlen(buff) - 1] = NULL; /* * Check if a new file needs to be opened */ if (vxLogFileName[0] != NULL) { (void)strncpy(buff1, &buff[4], sizeof(buff1)); buff1[6] = NULL; buff1[3] = '_'; if (strcmp(fileNamePostfix, buff1)) { /* * Check if "old" log file needs to be closed */ if (fileNamePostfix[0] != NULL) { (void)printf(">> %s Log file closed\n", buff); (void)fclose(stdout); } /* Close old log file */ /* * Open input file */ (void)sprintf(logFile, "%s_%s", vxLogFileName, buff1); if ((freopen(logFile, "a", stdout)) == NULL) { perror(logFile); } (void)printf(">> %s Log file %s opened\n", buff, logFile); (void)strcpy(fileNamePostfix, buff1); } /* File open */ } /* Check if log file is used */ /* * Print the filtered message. */ buff[19] = NULL; (void)printf("%s : %s", &buff[11], inBuff); /* * Flush to assist debugging in crash. */ (void)fflush(stdout); } /* vxRshFilterLine() */ #endif /* VXWORKS */ SHAR_EOF if test 24001 -ne "`wc -c vxRsh.c`" then echo shar: error transmitting vxRsh.c '(should have been 24001 characters)' fi # End of shell archive exit 0