home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff225.lzh / AmigaTCP / src / netrom.c < prev    next >
C/C++ Source or Header  |  1989-06-24  |  3KB  |  124 lines

  1. /*
  2.  * Tunnel IP datagrams thru NET/ROM nonsense.  Requires (right now) use
  3.  * of AX.25 module.  No reason that we can't also speak their async serial
  4.  * line protocol, expect that you'd have to have your own NET/ROM node.
  5.  *
  6.  * Louis A. Mamakos  WA3YMH
  7.  */
  8. #ifdef    NETROM
  9. #include <stdio.h>
  10. #include "machdep.h"
  11. #include "mbuf.h"
  12. #include "iface.h"
  13. #include "ax25.h"
  14. #include "netrom.h"
  15.  
  16. #ifdef    TRACE
  17. #include "trace.h"
  18. #endif
  19.  
  20. static int nnr;
  21.  
  22. void
  23. netrom_input(interface, bp)
  24.     struct interface *interface;
  25.     struct mbuf *bp;
  26. {
  27.     netrom_dump(bp);    /** DEBUG **/
  28.     free_p(bp);
  29. }
  30.  
  31. #ifdef    TRACE
  32. netrom_dump(bp)
  33.     struct mbuf *bp;
  34. {
  35.     struct ax25_addr addr;
  36.     char qual, ident[20];
  37.  
  38.     if (bp == NULLBUF)
  39.         return;
  40.  
  41.     /* make a copy of the frame */
  42.     if ((bp = copy_p(bp, len_mbuf(bp))) == NULL)
  43.         return;
  44.  
  45.     printf("NET/ROM: ");
  46.  
  47.     /* first: examine the first byte in the NET/ROM packet.  If it is
  48.      * equal to NETROM_SIG, then this frame is a routing update.
  49.      * Otherwise, it is an inter-node frame.
  50.      */
  51.     if ((unsigned char) *bp->data == NETROM_SIG) {
  52.         /* routing update */
  53.         if (pullup(&bp, NULLCHAR, 1) != 1)    /* trash signature */
  54.             return;
  55.  
  56.         /* get ident of sending node */
  57.         ident[6] = '\0';
  58.         if (pullup(&bp, ident, 6) != 6)
  59.             return;
  60.         printf("RT from %s:\r\n", ident);
  61.         /* now, loop through and display each of the routing entries */
  62.         for(;;) {
  63.             if (pullup(&bp, (char *)&addr, AXALEN) != AXALEN) {
  64.                 break;
  65.             }
  66.             pax25(ident, &addr);
  67.             printf(" [%s/", ident);
  68.             if (pullup(&bp, ident, 6) != 6) {
  69.                 printf("\r\nMissing ident!\r\n");
  70.                 break;
  71.             }
  72.             ident[6] = '\0';
  73.             printf("%s via ", ident);
  74.             if (pullup(&bp, (char *)&addr, AXALEN) != AXALEN) {
  75.                 printf("Missing neighbor node\r\n");
  76.                 break;
  77.             }
  78.             pax25(ident, &addr);
  79.             if (pullup(&bp, &qual, 1) != 1) {
  80.                 printf("missing qual\r\n");
  81.                 break;
  82.             }
  83.             printf("%s qual %u]", ident, qual & 0xff);
  84.         }
  85.         printf("\r\n");
  86.     } else {
  87.         /* inter node frame */
  88.         printf("inter-node frame\r\n");
  89.     }    
  90.     free_p(bp);
  91. }
  92. #endif    TRACE
  93.  
  94. /*
  95.  *  Attach a NET/ROM virual interface to the system.  This interface needs the
  96.  *  presence of a companion AX.25 interface to actually communicate.
  97.  *
  98.  *  argv[0]: hardware type: "netrom"
  99.  *  argv[1]: name of companion ax.25 interface (like ax0)
  100.  *  argv[2]: must be "ax25" to indicate using AX.25 as link level protocol
  101.  *  argv[3]: label, name of interface like "nr0"
  102.  *  argv[4]: optional: MTU
  103.  *  argv[5]: optional: update frequency in seconds
  104.  */
  105. netrom_attach(argc, argv)
  106.     int argc;
  107.     char *argv[];
  108. {
  109. #ifdef    foobarbaz
  110.     int dev;
  111.     register struct interface *if_nr;
  112.  
  113.     if (nnr >= NR_MAX) {
  114.         printf("Too many NET/ROM devices\r\n");
  115.         return -1;
  116.     }
  117.  
  118.     dev = nnr++;
  119.     if_nr = calloc(1, sizeof(struct interface));
  120.     
  121. #endif    NETROM
  122. }
  123. #endif
  124.