home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / NRHDR.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  3KB  |  148 lines

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