DLPI Programmer's Guide
Appendix A 151
Sample Programs
Connection Mode
con_req->dl_growth = 0;
/* copy in the dlsap */
tdlsap = (u_char *)ctrl_area + con_req->dl_dest_addr_offset;
memcpy(tdlsap, dlsap, dlsap_len);
/* send the connect request */
print_dlsap(”sending CONNECT_REQ to DLSAP ”, dlsap, dlsap_len);
put_ctrl(fd, sizeof(dl_connect_req_t) + dlsap_len, 0);
}
/*************************************************************************
get a connection response token for a stream; returns the token
*************************************************************************/
u_long
get_token(fd)
int fd; /* file descriptor */
{
dl_token_req_t *tok_req = (dl_token_req_t *)ctrl_area;
dl_token_ack_t *tok_ack = (dl_token_ack_t *)ctrl_area;
/*
Send down a token request. Note that unlike most of the other
messages this one is a PCPROTO message so we call put_ctrl with
RS_HIPRI instead of zero.
*/
tok_req->dl_primitive = DL_TOKEN_REQ;
put_ctrl(fd, sizeof(dl_token_req_t), RS_HIPRI);
/* wait for the token ack */
get_msg(fd);
check_ctrl(DL_TOKEN_ACK);
/* return the token */
return(tok_ack->dl_token);
}
/*************************************************************************
get a connect indication from a stream; returns the correlation number
*************************************************************************/
u_long
connect_ind(fd)
int fd; /* file descriptor */
{
dl_connect_ind_t *con_ind = (dl_connect_ind_t *)ctrl_area;
u_char *dlsap;
int dlsap_len;
/* wait for the connect indication */
get_msg(fd);
check_ctrl(DL_CONNECT_IND);
/* print the calling DLSAP */
dlsap = (u_char *)ctrl_area + con_ind->dl_calling_addr_offset;
dlsap_len = con_ind->dl_calling_addr_length;
print_dlsap(”received CONNECT_IND from DLSAP ”, dlsap, dlsap_len);