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

  1. /* Subs.c - Basic network handler support routines */
  2.  
  3. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  4. /* |_o_o|\\ Copyright (c) 1987 The Software Distillery.  All Rights Reserved */
  5. /* |. o.| || This program may not be distributed without the permission of   */
  6. /* | .  | || the author.                                           BBS:      */
  7. /* | o  | ||   John Toebes                                   (919)-471-6436  */
  8. /* |  . |//                                                                  */
  9. /* ======                                                                    */
  10. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  11. #define NETCOMMON
  12. #include "netcomm.h"
  13. #include "proto.h"
  14. /* misc.c  - support routines - Phillip Lindsay (C) Commodore 1986  
  15.  *  You may freely distribute this source and use it for Amiga Development -
  16.  *  as long as the Copyright notice is left intact.
  17.  *
  18.  * 30-SEP-86
  19.  */
  20.  
  21. /* returnpkt() - packet support routine 
  22.  * here is the guy who sends the packet back to the sender...
  23.  */
  24.  
  25. void retpkt(global, packet)
  26. NGLOBAL global;
  27. struct DosPacket *packet;
  28. {
  29.  struct Message *mess;
  30.  struct MsgPort *replyport;
  31.  
  32.  replyport                = packet->dp_Port;
  33.  mess                     = packet->dp_Link;
  34.  packet->dp_Port          = global->n.port;
  35.  
  36.  PutMsg(replyport,mess); 
  37. }
  38.  
  39. /*
  40.  * taskwait() ... Waits for a message to arrive at your port and 
  41.  *   extracts the packet address which is returned to you.
  42.  */
  43.  
  44. struct DosPacket *taskwait(global)
  45. NGLOBAL global;
  46. {
  47.  struct Message *mymess;
  48.  
  49.  WaitPort(global->n.port); /* wait for packet */
  50.  mymess = (struct Message *) GetMsg(global->n.port);
  51.  
  52.  global->pkt = (struct DosPacket *) mymess->mn_Node.ln_Name;
  53.  
  54.  return(global->pkt);
  55.  
  56. char *DosAllocMem(global, len)
  57. NGLOBAL global;
  58. long len;
  59. {
  60. long *p;
  61.  
  62. if (( p = (long *)AllocMem(len+4, MEMF_PUBLIC | MEMF_CLEAR)) == NULL)
  63.    {
  64.    if (global->pkt != NULL)
  65.       {
  66.       global->pkt->dp_Res1 = DOS_FALSE;
  67.       global->pkt->dp_Res2 = ERROR_NO_FREE_STORE;
  68.       }
  69.    else
  70.       {
  71.       /* Gee.  Out of memory AND there is nobody to tell about it ...  */
  72.       /* Only choice is to GURU.  Maybe we could do something clever   */
  73.       /* but I doubt it...                                             */
  74.       BUG(("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"));
  75.       BUG(("!!!!!!!!!!!!               !!!!!!!!\n"));
  76.       BUG(("!!!!!!!!!!!! OUT OF MEMORY !!!!!!!!\n"));
  77.       BUG(("!!!!!!!!!!!!               !!!!!!!!\n"));
  78.       BUG(("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"));
  79.       }
  80.    }
  81. else
  82.    *p++ = len;
  83.  
  84. return((char *)p);
  85. }
  86.  
  87. void DosFreeMem(p)
  88. char *p;
  89. {
  90. long *lp;
  91. long len;
  92.  
  93.    lp = (long *)p;
  94.    len = *--lp;
  95.    FreeMem((char *)lp, len);
  96. }
  97.  
  98. LONG checksum(c, len)
  99. char *c;
  100. int len;
  101. {
  102.    int i, l;
  103.    LONG sum, *lptr;
  104.    unsigned char *uc;
  105.  
  106.    l = len/sizeof(LONG);
  107.    lptr = (LONG *)c;
  108.    for(i=0, sum=0; i<l; i++, lptr++) sum += *lptr;
  109.  
  110.    l = len % sizeof(LONG);
  111.    uc = (unsigned char *)lptr;
  112.    for(i=0; i<l; i++, uc++) sum += *uc;
  113.  
  114.    return(sum);
  115. }
  116.  
  117. void CheckRP(r)
  118. struct RPacket *r;
  119. {
  120. #ifndef SMALLPACKET
  121.    /* Get checksum for RP */
  122.    if(r->DLen)
  123.       r->DCheck = checksum(r->Data, r->DLen);
  124.    else
  125.       r->DCheck = 0L;
  126.  
  127.    r->checksum = 0L;
  128.    r->checksum = checksum((char *)r, RPSIZE);
  129. #endif
  130. }
  131.  
  132.