home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3 / hamradioversion3.0examsandprograms1992.iso / packet / n17jsrc / ax25mail.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  3KB  |  119 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. #include "global.h"
  8. #include "proc.h"
  9. #include "iface.h"
  10. #include "pktdrvr.h"
  11. #include "ax25.h"
  12. #include "socket.h"
  13. #include "session.h"
  14. #include "mailbox.h"
  15. #include "ax25mail.h"
  16.  
  17.  
  18. /* Axi_sock is kept in Socket.c, so that this module won't be called */
  19.  
  20. int
  21. ax25start(argc,argv,p)
  22. int argc;
  23. char *argv[];
  24. void *p;
  25. {
  26.     int s,type;
  27.  
  28.     if (Axi_sock != -1)
  29.         return 0;
  30.  
  31.     psignal(Curproc,0);    /* Don't keep the parser waiting */
  32.     chname(Curproc,"AX25 listener");
  33.     Axi_sock = socket(AF_AX25,SOCK_STREAM,0);
  34.     /* bind() is done automatically */
  35.     if(listen(Axi_sock,1) == -1){
  36.         close_s(Axi_sock);
  37.         return -1;
  38.     }
  39.     for(;;){
  40.         if((s = accept(Axi_sock,NULLCHAR,NULLINT)) == -1)
  41.             break;    /* Service is shutting down */
  42.  
  43.         type = AX25TNC;
  44.         /* Eat the line that triggered the connection
  45.          * and then start the mailbox
  46.          */
  47.         sockmode(s,SOCK_ASCII);    /* To make recvline work */
  48.         recvline(s,NULLCHAR,80); 
  49.         newproc("mbox",2048,mbx_incom,s,(void *)type,NULL,0);
  50.     }
  51.     close_s(Axi_sock);
  52.     Axi_sock = -1;
  53.     return 0;
  54. }
  55. int
  56. ax250(argc,argv,p)
  57. int argc;
  58. char *argv[];
  59. void *p;
  60. {
  61.     close_s(Axi_sock);
  62.     Axi_sock = -1;
  63.     return 0;
  64. }
  65.  
  66.  
  67. int
  68. dogateway(argc,argv,p)
  69. int argc;
  70. char *argv[];
  71. void *p;
  72. {
  73.     struct mbx *m;
  74.     struct sockaddr_ax fsocket;
  75.     struct iface *ifp;
  76.     int ndigis,i,s;
  77.     char digis[MAXDIGIS][AXALEN];
  78.     char target[AXALEN];
  79.  
  80.     m = (struct mbx *)p;
  81.     if(!(m->privs & AX25_CMD)){
  82.         tprintf(Noperm);
  83.         return 0;
  84.     }
  85.     if(((ifp = if_lookup(argv[1])) != NULLIF) && (ifp->type != CL_AX25)){
  86.         tprintf("Interface %s not usable by gateway\n",argv[1]);
  87.         return 1;
  88.     }
  89.     /* If digipeaters are given, put them in the routing table */
  90.     if(argc > 3){
  91.         setcall(target,argv[2]);
  92.         ndigis = argc - 3;
  93.         if(ndigis > MAXDIGIS){
  94.             tprintf("Too many digipeaters\n");
  95.             return 1;
  96.         }
  97.         for(i=0;i<ndigis;i++){
  98.             if(setcall(digis[i],argv[i+3]) == -1){
  99.                 tprintf("Bad digipeater %s\n",argv[i+3]);
  100.                 return 1;
  101.             }
  102.         }
  103.         if(ax_add(target,AX_LOCAL,digis,ndigis) == NULLAXR){
  104.             tprintf("AX25 route add failed\n");
  105.             return 1;
  106.         }
  107.     }
  108.     if((s = socket(AF_AX25,SOCK_STREAM,0)) == -1){
  109.         tprintf(Nosock);
  110.         return 0;
  111.     }
  112.     fsocket.sax_family = AF_AX25;
  113.     setcall(fsocket.ax25_addr,argv[2]);
  114.     strncpy(fsocket.iface,argv[1],ILEN);
  115.     m->startmsg = mallocw(80);
  116.     sprintf(m->startmsg,"*** LINKED to %s\n",m->name);
  117.     return gw_connect(m,s,(char *)&fsocket, sizeof(struct sockaddr_ax));
  118. }
  119.