NAME

     atm_server_null - example server ATM program  using  a  null
     AAL


EXAMPLE

     /*
      * Copyright (c) 1992 by Fore Systems, Inc.
      */

     #ifndef lint
     static char -atm-server-null-c-[] = "@(#)$Id: atm-server-null.c,v 1.3 1994/06/28 20:18:40 jshirron Exp $ FSI";
     #endif /* lint */

     #include <stdio.h>
     #include <sys/file.h>
     #include <sys/fcntl.h>
     #include <fore-atm/fore-atm-user.h>

     #define SERVER-SAP      4096
     #define HOST-CELL-SIZE  56      /* ATM Computer Interface cell size */

     main(argc, argv)                                             main
         int     argc;
         char    *argv[];
     {
         int fd, cells, mtu, octets,  qlen, conn-id;
         u-int switchid, portid;
         Atm-info info;
         Atm-endpoint calling;
         Atm-qos qos;
         Atm-sap ssap;
         Aal-type aal;
         Atm-dataflow dataflow = simplex;
         char *device-name;
         char *rbuf;
         extern char *malloc();

         if (argc < 2) {
             fprintf(stderr, "Usage: %s device [server-sap]\n",
                          argv[0]);
             exit(1);
         }

         device-name = malloc(strlen("/dev/") + strlen(argv[1]) + 1);
         sprintf(device-name, "/dev/%s", argv[1]);

         if ((fd = atm-open(device-name, O-RDWR, &info)) < 0) {
             perror("atm-open");
             exit(1);
         }


         mtu = info.mtu; /* Max transmission unit */
         rbuf = malloc(info.mtu);

         /*
          * Bind to a well known sap and set pending
          * connect request queue length.
          */
         ssap = (argc == 3) ? atoi(argv[2]) : SERVER-SAP;
         qlen = 1;
         if (atm-bind(fd, ssap, &ssap, qlen) < 0) {
             atm-error("atm-bind");
             exit(1);
         }
         printf("SAP assigned=%d\n", ssap);

         /*
          * Wait for a connection request.
          */
         if (atm-listen(fd, &conn-id, &calling, &qos, &aal) < 0) {
             atm-error("atm-connect");
             exit(1);
         }
         /*
          * Extract the switch id and port id from the NSAP.
          */
         GET-SWITCH(switchid, calling.nsap);
         GET-PORT(portid, calling.nsap);

         printf("calling switch=%d, port=%d, sap=%d, aal=%d\n",
             switchid, portid, calling.asap, aal);

         printf("qos target peak=%d, mean=%d, burst=%d\n",
             qos.peak-bandwidth.target,
             qos.mean-bandwidth.target,
             qos.mean-burst.target);

         printf("qos minimum peak=%d, mean=%d, burst=%d\n",
             qos.peak-bandwidth.minimum,
             qos.mean-bandwidth.minimum,
             qos.mean-burst.minimum);

         printf("connect conn-id=%d\n", conn-id);

         /*
          * Request some quality of service.
          */
         qos.peak-bandwidth.target = 256; /* kbit/sec */
         qos.peak-bandwidth.minimum = 128; /* kbit/sec */
         qos.mean-bandwidth.target = 128; /* kbit/sec */
         qos.mean-bandwidth.minimum = 64; /* kbit/sec */


         qos.mean-burst.target = 2;  /* 2 kbit packet length */
         qos.mean-burst.minimum = 1; /* 1 kbit packet length */

         /*
          * Accept the connection request.
          */
         if (atm-accept(fd, fd, conn-id, &qos, dataflow) < 0) {
             atm-error("atm-accept");
             exit(1);
         }

         /*
          * Set batch size to 32. Causes the ATM device
                 * driver to send cells upstream in batchs of 32.
          * The default batch size is 1.
          */
         if (atm-setbatchsize(fd, 32) < 0) {
             atm-error("atm-setbatchsize");
             exit(1);
         }

         for(cells = 0; ;) {

             if ((octets = atm-recv(fd, rbuf, mtu)) < 0) {
                 atm-error("atm-recv");
                 break;
             }
             cells += (octets / HOST-CELL-SIZE);

             /*
              * The format of cells in `rbuf' is defined in
              * the appropriate ATM Computer Interface User's
              * Manual. The 48 octet cell payload is defined
              * by the application.
              */
         }
         printf("%d cells received\n", cells);
         return(0);
     }


SEE ALSO

     atm_intro(4N)