/* * sender.c * * Usage: sender * * Function: Example code to send a buffer of characters to a receiver * through a Fore ATM switch. * * Notes: * * The ATM interface name for the receiver must be on the command line. * * The receiver must be started before the sender is started. * * The RSAP in this file must agree with the RSAP in receiver.c. * */ #include #include #include #include #define ATM_DEVICE "qaa0" /* qaa[0-3], fa0 - logical devices mapping to same ATM adapter card */ #define RSAP 4096 #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; Atm_info info; Atm_endpoint rcvr; Atm_qos qos; Atm_qos_sel qos_selected; Atm_sap asap; 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 *tbuf; if (argc != 2) { fprintf(stderr, "Usage: %s receiver-hostname\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"); /* Bind ASAP to file descriptor */ asap = 0; /* fore_xdr.h: Atm_sap defined as u_int */ /* atm_bind: asap = 0 causes device driver to select asap */ /* sender asap does not need to be known anywhere else */ qlen = 0; /* atm_bind: 0 means will not accept any connection request */ printf("Binding ASAP to file descriptor.\n"); if (atm_bind(fd, asap, &asap, qlen) < 0) { atm_error("atm_bind"); exit(1); } printf("Binding done. ASAP assigned %d\n",asap); /* Get receiver's NSAP */ printf("Getting receiver's NSAP.\n"); if (atm_gethostbyname(argv[1], &rcvr.nsap) < 0) { fprintf(stderr, "atm_gethostbyname failed\n"); exit(1); } printf("Got NSAP %d for receiver\n",rcvr.nsap); /* Set up qos parameters and request connection to receiver */ rcvr.asap = RSAP; qos.peak_bandwidth.target = PBW; qos.peak_bandwidth.minimum = PBW; qos.mean_bandwidth.target = MBW; qos.mean_bandwidth.minimum = MBW; qos.mean_burst.target = BURST; qos.mean_burst.minimum = BURST; printf("Connecting to destination.\n"); if (atm_connect(fd, &rcvr, &qos, &qos_selected, aal, dataflow) < 0) { atm_error("atm_connect"); exit(1); } mtu = min(info.mtu, 4092); /* will break if mtu larger than 4092 */ printf("Connection made.\n"); printf("Selected qos: peak %d, mean %d, burst %d, mtu %d\n", qos_selected.peak_bandwidth, qos_selected.mean_bandwidth, qos_selected.mean_burst, mtu); /* Finally, let's write to the destination */ tbuf = malloc(mtu); for (i = 0; i < mtu; i++) tbuf[i] = i; printf("Sending to receiver.\n"); if (atm_send(fd, tbuf, mtu) < 0) { atm_error("atm_send"); exit(1); } printf("Data sent.\n"); }