home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / vxworks / 1034 < prev    next >
Encoding:
Text File  |  1992-11-18  |  2.9 KB  |  143 lines

  1. 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
  2. From: leonid@amil.co.il (Leonid Rosenboim)
  3. Newsgroups: comp.os.vxworks
  4. Subject: re: Remote shells and the rcmd() function
  5. Date: Thu, 19 Nov 92 09:56:39 IST
  6. Organization: Lawrence Berkeley Laboratory, Berkeley CA
  7. Lines: 130
  8. Sender: vxwexplo@lbl.gov
  9. Message-ID: <9211190756.AA01239@amil.co.il>
  10. NNTP-Posting-Host: 128.3.112.16
  11. Originator: daemon@vxw.ee.lbl.gov
  12.  
  13. ----------
  14. X-Sun-Data-Type: text
  15. X-Sun-Data-Description: text
  16. X-Sun-Data-Name: text
  17. X-Sun-Content-Lines: 8
  18.  
  19. Here's an example of how to use rcmd() and a peice of useful code
  20. by its own right. The code is absolutely free.
  21. [ Please somebody archive it on "thor" ]
  22.  
  23. -------------------------------------------
  24. R. S. T.  Software Enterprises LTD., Israel
  25. Tel/Fax: +972-3-55-61-661
  26.  
  27. ----------
  28. X-Sun-Data-Type: c-file
  29. X-Sun-Data-Name: hostRead.c
  30. X-Sun-Content-Lines: 111
  31.  
  32. /*
  33.  * hostRead - a single function module that loads the full host table
  34.  * into vxWorks memory from the server it booted from. This info is
  35.  * taken either from NIS (aka YP) or directly from /etc/hosts if NIS
  36.  * is turned off.
  37.  *
  38.  * Written By Leonid Rosenboim, May 29 1991
  39.  *
  40.  * Added support for non-NIS host. Oct 22, 1991 by Leonid
  41.  *
  42.  */
  43. #include <vxWorks.h>
  44. #include <stdioLib.h>
  45. #include <strLib.h>
  46. #include <remLib.h>
  47. #include <sysLib.h>
  48. #include <hostLib.h>
  49.  
  50. int
  51. hostRead()
  52. {
  53.     char server[16], user[16] ;
  54.     char line[80] ;
  55.     char addr[20], name[4][16] ;
  56.     char cmd[] = "ypcat hosts" ;
  57.     char cmd2[] = "cat /etc/hosts" ;
  58.     char *p ;
  59.     FILE *f ;
  60.     register lcount ;
  61.     register int fd, i ;
  62.  
  63.     strcpy(server, sysBootHost) ;
  64.     remCurIdGet( user, NULL ) ;
  65.  
  66.     printf("Host: %s, User: %s\n", server, user) ;
  67.  
  68.     fd = rcmd (server,
  69.     /*remotePort*/ 514,
  70.     /*localUser*/ user,
  71.     /*remoteUser*/ user,
  72.     cmd,
  73.     /*fd2p*/ NULL ) ;
  74.  
  75.     if( fd < 0 ) {
  76.     perror("rcmd") ;
  77.     return(fd);
  78.     }
  79.  
  80.     f = fdopen(fd, "r") ;
  81.  
  82.     lcount = 0 ;
  83.  
  84.     while( fgets(line, 79, f) == line ) {
  85.  
  86.     lcount ++ ;
  87.  
  88.     /* puts(line) ; */
  89.  
  90.     p = index(line, '#') ;
  91.     if( p != NULL ) *p = '\0' ;
  92.  
  93.     fd = sscanf(line, "%s %s %s %s %s", addr, name[0], name[1], name[2],
  94.         name[3] ) ;
  95.  
  96.     for( i=0, fd--; fd>0; fd--) {
  97.         (void) hostAdd(name[i++], addr) ;
  98.     } /*for*/
  99.  
  100.     } /* while */
  101.  
  102.     i = fclose(f);
  103.  
  104.     if ( lcount != 0 ) return(i) ;
  105.  
  106.     /* If no hosts where recorded we asume that NIS is not running */
  107.  
  108.     fd = rcmd (server,
  109.     /*remotePort*/ 514,
  110.     /*localUser*/ user,
  111.     /*remoteUser*/ user,
  112.     cmd2,
  113.     /*fd2p*/ NULL ) ;
  114.  
  115.     if( fd < 0 ) {
  116.     perror("rcmd") ;
  117.     return(fd);
  118.     }
  119.  
  120.     f = fdopen(fd, "r") ;
  121.  
  122.     while( fgets(line, 79, f) == line ) {
  123.  
  124.     lcount ++ ;
  125.  
  126.     /* puts(line) ; */
  127.  
  128.     p = index(line, '#') ;
  129.     if( p != NULL ) *p = '\0' ;
  130.  
  131.     fd = sscanf(line, "%s %s %s %s %s", addr, name[0], name[1], name[2],
  132.         name[3] ) ;
  133.  
  134.     for( i=0, fd--; fd>0; fd--) {
  135.         (void) hostAdd(name[i++], addr) ;
  136.     } /*for*/
  137.  
  138.     } /* while */
  139.  
  140.     i = fclose(f);
  141.     return(i);
  142. }
  143.