home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff294.lzh / DNet / unix / client / dsoc.c < prev    next >
C/C++ Source or Header  |  1989-12-11  |  1KB  |  67 lines

  1.  
  2. /*
  3.  *    DSOC.C
  4.  *
  5.  *    DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved
  6.  *
  7.  *    DSOC [port#]
  8.  *
  9.  *      Connect to the specified port# .. Used to connect to a remote CLI
  10.  *    (s_shell server on the Amiga, which requires PIPE: to work, port 8196,
  11.  *    is the default)
  12.  *
  13.  *    Uses standard cooked mode instead of RAW mode.
  14.  */
  15.  
  16.  
  17. #include <sys/types.h>
  18. #include <sys/ioctl.h>
  19. #include <stdio.h>
  20. #include <sys/file.h>
  21. #include <signal.h>
  22. #include <errno.h>
  23. #include "../server/servers.h"
  24.  
  25. int fd;
  26. char buf[2048];
  27.  
  28. main(ac,av)
  29. char *av[];
  30. {
  31.     int n;
  32.     extern int handler();
  33.     int port = (av[1]) ? atoi(av[1]) : PORT_AMIGASHELL;
  34.  
  35.     puts("DSOC V1.01 11 March 1988 Connecting");
  36.     fd = DOpen(NULL, port, 0, 0);
  37.     if (fd < 0) {
  38.     perror("DOpen");
  39.     exit(1);
  40.     }
  41.     puts("Connected");
  42.     signal(SIGIO, handler);
  43.     fcntl(fd, F_SETOWN, getpid());
  44.     fcntl(fd, F_SETFL, FNDELAY|FASYNC);
  45.     while ((n = gread(0, buf, sizeof(buf))) > 0) {
  46.     gwrite(fd, buf, n);
  47.     }
  48.     fprintf(stderr, "EOF\n");
  49.     DEof(fd);
  50.     for (;;)
  51.     pause();
  52. }
  53.  
  54. handler()
  55. {
  56.     int n;
  57.     char buf[1024];
  58.  
  59.     while ((n = read(fd, buf, sizeof(buf))) > 0) 
  60.     write(1, buf, n);
  61.     if (n == 0) {
  62.     write(1, "REMEOF\n", 7);
  63.     exit(1);
  64.     }
  65. }
  66.  
  67.