home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / s920603.zip / ARCNET.C < prev    next >
C/C++ Source or Header  |  1992-04-08  |  3KB  |  127 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,bp)
  18. struct arc *arc;
  19. struct mbuf *bp;
  20. {
  21.     register char *cp;
  22.  
  23.     bp = pushdown(bp,ARCLEN);
  24.  
  25.     cp = bp->data;
  26.  
  27.     memcpy(cp,arc->source,AADDR_LEN);
  28.     cp += AADDR_LEN;
  29.     memcpy(cp,arc->dest,AADDR_LEN);
  30.     cp += AADDR_LEN;
  31.     *cp++ = arc->type;
  32.  
  33.     return bp;
  34. }
  35. /* Extract ARCnet header */
  36. int
  37. ntoharc(arc,bpp)
  38. struct arc *arc;
  39. struct mbuf **bpp;
  40. {
  41.     pullup(bpp,arc->source,AADDR_LEN);
  42.     pullup(bpp,arc->dest,AADDR_LEN);
  43.     arc->type = PULLCHAR(bpp);
  44.     return ARCLEN;
  45. }
  46.  
  47. /* Format an ARCnet address into a printable ascii string */
  48. char *
  49. parc(out,addr)
  50. char *out,*addr;
  51. {
  52.     sprintf(out,"%02x", uchar(addr[0]));
  53.     return  out;
  54. }
  55.  
  56. /* Convert an ARCnet address from Hex/ASCII to binary */
  57. int
  58. garc(out,cp)
  59. register char *out;
  60. register char *cp;
  61. {
  62.     *out = htoi(cp);
  63.     return 0;
  64. }
  65. /* Send an IP datagram on ARCnet */
  66. int
  67. anet_send(bp,iface,gateway,prec,del,tput,rel)
  68. struct mbuf *bp;    /* Buffer to send */
  69. struct iface *iface;    /* Pointer to interface control block */
  70. int32 gateway;        /* IP address of next hop */
  71. int prec;
  72. int del;
  73. int tput;
  74. int rel;
  75. {
  76.     char *agate;
  77.  
  78.     agate = res_arp(iface,ARP_ARCNET,gateway,bp);
  79.     if(agate != NULLCHAR)
  80.         return (*iface->output)(iface,agate,iface->hwaddr,ARC_IP,bp);
  81.     return 0;
  82. }
  83. /* Send a packet with ARCnet header */
  84. int
  85. anet_output(iface,dest,source,type,data)
  86. struct iface *iface;    /* Pointer to interface control block */
  87. char *dest;        /* Destination ARCnet address */
  88. char *source;        /* Source ARCnet address */
  89. int16 type;        /* Type field */
  90. struct mbuf *data;    /* Data field */
  91. {
  92.     struct arc ap;
  93.     struct mbuf *bp;
  94.  
  95.     memcpy(ap.dest,dest,AADDR_LEN);
  96.     memcpy(ap.source,source,AADDR_LEN);
  97.     ap.type = type;
  98.     if((bp = htonarc(&ap,data)) == NULLBUF){
  99.         free_p(data);
  100.         return -1;
  101.     }
  102.     return (*iface->raw)(iface,bp);
  103. }
  104. /* Process incoming ARCnet packets. Shared by all ARCnet drivers. */
  105. void
  106. aproc(iface,bp)
  107. struct iface *iface;
  108. struct mbuf *bp;
  109. {
  110.     struct arc hdr;
  111.  
  112.     /* Remove ARCnet header and kick packet upstairs */
  113.     ntoharc(&hdr,&bp);
  114.     switch(uchar(hdr.type)){
  115.     case ARC_ARP:
  116.         arp_input(iface,bp);
  117.         break;
  118.     case ARC_IP:
  119.         ip_route(iface,bp,0);
  120.         break;
  121.     default:
  122.         free_p(bp);
  123.         break;
  124.     }
  125. }
  126.  
  127.