/* * receiver.c * * Usage: receiver * * Function: Example code to receiver a buffer of characters from a sender * through a Fore ATM switch. * * Notes: * * The receiver must be started before the sender is started. * * The RSAP in this file must agree with the RSAP in sender.c. * */ #include #include #include #include #define ATM_DEVICE "qaa0" /* qaa[0-3], fa0 - logical devices mapping to same ATM adapter card */ #define RSAP 4096 /* receiver application service access point */ #define PBW 2000 /* peak bandwidth in kbits/sec */ #define MBW 2000 /* mean bandwidth in kbits/sec */ #define BURST 2 /* burst size in kbits */ #define min(a,b) (a > b ? b : a) main(argc, argv) int argc; char **argv; { int fd, qlen, mtu, i; int conn_id; u_int switchid, portid; Atm_info info; Atm_endpoint sender; Atm_sap rsap; Atm_qos qos; Aal_type aal = aal_type_5; /* fore_xdr.h: defines aal_null, aal_type_[1-5] */ /* XXX Are aal_type_[1,2] really supported? */ Atm_dataflow dataflow = simplex; /* fore_atm_user.h: defines simplex, duplex, multicast */ char *device_name; char *rbuf; if (argc != 1) { fprintf(stderr, "Usage: %s\n",argv[0]); exit(1); } /* Open ATM device and get file descriptor */ device_name = malloc(strlen("/dev/") + strlen(ATM_DEVICE) + 1); sprintf(device_name, "/dev/%s", ATM_DEVICE); printf("Opening device %s.\n",device_name); if ((fd = atm_open(device_name, O_RDWR, &info)) < 0) { perror("atm_open"); exit(1); } printf("Device opened.\n"); mtu = min(info.mtu, 4092); /* will break if mtu larger than 4092 */ /* Bind ASAP to file descriptor */ rsap = RSAP; qlen = 1; /* atm_bind: 1 means will accept one connection request */ printf("Binding RSAP to file descriptor.\n"); if (atm_bind(fd, rsap, &rsap, qlen) < 0) { atm_error("atm_bind"); exit(1); } printf("Binding done. RSAP assigned %d\n",rsap); /* Listen for connection request */ printf("Listening for connection request.\n"); if (atm_listen(fd, &conn_id, &sender, &qos, &aal) < 0) { atm_error("atm_listen"); exit(1); } printf("Call received.\n"); /* use Fore macros to get switch and port id's */ GET_SWITCH(switchid, sender.nsap); GET_PORT(portid, sender.nsap); printf("Source switch %d, port %d, sap %d, aal %d\n", switchid, portid, sender.asap, aal); printf("Target qos of call: peak %d, mean %d, burst %d\n", qos.peak_bandwidth.target, qos.mean_bandwidth.target, qos.mean_burst.target); /* Accept connection */ printf("Accepting connection.\n"); if (atm_accept(fd, fd, conn_id, &qos, dataflow) < 0) { atm_error("atm_accept"); exit(1); } printf("Connection accepted.\n"); /* Receive data */ rbuf = malloc(mtu); printf("Receiving data of size %d.\n",mtu); if (atm_recv(fd, rbuf, mtu) < 0) { atm_error("atm_recv"); exit(1); } printf("Data received:\n"); for (i = 0; i < mtu; i++) if (i % 100 == 0) printf(" index %d, value %d\n",i,rbuf[i]); /* Close connection - needed? */ /* XXXX when and where to do close?? */ /* printf("Closing connection.\n"); atm_close(fd); printf("Connection closed.\n"); */ }