DLPI Programmer's Guide

Appendix A 159
Sample Programs
Connectionless Mode
{
/* set the len field in the strbuf structure */
data_buf.len = length;
/* call putmsg and check for an error */
if(putmsg(fd, 0, &data_buf, 0) < 0) {
printf(”error: put_data putmsg failed, errno = %d\n”, errno);
exit(1);
}
}
/**************************************************************************
put a message consisting of only a control part on a stream
**************************************************************************/
void
put_ctrl(fd, length, pri)
int fd; /* file descriptor */
int length; /* length of control message */
int pri; /* priority of message: either 0 or RS_HIPRI */
{
/* set the len field in the strbuf structure */
ctrl_buf.len = length;
/* call putmsg and check for an error */
if(putmsg(fd, &ctrl_buf, 0, pri) < 0) {
printf(”error: put_ctrl putmsg failed, errno = %d\n”, errno);
exit(1);
}
}
/**************************************************************************
put a message consisting of both a control part and a control part
on a stream
**************************************************************************/
void
put_both(fd, ctrl_length, data_length, pri)
int fd; /* file descriptor */
int ctrl_length; /* length of control part */
int data_length; /* length of data part */
int pri; /* priority of message: either 0 or RS_HIPRI */
{
/* set the len fields in the strbuf structures */
ctrl_buf.len = ctrl_length;
data_buf.len = data_length;
/* call putmsg and check for an error */
if(putmsg(fd, &ctrl_buf, &data_buf, pri) < 0) {
printf(”error: put_both putmsg failed, errno = %d\n”, errno);
exit(1);
}
}
/******************************************************************************
open the DLPI cloneable device file, get a list of available PPAs,
and attach to the first PPA; returns a file descriptor for the stream
******************************************************************************/
int