home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 2 / amigaformatcd02.iso / comms / netsoftware / nethandler.lha / NetHandler / util / netmount.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-17  |  2.7 KB  |  111 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. #define ACTION_NETWORK_KLUDGE 4674764L   
  21.  
  22. long sendpkt(struct MsgPort *, long, long*, long);
  23.  
  24. void main(argc, argv)
  25. int argc;
  26. char **argv;
  27. {
  28. struct MsgPort *proc;
  29. long myargs[8];
  30. int len1, len2;
  31. unsigned char *nodename;
  32. char *devname;
  33.  
  34.    if (argc != 4)
  35.    {
  36.       printf("Usage: %s <netdevice> <nodename> <rmtdevice>\n", argv[0]);
  37.       return;
  38.    }
  39.  
  40.    if(!(nodename = AllocMem(len1=strlen(argv[2])+2, 0)) ||
  41.       !(devname  = AllocMem(len2=strlen(argv[3]+1), 0)))
  42.    {
  43.       printf("Error: No memory\n");
  44.       return;
  45.    }
  46.  
  47.    nodename[0] = strlen(argv[2]);
  48.    strcpy(nodename+1, argv[2]);
  49.  
  50.    strcpy(devname, argv[3]);
  51.  
  52.    myargs[0]=(long)MKBADDR(nodename);
  53.    myargs[1]=(long)MKBADDR(devname);
  54.  
  55.    if ((proc = (struct MsgPort *)DeviceProc(argv[1])) == NULL)
  56.    {
  57.       printf("Unable to get a device proc for %s\n", argv[1]);
  58.       return;
  59.    }
  60.  
  61.    sendpkt(proc,ACTION_NETWORK_KLUDGE,myargs,2);
  62.  
  63.    FreeMem(nodename, len1);
  64.    FreeMem(devname, len2);
  65. }
  66.  
  67. LONG sendpkt(pid,action,args,nargs)
  68. struct MsgPort *pid;  /* process indentifier ... (handlers message port ) */
  69. LONG action,          /* packet type ... (what you want handler to do )   */
  70.      args[],          /* a pointer to a argument list */
  71.      nargs;           /* number of arguments in list  */
  72.    {
  73.    struct MsgPort        *replyport;
  74.    struct StandardPacket *packet;
  75.  
  76.    LONG  count, *pargs, res1;
  77.  
  78.    replyport = (struct MsgPort *) CreatePort(NULL,0);
  79.    if(!replyport) return(NULL);
  80.  
  81.    packet = (struct StandardPacket *) 
  82.       AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  83.    if(!packet) 
  84.       {
  85.       DeletePort(replyport);
  86.       return(NULL);
  87.       }
  88.  
  89.    packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  90.    packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);
  91.    packet->sp_Pkt.dp_Port         = replyport;
  92.    packet->sp_Pkt.dp_Type         = action;
  93.  
  94.    /* copy the args into the packet */
  95.    pargs = &(packet->sp_Pkt.dp_Arg1);       /* address of first argument */
  96.    for(count=0;count < nargs;count++) 
  97.       pargs[count]=args[count];
  98.  
  99.    PutMsg(pid,(struct Message *)packet); /* send packet */
  100.  
  101.    WaitPort(replyport);
  102.    GetMsg(replyport); 
  103.  
  104.    res1 = packet->sp_Pkt.dp_Res1;
  105.  
  106.    FreeMem((char *)packet,(long)sizeof(struct StandardPacket));
  107.    DeletePort(replyport); 
  108.  
  109.    return(res1);
  110. }
  111.