home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!dog.ee.lbl.gov!lbl.gov!vxwexplo
- From: leonid@amil.co.il (Leonid Rosenboim)
- Newsgroups: comp.os.vxworks
- Subject: re: Remote shells and the rcmd() function
- Date: Thu, 19 Nov 92 09:56:39 IST
- Organization: Lawrence Berkeley Laboratory, Berkeley CA
- Lines: 130
- Sender: vxwexplo@lbl.gov
- Message-ID: <9211190756.AA01239@amil.co.il>
- NNTP-Posting-Host: 128.3.112.16
- Originator: daemon@vxw.ee.lbl.gov
-
- ----------
- X-Sun-Data-Type: text
- X-Sun-Data-Description: text
- X-Sun-Data-Name: text
- X-Sun-Content-Lines: 8
-
- Here's an example of how to use rcmd() and a peice of useful code
- by its own right. The code is absolutely free.
- [ Please somebody archive it on "thor" ]
-
- -------------------------------------------
- R. S. T. Software Enterprises LTD., Israel
- Tel/Fax: +972-3-55-61-661
-
- ----------
- X-Sun-Data-Type: c-file
- X-Sun-Data-Name: hostRead.c
- X-Sun-Content-Lines: 111
-
- /*
- * hostRead - a single function module that loads the full host table
- * into vxWorks memory from the server it booted from. This info is
- * taken either from NIS (aka YP) or directly from /etc/hosts if NIS
- * is turned off.
- *
- * Written By Leonid Rosenboim, May 29 1991
- *
- * Added support for non-NIS host. Oct 22, 1991 by Leonid
- *
- */
- #include <vxWorks.h>
- #include <stdioLib.h>
- #include <strLib.h>
- #include <remLib.h>
- #include <sysLib.h>
- #include <hostLib.h>
-
- int
- hostRead()
- {
- char server[16], user[16] ;
- char line[80] ;
- char addr[20], name[4][16] ;
- char cmd[] = "ypcat hosts" ;
- char cmd2[] = "cat /etc/hosts" ;
- char *p ;
- FILE *f ;
- register lcount ;
- register int fd, i ;
-
- strcpy(server, sysBootHost) ;
- remCurIdGet( user, NULL ) ;
-
- printf("Host: %s, User: %s\n", server, user) ;
-
- fd = rcmd (server,
- /*remotePort*/ 514,
- /*localUser*/ user,
- /*remoteUser*/ user,
- cmd,
- /*fd2p*/ NULL ) ;
-
- if( fd < 0 ) {
- perror("rcmd") ;
- return(fd);
- }
-
- f = fdopen(fd, "r") ;
-
- lcount = 0 ;
-
- while( fgets(line, 79, f) == line ) {
-
- lcount ++ ;
-
- /* puts(line) ; */
-
- p = index(line, '#') ;
- if( p != NULL ) *p = '\0' ;
-
- fd = sscanf(line, "%s %s %s %s %s", addr, name[0], name[1], name[2],
- name[3] ) ;
-
- for( i=0, fd--; fd>0; fd--) {
- (void) hostAdd(name[i++], addr) ;
- } /*for*/
-
- } /* while */
-
- i = fclose(f);
-
- if ( lcount != 0 ) return(i) ;
-
- /* If no hosts where recorded we asume that NIS is not running */
-
- fd = rcmd (server,
- /*remotePort*/ 514,
- /*localUser*/ user,
- /*remoteUser*/ user,
- cmd2,
- /*fd2p*/ NULL ) ;
-
- if( fd < 0 ) {
- perror("rcmd") ;
- return(fd);
- }
-
- f = fdopen(fd, "r") ;
-
- while( fgets(line, 79, f) == line ) {
-
- lcount ++ ;
-
- /* puts(line) ; */
-
- p = index(line, '#') ;
- if( p != NULL ) *p = '\0' ;
-
- fd = sscanf(line, "%s %s %s %s %s", addr, name[0], name[1], name[2],
- name[3] ) ;
-
- for( i=0, fd--; fd>0; fd--) {
- (void) hostAdd(name[i++], addr) ;
- } /*for*/
-
- } /* while */
-
- i = fclose(f);
- return(i);
- }
-