home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / h / if / Radio / c / NRSUBR < prev   
Text File  |  1994-07-19  |  3KB  |  139 lines

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