home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / ARCNET.C < prev    next >
C/C++ Source or Header  |  1991-01-27  |  3KB  |  129 lines

  1. /* Stuff generic to all ARCnet controllers
  2.  * Copyright 1990 Russ Nelson
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "iface.h"
  8. #include "timer.h"
  9. #include "arp.h"
  10. #include "ip.h"
  11. #include "arcnet.h"
  12.  
  13. char ARC_bdcst[] = { 0 };
  14.  
  15. /* Convert ARCnet header in host form to network mbuf */
  16. struct mbuf *
  17. htonarc(arc,data)
  18. struct arc *arc;
  19. struct mbuf *data;
  20. {
  21.     struct mbuf *bp;
  22.     register char *cp;
  23.  
  24.     if((bp = pushdown(data,ARCLEN)) == NULLBUF)
  25.         return NULLBUF;
  26.  
  27.     cp = bp->data;
  28.  
  29.     memcpy(cp,arc->source,AADDR_LEN);
  30.     cp += AADDR_LEN;
  31.     memcpy(cp,arc->dest,AADDR_LEN);
  32.     cp += AADDR_LEN;
  33.     *cp++ = arc->type;
  34.  
  35.     return bp;
  36. }
  37. /* Extract ARCnet header */
  38. int
  39. ntoharc(arc,bpp)
  40. struct arc *arc;
  41. struct mbuf **bpp;
  42. {
  43.     pullup(bpp,arc->source,AADDR_LEN);
  44.     pullup(bpp,arc->dest,AADDR_LEN);
  45.     arc->type = PULLCHAR(bpp);
  46.     return ARCLEN;
  47. }
  48.  
  49. /* Format an ARCnet address into a printable ascii string */
  50. char *
  51. parc(out,addr)
  52. char *out,*addr;
  53. {
  54.     sprintf(out,"%02x", uchar(addr[0]));
  55.     return  out;
  56. }
  57.  
  58. /* Convert an ARCnet address from Hex/ASCII to binary */
  59. int
  60. garc(out,cp)
  61. register char *out;
  62. register char *cp;
  63. {
  64.     *out = htoi(cp);
  65.     return 0;
  66. }
  67. /* Send an IP datagram on ARCnet */
  68. int
  69. anet_send(bp,iface,gateway,prec,del,tput,rel)
  70. struct mbuf *bp;    /* Buffer to send */
  71. struct iface *iface;    /* Pointer to interface control block */
  72. int32 gateway;        /* IP address of next hop */
  73. int prec;
  74. int del;
  75. int tput;
  76. int rel;
  77. {
  78.     char *agate;
  79.  
  80.     agate = res_arp(iface,ARP_ARCNET,gateway,bp);
  81.     if(agate != NULLCHAR)
  82.         return (*iface->output)(iface,agate,iface->hwaddr,ARC_IP,bp);
  83.     return 0;
  84. }
  85. /* Send a packet with ARCnet header */
  86. int
  87. anet_output(iface,dest,source,type,data)
  88. struct iface *iface;    /* Pointer to interface control block */
  89. char *dest;        /* Destination ARCnet address */
  90. char *source;        /* Source ARCnet address */
  91. int16 type;        /* Type field */
  92. struct mbuf *data;    /* Data field */
  93. {
  94.     struct arc ap;
  95.     struct mbuf *bp;
  96.  
  97.     memcpy(ap.dest,dest,AADDR_LEN);
  98.     memcpy(ap.source,source,AADDR_LEN);
  99.     ap.type = type;
  100.     if((bp = htonarc(&ap,data)) == NULLBUF){
  101.         free_p(data);
  102.         return -1;
  103.     }
  104.     return (*iface->raw)(iface,bp);
  105. }
  106. /* Process incoming ARCnet packets. Shared by all ARCnet drivers. */
  107. void
  108. aproc(iface,bp)
  109. struct iface *iface;
  110. struct mbuf *bp;
  111. {
  112.     struct arc hdr;
  113.  
  114.     /* Remove ARCnet header and kick packet upstairs */
  115.     ntoharc(&hdr,&bp);
  116.     switch(uchar(hdr.type)){
  117.     case ARC_ARP:
  118.         arp_input(iface,bp);
  119.         break;
  120.     case ARC_IP:
  121.         ip_route(iface,bp,0);
  122.         break;
  123.     default:
  124.         free_p(bp);
  125.         break;
  126.     }
  127. }
  128.  
  129.