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

  1. /* AX25 mailbox interface
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *    May '91    Bill Simpson
  5.  *        move to separate file for compilation & linking
  6.  */
  7.  
  8. /****************************************************************************
  9. *    $Id: ax25mail.c 1.2 93/07/16 11:42:43 ROOT_DOS Exp $
  10. *    15 Jul 93    1.2        GT    AX25 conditional.                                *
  11. ****************************************************************************/
  12.  
  13. #include "global.h"
  14. #include "proc.h"
  15. #include "ax25.h"
  16. #include "socket.h"
  17. #include "session.h"
  18. #include "mailbox.h"
  19. #include "ax25mail.h"
  20. #include "ip.h"
  21. #include "config.h"
  22.  
  23. #if    AX25
  24.  
  25. /* Axi_sock is kept in Socket.c, so that this module won't be called */
  26.  
  27. int
  28. ax25start(argc,argv,p)
  29. int argc;
  30. char *argv[];
  31. void *p;
  32. {
  33.     int s,type;
  34.  
  35.     if (Axi_sock != -1)
  36.         return 0;
  37.  
  38.     psignal(Curproc,0);    /* Don't keep the parser waiting */
  39.     chname(Curproc,"AX25 listener");
  40.     Axi_sock = socket(AF_AX25,SOCK_STREAM,0);
  41.     /* bind() is done automatically */
  42.     if(listen(Axi_sock,1) == -1){
  43.         close_s(Axi_sock);
  44.         return -1;
  45.     }
  46.     for(;;){
  47.         if((s = accept(Axi_sock,NULLCHAR,NULLINT)) == -1)
  48.             break;    /* Service is shutting down */
  49.  
  50.         type = AX25TNC;
  51.         /* Eat the line that triggered the connection
  52.          * and then start the mailbox
  53.          */
  54.         sockmode(s,SOCK_ASCII);    /* To make recvline work */
  55.         recvline(s,NULLCHAR,80); 
  56.         newproc("mbox",2048,mbx_incom,s,(void *)type,NULL,0);
  57.     }
  58.     close_s(Axi_sock);
  59.     Axi_sock = -1;
  60.     return 0;
  61. }
  62. int
  63. ax250(argc,argv,p)
  64. int argc;
  65. char *argv[];
  66. void *p;
  67. {
  68.     close_s(Axi_sock);
  69.     Axi_sock = -1;
  70.     return 0;
  71. }
  72.  
  73.  
  74. int
  75. dogateway(argc,argv,p)
  76. int argc;
  77. char *argv[];
  78. void *p;
  79. {
  80.     struct mbx *m;
  81.     struct sockaddr_ax fsocket;
  82.     int ndigis,i,s;
  83.     char digis[MAXDIGIS][AXALEN];
  84.     char target[AXALEN];
  85.  
  86.     m = (struct mbx *)p;
  87.     if(!(m->privs & AX25_CMD)){
  88.         tprintf(Noperm);
  89.         return 0;
  90.     }
  91.     /* If digipeaters are given, put them in the routing table */
  92.     if(argc > 3){
  93.         setcall(target,argv[2]);
  94.         ndigis = argc - 3;
  95.         if(ndigis > MAXDIGIS){
  96.             tprintf("Too many digipeaters\n");
  97.             return 1;
  98.         }
  99.         for(i=0;i<ndigis;i++){
  100.             if(setcall(digis[i],argv[i+3]) == -1){
  101.                 tprintf("Bad digipeater %s\n",argv[i+3]);
  102.                 return 1;
  103.             }
  104.         }
  105.         if(ax_add(target,AX_LOCAL,digis,ndigis) == NULLAXR){
  106.             tprintf("Route add failed\n");
  107.             return 1;
  108.         }
  109.     }
  110.     if((s = socket(AF_AX25,SOCK_STREAM,0)) == -1){
  111.         tprintf(Nosock);
  112.         return 0;
  113.     }
  114.     fsocket.sax_family = AF_AX25;
  115.     setcall(fsocket.ax25_addr,argv[2]);
  116.     strncpy(fsocket.iface,argv[1],ILEN);
  117.     m->startmsg = mallocw(80);
  118.     sprintf(m->startmsg,"*** LINKED to %s\n",m->name);
  119.     return gw_connect(m,s,(char *)&fsocket, sizeof(struct sockaddr_ax));
  120. }
  121.  
  122. #endif    /* AX25 */
  123.