home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 2 / amigaformatcd02.iso / comms / netsoftware / nethandler.lha / NetHandler / util / shutdown.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-17  |  2.2 KB  |  90 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <exec/nodes.h>
  4. #include <exec/lists.h>
  5. #include <exec/ports.h>
  6. #include <libraries/dos.h>
  7. #include <libraries/dosextens.h>
  8. #include <libraries/filehandler.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13.  
  14. #undef GLOBAL
  15. /* my version of BADDR() has no problems with casting */
  16. #undef  BADDR
  17. #define BADDR(x)        ((APTR)((long)x << 2))
  18. #define MKBADDR(x)      ((BPTR)((long)x >> 2))
  19.  
  20. long sendpkt(struct MsgPort *, long, long*, long);
  21.  
  22. void main(argc, argv)
  23. int argc;
  24. char **argv;
  25. {
  26. struct MsgPort *proc;
  27. long myargs[8];
  28.  
  29. if (argc != 2)
  30.    {
  31.    printf("Usage: %s <device>\n", argv[0]);
  32.    return;
  33.    }
  34.  
  35. myargs[0]=1;
  36.  
  37. if ((proc = (struct MsgPort *)DeviceProc(argv[1])) == NULL)
  38.    {
  39.    printf("Unable to get a device proc for %s\n", argv[1]);
  40.    return;
  41.    }
  42.  
  43. sendpkt(proc,ACTION_DIE,myargs,1);
  44. }
  45.  
  46. LONG sendpkt(pid,action,args,nargs)
  47. struct MsgPort *pid;  /* process indentifier ... (handlers message port ) */
  48. LONG action,          /* packet type ... (what you want handler to do )   */
  49.      args[],          /* a pointer to a argument list */
  50.      nargs;           /* number of arguments in list  */
  51.    {
  52.    struct MsgPort        *replyport;
  53.    struct StandardPacket *packet;
  54.  
  55.    LONG  count, *pargs, res1;
  56.  
  57.    replyport = (struct MsgPort *) CreatePort(NULL,0);
  58.    if(!replyport) return(NULL);
  59.  
  60.    packet = (struct StandardPacket *) 
  61.       AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  62.    if(!packet) 
  63.       {
  64.       DeletePort(replyport);
  65.       return(NULL);
  66.       }
  67.  
  68.    packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  69.    packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);
  70.    packet->sp_Pkt.dp_Port         = replyport;
  71.    packet->sp_Pkt.dp_Type         = action;
  72.  
  73.    /* copy the args into the packet */
  74.    pargs = &(packet->sp_Pkt.dp_Arg1);       /* address of first argument */
  75.    for(count=0;count < nargs;count++) 
  76.       pargs[count]=args[count];
  77.  
  78.    PutMsg(pid,(struct Message *)packet); /* send packet */
  79.  
  80.    WaitPort(replyport);
  81.    GetMsg(replyport); 
  82.  
  83.    res1 = packet->sp_Pkt.dp_Res1;
  84.  
  85.    FreeMem((char *)packet,(long)sizeof(struct StandardPacket));
  86.    DeletePort(replyport); 
  87.  
  88.    return(res1);
  89. }
  90.