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

  1. /* Functions for level 3 net/rom support
  2.  * Copyright 1989 Dan Frank, W9NK
  3.  */
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "ax25.h"
  7. #include "netrom.h"
  8. #include "lapb.h"
  9. #include <ctype.h>
  10.  
  11. /* Convert a net/rom network header to host format structure
  12.  * Return -1 if error, 0 if OK
  13.  */
  14.  
  15. int
  16. ntohnr3(hdr,bpp)
  17. register struct nr3hdr *hdr;    /* output structure */
  18. struct mbuf **bpp;
  19. {
  20.     int ttl;
  21.     
  22.     if(pullup(bpp,hdr->source,AXALEN) < AXALEN)
  23.         return -1;
  24.  
  25.     if(pullup(bpp,hdr->dest,AXALEN) < AXALEN)
  26.         return -1;
  27.  
  28.     if((ttl = PULLCHAR(bpp)) == -1)
  29.         return -1;
  30.  
  31.     hdr->ttl = ttl;
  32.  
  33.     return 0;
  34. }
  35.  
  36. /* Convert a host-format net/rom level 3 header into an mbuf ready
  37.  * for transmission.
  38.  */
  39.  
  40. struct mbuf *
  41. htonnr3(hdr)
  42. register struct nr3hdr *hdr;
  43. {
  44.     struct mbuf *rbuf;
  45.     register char *cp;
  46.  
  47.     if(hdr == (struct nr3hdr *) NULL)
  48.         return NULLBUF;
  49.  
  50.     /* Allocate space for return buffer */
  51.     if((rbuf = alloc_mbuf(NR3HLEN)) == NULLBUF)
  52.         return NULLBUF;
  53.  
  54.     rbuf->cnt = NR3HLEN;
  55.  
  56.     /* Now convert */
  57.     cp = rbuf->data;
  58.  
  59.     memcpy(cp,hdr->source,AXALEN);
  60.     cp[ALEN] &= ~E;    /* source E-bit is always off */
  61.     cp += AXALEN;
  62.     memcpy(cp,hdr->dest,AXALEN);
  63.     cp[ALEN] |= E;        /* destination E-bit always set */
  64.     cp += AXALEN;
  65.     *cp = hdr->ttl;
  66.  
  67.     return rbuf;
  68. }
  69.  
  70. /* Convert a net/rom routing broadcast destination subpacket from
  71.  * network format to a host format structure.  Return -1 if error,
  72.  * 0 if OK.
  73.  */
  74. int
  75. ntohnrdest(ds,bpp)
  76. register struct nr3dest *ds;
  77. struct mbuf **bpp;
  78. {
  79.     int quality;
  80.  
  81.     /* get destination callsign */
  82.     if(pullup(bpp,ds->dest,AXALEN) < AXALEN)
  83.         return -1;
  84.  
  85.     /* get destination alias */
  86.     if(pullup(bpp,ds->alias,ALEN) < ALEN)
  87.         return -1;
  88.     ds->alias[ALEN] = '\0';
  89.  
  90.     /* get best neighbor callsign */
  91.     if(pullup(bpp,ds->neighbor,AXALEN) < AXALEN)
  92.         return -1;
  93.  
  94.     /* get route quality */
  95.     if((quality = PULLCHAR(bpp)) == -1)
  96.         return -1;
  97.     ds->quality = uchar(quality);
  98.  
  99.     return 0;
  100. }
  101.  
  102. /* Convert a host-format net/rom destination subpacket into an
  103.  * mbuf ready for transmission as part of a route broadcast
  104.  * packet.
  105.  */
  106. struct mbuf *
  107. htonnrdest(ds)
  108. register struct nr3dest *ds;
  109. {
  110.     struct mbuf *rbuf;
  111.     register char *cp;
  112.  
  113.     if(ds == (struct nr3dest *) NULL)
  114.         return NULLBUF;
  115.  
  116.     /* Allocate space for return buffer */
  117.     if((rbuf = alloc_mbuf(NRRTDESTLEN)) == NULLBUF)
  118.         return NULLBUF;
  119.  
  120.     rbuf->cnt = NRRTDESTLEN;
  121.  
  122.     cp = rbuf->data;
  123.  
  124.     memcpy(cp,ds->dest,AXALEN);
  125.     cp += AXALEN;
  126.  
  127.     memcpy(cp,ds->alias,ALEN);
  128.     cp += ALEN;
  129.  
  130.     memcpy(cp,ds->neighbor,AXALEN);
  131.     cp += AXALEN;
  132.  
  133.     *cp = uchar(ds->quality);
  134.  
  135.     return rbuf;
  136. }
  137.  
  138.