LLA and DLPI Example Programs

DLPI Example Program

dl_subs_bind_req_t *subs_bind_req = (dl_subs_bind_req_t*)ctrl_area; dl_subs_bind_ack_t *subs_bind_ack = (dl_subs_bind_ack_t*)ctrl_area; u_char *dlsap_addr;

/* Fill in Subsequent bind req */

subs_bind_req->dl_primitive = DL_SUBS_BIND_REQ;

subs_bind_req->dl_subs_sap_offset = DL_SUBS_BIND_REQ_SIZE; subs_bind_req->dl_subs_sap_length = snapsap_len; subs_bind_req->dl_subs_bind_class = subs_bind_class; memcpy((caddr_t)&subs_bind_req[1], snapsap, snapsap_len);

/* send the SUBS_BIND_REQ and wait for the OK_ACK */ put_ctrl(fd, sizeof(dl_subs_bind_req_t)+snapsap_len, 0); get_msg(fd);

check_ctrl(DL_SUBS_BIND_ACK);

/* return the DLSAP to the caller */

*dlsap_len = subs_bind_ack->dl_subs_sap_length;

dlsap_addr = (u_char *)ctrl_area +subs_bind_ack->dl_subs_sap_offset; memcpy(dlsap, dlsap_addr, *dlsap_len);

}

/********************************************************************* unbind, detach, and close

*********************************************************************/

void

 

 

 

cleanup(fd)

 

 

 

int

fd;

/* file

descriptor */

{

 

 

 

dl_unbind_req_t*unbind_req =

(dl_unbind_req_t *)ctrl_area;

dl_detach_req_t*detach_req =

(dl_detach_req_t *)ctrl_area;

/* unbind */

unbind_req->dl_primitive = DL_UNBIND_REQ; put_ctrl(fd, sizeof(dl_unbind_req_t), 0); get_msg(fd);

check_ctrl(DL_OK_ACK);

/* detach */

detach_req->dl_primitive = DL_DETACH_REQ; put_ctrl(fd, sizeof(dl_detach_req_t), 0); get_msg(fd);

check_ctrl(DL_OK_ACK);

/* close */ close(fd);

}

/********************************************************************* receive a data packet;

*********************************************************************/

int

 

 

recv_data(fd)

 

 

int

fd;

/* file descriptor */

{

 

 

dl_unitdata_ind_t *data_ind = (dl_unitdata_ind_t *)ctrl_area;

Chapter 2

27

Page 27
Image 27
HP B2355-90138 manual Dlpi Example Program