home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / comm / net / amitcp / amitcp-2.2 / src / util / online / online.c next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  4.9 KB  |  215 lines

  1. static char rcsid[] = 
  2.   "$Id: online.c,v 1.6 1993/08/10 20:46:23 jraja Exp $";
  3. /*
  4.  * online.c --- Send an online/offline command to a SANA-II device
  5.  *
  6.  * Author: ppessi <Pekka.Pessi@hut.fi>
  7.  *
  8.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>,
  9.  *            Helsinki University of Technology, Finland.
  10.  *            All rights reserved. 
  11.  *
  12.  * Created      : Sat Feb 20 14:15:07 1993 ppessi
  13.  * Last modified: Tue Aug 10 23:40:00 1993 jraja
  14.  */
  15.  
  16. static const char version[] = "$VER: online 2.0 (13.8.93)";
  17.  
  18. char copyright[] =
  19.   "Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>\n"
  20.                    "Helsinki University of Technology, Finland.\n"
  21.                    "All rights reserved.\n";
  22.  
  23. /****** netutil.doc/offline *************************************************
  24. *
  25. *  NAME
  26. *       Offline - put a SANA-II device offline 
  27. *
  28. *  TEMPLATE
  29. *       Offline DEV=DEVICE devicename[/unit] [UNIT unit]
  30. *
  31. *  DESCRIPTION 
  32. *       Offline sends the S2_OFFLINE command to the given SANA-II device
  33. *       driver and unit. This command is normally used to disconnect SANA-II
  34. *       device driver from the network adapter hardware. Device driver does
  35. *       not accept any more read or write requests.
  36. *
  37. *  EXAMPLES 
  38. *       This command puts the SLIP offline, which frees then the serial port
  39. *       to your use.
  40. *
  41. *       OFFLINE slip.device/1
  42. *
  43. *  SEE ALSO
  44. *       Online, sana2.device/S2_OFFLINE
  45. *
  46. *****************************************************************************
  47. *
  48. */
  49.  
  50. /****** netutil.doc/online **************************************************
  51. *
  52. *  NAME
  53. *       Online - put a SANA-II device online 
  54. *
  55. *  TEMPLATE
  56. *       Online DEV=DEVICE devicename[/unit] [UNIT unit]
  57. *
  58. *  DESCRIPTION 
  59. *       Online sends the S2_ONLINE command to the given SANA-II device driver
  60. *       and unit. The device driver restarts the network adapter hardware and
  61. *       accepts read and write request again.
  62. *
  63. *  EXAMPLES 
  64. *
  65. *       This command puts the Commodore Ethernet driver online.
  66. *
  67. *       Online a2065.device/0
  68. *
  69. *  SEE ALSO
  70. *       Offline, sana2.device/S2_ONLINE
  71. *
  72. *****************************************************************************
  73. *
  74. */
  75.  
  76. #include <exec/types.h>
  77. #include <exec/devices.h>
  78. #include <exec/ports.h>
  79. #include <exec/semaphores.h>
  80. #include <exec/memory.h>
  81. #include <exec/execbase.h>
  82.  
  83. #include <dos/dos.h>
  84. #include <dos/dosextens.h>
  85.  
  86. #ifdef __SASC 
  87. #include <clib/exec_protos.h>
  88. extern struct ExecBase* SysBase;
  89. #include <pragmas/exec_sysbase_pragmas.h>
  90. #include <proto/dos.h>
  91. #else
  92. #include <clib/exec_protos.h>
  93. #include <clib/dos_protos.h>
  94. #endif
  95.  
  96. #include <devices/sana2.h>
  97. #include <net/sana2errno.h>
  98. #include <string.h>
  99.  
  100. extern int main(char *myname);
  101.  
  102. __asm LONG _main(void)
  103. {
  104.   struct Process *p;
  105.   LONG retval = 128;
  106.  
  107.   SysBase = *(struct ExecBase**)4;
  108.   DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37L);
  109.   if (DOSBase) {
  110.     p = (struct Process *)SysBase->ThisTask;
  111.     if (p->pr_CLI) {
  112.       struct CommandLineInterface *cli = (void *)(p->pr_CLI << 2);
  113.       retval = main((char *)(cli->cli_CommandName<<2)+1);
  114.     } else {
  115.       /* No CLI. A process or a son of WB? */
  116.     }
  117.     CloseLibrary((struct Library *)DOSBase);
  118.   }
  119.  
  120.   return retval;
  121. }
  122.  
  123. struct DosLibrary *DOSBase;
  124. struct ExecBase *SysBase;
  125.  
  126. int
  127. main(char *myname)
  128. {
  129.   struct MsgPort *port = NULL;
  130.   struct IOSana2Req *req = NULL;
  131.   struct RDArgs *rdargs = NULL;
  132.   LONG args[10] = { 0 };
  133.   char *name; LONG unit;
  134.   LONG retval = 0;
  135.   LONG openerr = 1;
  136.  
  137.   rdargs = ReadArgs("DEV=DEVICE/A,UNIT/N", args, NULL);
  138.   if (!rdargs) {
  139.     retval = 10;
  140.     PrintFault(IoErr(), myname);
  141.     goto close;
  142.   }
  143.  
  144.   if (port = CreateMsgPort()) 
  145.     req = CreateIORequest(port, sizeof(*req));
  146.   if (!port || !req) {
  147.     retval = 40;
  148.     PrintFault(ERROR_NO_FREE_STORE, "CreateIORequest");
  149.     goto close;
  150.   }
  151.  
  152.   name = (STRPTR) args[0];
  153.   /* find unit number */
  154.   {
  155.     int namlen = strlen(name);
  156.     char c;
  157.  
  158.     if (args[1]) {
  159.       unit = *(LONG *)args[1];
  160.     } else {
  161.       unit = 0;
  162.       c = '0';
  163.       do {
  164.     unit = unit * 10 + c - '0';
  165.     c = name[--namlen];
  166.       }
  167.       while (c >= '0' && c <= '9');
  168.  
  169.       if (c != '/') {
  170.     retval = 10;
  171.     PrintFault(ERROR_REQUIRED_ARG_MISSING, myname);
  172.     goto close;
  173.       }
  174.       name[namlen] = '\0';    
  175.     }
  176.     if (openerr = OpenDevice(name, unit, (struct IORequest *)req, 0L)) {
  177.       retval = 10;
  178.       Sana2PrintFault("OpenDevice", req);
  179.       goto close;
  180.     }
  181.   }
  182.  
  183.   switch (FindArg("online,offline", FilePart(myname))) {
  184.   case 0: 
  185.     req->ios2_Req.io_Command = S2_ONLINE;
  186.     name = "S2_ONLINE";
  187.     break;
  188.   case 1:
  189.     req->ios2_Req.io_Command = S2_OFFLINE;
  190.     name = "S2_OFFLINE";
  191.     break;
  192.   default:
  193.     Printf("But what to do?\n");
  194.     goto close;
  195.   }
  196.   DoIO((struct IORequest *)req);
  197.   if (req->ios2_Req.io_Error) {
  198.     Sana2PrintFault(name, req);
  199.   }
  200.  
  201.  close:
  202.   if (!openerr) 
  203.     CloseDevice((struct IORequest*)req);
  204.   if (req)
  205.     DeleteIORequest((struct IORequest *)req);
  206.   if (port)
  207.     DeleteMsgPort(port);
  208.   if (rdargs)
  209.     FreeArgs(rdargs);
  210.  
  211.   return (retval);
  212. }
  213.  
  214.  
  215.