Sample Programs
Connection Mode
*/
/* send the disconnect request */
put_ctrl(fd, sizeof(dl_disconnect_req_t), 0);
/* wait for the OK_ACK */ get_msg(fd); check_ctrl(DL_OK_ACK);
}
/************************************************************************** main
**************************************************************************/
main() {
int | send_fd; | /* file descriptor for sending stream */ |
int | recv_c_fd; | /* fd for recv ctrl stream */ |
int | recv_d_fd; | /* fd for recv data stream */ |
u_char | sdlsap[20]; | /* sending DLSAP */ |
u_char | rcdlsap[20]; | /* receiving control DLSAP */ |
u_char | rddlsap[20]; | /* receiving data DLSAP */ |
int | sdlsap_len, rcdlsap_len, rddlsap_len; /* DLSAP lengths */ | |
u_long | correlation; | /* correlation number for CONNECT_IND */ |
u_long | token; | /* token for recv_d stream */ |
int | i; | /* loop counter */ |
/*
We'll use three streams: a sending stream, a receiving stream bound with max_conind = 1 (the ”control” stream), and a receiving stream bound with max_conind = 0 (the ”data” stream). The connect indication will be handed off from the control stream to the data stream.
We initially open only the sending stream and the receiving control stream.
*/
/*
First, we must open the DLPI device file, /dev/dlpi, and attach to a PPA. attach will open /dev/dlpi, find the first PPA with the DL_HP_PPA_INFO primitive, and attach to that PPA. attach() returns the file descriptor for the stream.
*/
send_fd = attach(); recv_c_fd = attach();
/*
Now we must bind the streams to saps. The bind function will return the local DLSAP and its length for each stream in the last two arguments. Only the receiving control stream has a
*/
bind(send_fd, SEND_SAP, 0, DL_CODLS, sdlsap, &sdlsap_len); bind(recv_c_fd, RECV_SAP, 1, DL_CODLS, rcdlsap, &rcdlsap_len);
/*
Start the connection establishment process by sending a CONNECT_REQ from the sender to the receiver control stream.
*/
Appendix A | 153 |